CMakeLists.txt 4.25 KB
Newer Older
1 2 3 4 5 6 7
# UMANS: Unified Microscopic Agent Navigation Simulator
# Copyright (C) 2018-2020  Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
8
#
9 10
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 13
# GNU General Public License for more details.
#
14 15
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16 17
#
# Contact: crowd_group@inria.fr
18 19
# Website: https://project.inria.fr/crowdscience/
# See the file AUTHORS.md for a list of all contributors.
20

Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
21
cmake_minimum_required( VERSION 3.10 )
22
project( UMANS )
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
23
set (CMAKE_CXX_STANDARD 17)
24

Javad AMIRIAN's avatar
Javad AMIRIAN committed
25
#set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
26

27 28 29 30
file( GLOB_RECURSE src_All src/*)
file( GLOB_RECURSE src_Engine src/Engine/* src/3rd-party/* )
file( GLOB_RECURSE src_Library src/Library/* )
file( GLOB_RECURSE src_ConsoleApplication src/ConsoleApplication/* )
31
file( GLOB_RECURSE src_GUI src/GUI/* )
32

33 34
# --- ensure that certain directories are recognized in "#include <...>" lines
include_directories( ./src/ ./src/Engine/ )
35

36
# === Include the GUI application (which requires Qt)?
37

38
option(UMANS_USE_GUI_APPLICATION "Include a GUI demo application (which relies on Qt)" ON)
39

VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
40
# === Use multithreading?
41

42 43
option(UMANS_USE_MULTITHREADING "Allow the program to use multiple parallel threads" ON)
if (UMANS_USE_MULTITHREADING)
44
	if (MSVC)
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
45 46 47
	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /openmp")
	else()
	  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
48 49
    endif ()
endif (UMANS_USE_MULTITHREADING)
50

VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
51 52 53
# === Linux compatibility compiler option

if (NOT MSVC)
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
54
	add_definitions(-O3 -lstdc++fs -fPIC -shared)
55
endif() 
56

57 58
# === Engine project: a static library that performs the simulation

59
add_library(Engine STATIC ${src_Engine})
60

61 62
# === Console application

VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
63
if (WIN32)
64 65
	add_executable(UMANS-ConsoleApplication-Windows ${src_ConsoleApplication})
	target_link_libraries(UMANS-ConsoleApplication-Windows Engine)
VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
66
else()
67 68
	add_executable(UMANS-ConsoleApplication-Linux  ${src_ConsoleApplication})
	target_link_libraries(UMANS-ConsoleApplication-Linux Engine)
VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
69
endif()
70

71
# === Dynamic library (e.g. a DLL on Windows) to include into other programs
Javad AMIRIAN's avatar
Javad AMIRIAN committed
72

73 74
add_library(UMANS-Library SHARED ${src_Library})
target_link_libraries(UMANS-Library Engine)
75

76 77 78 79
# === Qt demo project (if enabled)

if (UMANS_USE_GUI_APPLICATION)

Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
80 81 82 83 84
	# necessary: gives the path to GUI src files to qt autogen files
	include_directories( ./src/GUI/ )

	# set autogen variables for qt
	set(CMAKE_INCLUDE_CURRENT_DIR ON)
85
	set(CMAKE_AUTOUIC ON)
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
86 87 88 89 90 91 92
	set(CMAKE_AUTOMOC ON)
	set(CMAKE_AUTORCC ON)
	
	# find relevant packages
	find_package(Qt5Core REQUIRED)
	find_package(Qt5Widgets REQUIRED)
	find_package(OpenGL REQUIRED)
93 94

	# --- include the Qt resources, so that the application icon gets shown
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
95
	set(UI_RESOURCES src/GUI/UMANSQtGuiApplication.qrc)
96
	qt5_add_resources(UI_RESOURCES_RCC ${UI_RESOURCES})
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
97
	
98
	# --- define the project itself
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
99
	add_executable(UMANS-GUI src/GUI/main.cpp ${src_GUI} ${UI_RESOURCES_RCC} ${UI_HEADERS})
100 101

	# --- the project depends on some libraries
Fabien Grzeskowiak's avatar
Fabien Grzeskowiak committed
102
	target_link_libraries(UMANS-GUI Engine Qt5::Core Qt5::Widgets ${OPENGL_LIBRARIES})
103 104

	# --- post-build command: copy the required Qt DLLs, to prevent runtime errors
105 106 107 108
	add_custom_command(TARGET UMANS-GUI POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:UMANS-GUI>
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:UMANS-GUI>
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:UMANS-GUI>
109 110 111 112
		)

endif (UMANS_USE_GUI_APPLICATION)

113
# === Clean up the project's directory structure
114

115
foreach(_source IN ITEMS ${src_All})
116
    get_filename_component(_source_path "${_source}" PATH)
117
    file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}/src/" "${_source_path}")
118 119 120
    string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
    source_group("${_group_path}" FILES "${_source}")
endforeach()
121