-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
208 lines (184 loc) · 8.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(SEGS)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# for version and revision info. Derived from https://github.com/dolphin-emu/dolphin/blob/master/CMakeLists.txt#L132
find_package(Git)
if(GIT_FOUND)
# defines SEGS_REVISION
execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE SEGS_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# defines SEGS_DESCRIPTION
execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --long --dirty
OUTPUT_VARIABLE SEGS_DESCRIPTION
OUTPUT_STRIP_TRAILING_WHITESPACE)
# remove hash (and trailing "-0" if needed) from description
string(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" SEGS_DESCRIPTION "${SEGS_DESCRIPTION}")
# defines SEGS_BRANCH
execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE SEGS_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
# version number
set(SEGS_VERSION_MAJOR "0")
set(SEGS_VERSION_MINOR "6")
set(SEGS_VERSION_PATCH "1")
# If SEGS is not built from a Git repository, default the version info to
# reasonable values.
if(NOT SEGS_REVISION)
set(SEGS_DESCRIPTION "${SEGS_VERSION_MAJOR}.${SEGS_VERSION_MINOR}.${SEGS_VERSION_PATCH}")
set(SEGS_REVISION "${SEGS_DESCRIPTION} (no further info)")
set(SEGS_BRANCH "develop")
endif()
add_definitions(
"-DSEGS_VERSION=\"${SEGS_VERSION_MAJOR}.${SEGS_VERSION_MINOR}.${SEGS_VERSION_PATCH}\""
"-DSEGS_BRANCH=\"${SEGS_BRANCH}\""
"-DSEGS_DESCRIPTION=\"${SEGS_DESCRIPTION}\""
)
IF(MSVC)
add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -DNOMINMAX -D_USE_MATH_DEFINES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wuseless-cast -std=c++14")
if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
endif()
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra -Wuseless-cast -std=c++14 -Wno-nested-anon-types -Wno-gnu-anonymous-struct -Wno-gnu-zero-variadic-macro-arguments")
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(AUTOGEN_TARGETS_FOLDER ON)
add_definitions(-D__STDC_FORMAT_MACROS)
SET(MAIN_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/3rd_party/include CACHE PATH "Includes")
SET(MAIN_LIB_PATH ${PROJECT_SOURCE_DIR}/3rd_party/lib CACHE PATH "Libraries")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/out)
SET(CMAKE_INCLUDE_PATH ${MAIN_INCLUDE_PATH})
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts;${CMAKE_MODULE_PATH})
SET(UNICODE TRUE)
set(INSTALLED_TARGETS)
OPTION(ENABLE_SCRIPTING_ENGINE "Build experimental scripting engine ?" ON)
OPTION(ENABLE_TESTS "Enable testing unit and functional tests" OFF)
OPTION(BUILD_COX_MAP_VIEWER "Build CoX map file viewer ?" OFF)
OPTION(BUILD_RPC_TEST_CLIENT "Build RPC Test Client ?" OFF)
########################################################################################
# Prerequisites
########################################################################################
find_package(Threads REQUIRED)
include(3rdparty_support)
set(ThirdParty_Install_Dir ${CMAKE_BINARY_DIR}/3rd_party/built) # ERICEDIT: Changed to CMAKE_BINARY_DIR so that this variable always points to the top level of the build directory.
add_subdirectory(3rd_party)
link_directories(${PROJECT_SOURCE_DIR}/lib) # ERICEDIT: Changed to lowercase.
include(LocateQt5)
find_package(Qt5 COMPONENTS Core Sql REQUIRED)
if(ENABLE_TESTS)
enable_testing()
find_package(Qt5 COMPONENTS Test REQUIRED)
# Event registration support functionality
macro(add_segs_test testname) # followed by a list of directories to scan
add_executable(${testname} ${testname}.cpp)
add_test(${testname} ${testname})
target_link_libraries(${testname}
Qt5::Test
${ARGN}
)
set_target_properties (${testname} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/utilities/unit_tests
)
endmacro()
endif()
link_directories(${ThirdParty_Install_Dir}/lib)
include_directories(SYSTEM ${ThirdParty_Install_Dir}/include)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/3rd_party)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(Components)
# this has to be visited before scan_event_types macro below has been used
add_subdirectory(Utilities)
# this function is here to solve the env paths issue
function(to_path_list var path1)
if("${CMAKE_HOST_SYSTEM}" MATCHES ".*Windows.*")
set(sep "\\;")
else()
set(sep ":")
endif()
set(result "${path1}") # First element doesn't require separator at all...
foreach(path ${ARGN})
set(result "${result}${sep}${path}") # .. but other elements do.
endforeach()
set(${var} "${result}" PARENT_SCOPE)
endfunction()
##############################################
# Event registration support functionality
macro(scan_event_types group) # followed by a list of directories to scan
set(all_headers)
foreach(path ${ARGN})
message("Scanning ${path} for events")
file(GLOB headers ${path}/*.h)
list(APPEND all_headers ${headers})
endforeach()
to_path_list(path_with_qt5 $ENV{PATH} ${Qt5_BIN_DIR} )
# for event_gen we first add qt5 binary path to allow it to run during build.
add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env "PATH=${path_with_qt5}" $<SHELL_PATH:$<TARGET_FILE:event_gen>> scan_events ${group} ${CMAKE_CURRENT_BINARY_DIR}/ ${ARGN}
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${group}.gen.cpp
DEPENDS event_gen ${all_headers}
COMMENT "Generating ${group} implementation source"
)
endmacro()
macro(add_event_sources group tgt_var)
list(APPEND ${tgt_var} ${CMAKE_CURRENT_BINARY_DIR}/${group}.gen.cpp)
message("adding ${group} to sources")
endmacro()
macro(add_messages_library name )
#find handler's events
scan_event_types(${name}Events ${CMAKE_CURRENT_SOURCE_DIR})
add_event_sources(${name}Events ${name}_SOURCES)
add_library(${name}_interface STATIC ${${name}_SOURCES} ${ARGN})
# allow all headers to refer to events by their dir/name.h
target_include_directories(${name}_interface PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_link_libraries(${name}_interface PUBLIC Qt5::Core)
# all interfaces use stuff from Common, so should depend/link to it
target_link_libraries(${name}_interface PUBLIC SEGS_Components)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ARGN})
set_target_properties (${name}_interface PROPERTIES
FOLDER Projects/CoX/Common/Messages
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/utilities/unit_tests
)
endmacro()
macro(add_handler name)
# TODO: consider add_subdirectory(../../Common/Messages/${name}) to force existence/building of interface lib
# add the implementation library
add_library(${name} STATIC ${ARGN})
target_link_libraries(${name} PUBLIC ${name}_interface)
endmacro()
##############################################
add_subdirectory(Components)
add_subdirectory(Projects)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/data)
set(MAPNAMES
City_00_01
City_01_01 City_01_02 City_01_03
City_02_01 City_02_02
City_03_01 City_03_02
City_04_01 City_04_02
City_05_01
Hazard_01_01
Hazard_02_01
Hazard_03_01
Hazard_04_01 Hazard_04_02
Hazard_05_01
Trial_01_01 Trial_01_02
Trial_02_01
Trial_03_01
Trial_04_01 Trial_04_02
Trial_05_01
)
foreach(MAPDIR ${MAPNAMES})
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/maps/${MAPDIR})
endforeach(MAPDIR)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default_setup)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/logs)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/scripts)