CMakeLists.txt 4.19 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

21
cmake_minimum_required( VERSION 2.8 )
22
project( UMANS )
LOPEZ GANDIA Axel's avatar
LOPEZ GANDIA Axel committed
23
set (CMAKE_CXX_STANDARD 14)
24

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

27 28 29 30 31
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/* )
file( GLOB_RECURSE src_QtDemo src/QtDemo/* )
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 39

option(UMANS_USE_GUI_APPLICATION "Include a GUI demo application (which relies on Qt)" OFF)

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 54
# === Linux compatibility compiler option

if (NOT MSVC)
	add_definitions(-fPIC)
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
	add_executable(UMANS_ConsoleApplication_Windows ${src_ConsoleApplication})
65
	target_link_libraries(UMANS_ConsoleApplication_Windows Engine)
VAN TOLL Wouter's avatar
VAN TOLL Wouter committed
66
else()
67
	add_executable(UMANS_ConsoleApplication_Linux  ${src_ConsoleApplication})
68
	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
add_library(UMANS_Library SHARED ${src_Library})
74
target_link_libraries(UMANS_Library Engine)
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
# === Qt demo project (if enabled)

if (UMANS_USE_GUI_APPLICATION)

	set(CMAKE_AUTOMOC ON)
	set(CMAKE_AUTOUIC ON)
	set (CMAKE_INCLUDE_CURRENT_DIR ON)
	# --- NOTE: To let this line work, add the following environment variable:
	#	  CMAKE_PREFIX_PATH
	#     with a value such as C:\Qt\5.12.0\msvc2017_64 (depending on your Qt installation)
	find_package(Qt5 COMPONENTS Core Widgets REQUIRED)

	# --- include the Qt resources, so that the application icon gets shown
	set(UI_RESOURCES QtDemo/UMANSQtGuiApplication.qrc )
	qt5_add_resources(UI_RESOURCES_RCC ${UI_RESOURCES})

	# --- define the project itself
93
	add_executable(UMANS_QtDemo src/QtDemo/main.cpp ${src_QtDemo} ${UI_RESOURCES_RCC})
94 95 96 97 98 99 100 101 102 103 104 105 106

	# --- the project depends on some libraries
	target_link_libraries(UMANS_QtDemo Engine Qt5::Widgets opengl32.lib glu32.lib)

	# --- post-build command: copy the required Qt DLLs, to prevent runtime errors
	add_custom_command(TARGET UMANS_QtDemo POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:UMANS_QtDemo>
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:UMANS_QtDemo>
		COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:UMANS_QtDemo>
		)

endif (UMANS_USE_GUI_APPLICATION)

107
# === Clean up the project's directory structure
108

109
foreach(_source IN ITEMS ${src_All})
110
    get_filename_component(_source_path "${_source}" PATH)
111
    file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}/src/" "${_source_path}")
112 113 114
    string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
    source_group("${_group_path}" FILES "${_source}")
endforeach()
115