-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
240 lines (196 loc) · 7.34 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(PathFinding LANGUAGES CXX)
set(CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED On)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Enabled release build")
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
if (CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "Enabled aggressive warnings")
if (GEN_STATS)
add_definitions (-DGEN_STATS)
endif(GEN_STATS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wpedantic -pedantic -pedantic-errors -march=native")
endif(CMAKE_COMPILER_IS_GNUCXX)
# Boost (system + filesystem)
#########################################
find_package(Boost REQUIRED
COMPONENTS "system" "filesystem" "thread")
add_library(boost-system SHARED IMPORTED)
set_property(
TARGET boost-system
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(
TARGET boost-system
PROPERTY IMPORTED_LOCATION ${Boost_SYSTEM_LIBRARY})
add_library(boost-filesystem SHARED IMPORTED)
set_property(
TARGET boost-filesystem
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(
TARGET boost-filesystem
PROPERTY IMPORTED_LOCATION ${Boost_FILESYSTEM_LIBRARY})
add_library(boost-thread SHARED IMPORTED)
set_property(
TARGET boost-thread
PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set_property(
TARGET boost-thread
PROPERTY IMPORTED_LOCATION ${Boost_THREAD_LIBRARY})
# SDL2 + SDL2_ttf
#########################################
# Use until SDL2 is added to built-in CMake
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PathFinding_SOURCE_DIR}/cmake")
find_package(SDL2 REQUIRED)
add_library(sdl2 SHARED IMPORTED)
# WKK: Disgusting Hack which should be somehow avoided in the future
# 1). Splice the 1st element out of the array and mark as "primary"
# 2). Mark remaining array elements as dependent libraries
# 3). Cry in a corner
list(GET SDL2_LIBRARY 1 "SDL2_CORE_LIB")
list(REMOVE_AT SDL2_LIBRARY 1)
set_property(TARGET sdl2 PROPERTY IMPORTED_LOCATION "${SDL2_CORE_LIB}")
set_property(TARGET sdl2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}")
set_property(TARGET sdl2 PROPERTY IMPORTED_LINK_DEPENDENT_LIBRARIES "${SDL2_LIBRARY}")
find_package(SDL2_ttf REQUIRED)
add_library(sdl2-ttf SHARED IMPORTED)
set_property(TARGET sdl2-ttf PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL2_TTF_INCLUDE_DIR}")
set_property(TARGET sdl2-ttf PROPERTY IMPORTED_LOCATION "${SDL2_TTF_LIBRARIES}")
# PThreads
#########################################
set(THREADS_PREFER_PTHREAD_FLAG On)
find_package(Threads REQUIRED)
# TBB
########################################
find_package(TBB REQUIRED)
# Common Sources and Includes
#########################################
set(DEFAULT_INCLUDE_DIR includes)
add_library(common
src/common/World.cc)
target_include_directories(common PUBLIC ${DEFAULT_INCLUDE_DIR})
target_link_libraries(common PUBLIC boost-system boost-filesystem)
add_library(algorithm
src/algorithms/tools/PathTile.cc
src/algorithms/tools/PriorityQueue.cc)
target_include_directories(algorithm PUBLIC ${DEFAULT_INCLUDE_DIR})
target_link_libraries(algorithm PUBLIC common)
# Assistive Macros
#########################################
macro(add_custom_executable)
set(options )
set(singleValueArgs NAME)
set(multiValueArgs INCLUDES LIBRARIES SOURCES)
cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${arg_NAME} ${arg_SOURCES})
target_include_directories(${arg_NAME} PUBLIC ${DEFAULT_INCLUDE_DIR} ${arg_INCLUDES})
target_link_libraries(${arg_NAME} PRIVATE common PUBLIC ${arg_LIBRARIES})
endmacro(add_custom_executable)
macro(add_algorithm)
set(options )
set(singleValueArgs NAME SOURCE)
set(multiValueArgs INCLUDES LIBRARIES)
cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${arg_NAME} ${arg_SOURCE})
target_include_directories(${arg_NAME} PUBLIC ${DEFAULT_INCLUDE_DIR} ${arg_INCLUDES})
target_link_libraries(${arg_NAME} PRIVATE algorithm PUBLIC ${arg_LIBRARIES})
endmacro(add_algorithm)
# Executables
#########################################
add_custom_executable(
NAME gui
LIBRARIES sdl2 sdl2-ttf
SOURCES
src/gui/Gui.cc
src/gui/Error.cc
src/gui/Window.cc
src/gui/Viewport.cc
src/gui/Button.cc
src/gui/TextInput.cc
src/gui/WorldViewport.cc
src/gui/GraphicTile.cc
src/gui/Text.cc
src/gui/ToolbarViewport.cc)
add_custom_executable(
NAME worldGen
SOURCES src/worldGen/WorldGen.cc)
add_custom_executable(
NAME pathGen
SOURCES src/worldGen/PathGen.cc)
add_algorithm(
NAME dijkstra
SOURCE src/algorithms/dijkstra/Dijkstra.cc)
add_algorithm(
NAME aStar
SOURCE src/algorithms/aStar/AStar.cc)
add_algorithm(
NAME bidir
SOURCE src/algorithms/bidirectional/Bidirectional.cc)
add_algorithm(
NAME parBidir
SOURCE src/algorithms/parBidirectional/ParBidirectional.cc
LIBRARIES Threads::Threads)
add_algorithm(
NAME fringe
SOURCE src/algorithms/fringe/Fringe.cc
LIBRARIES Threads::Threads)
add_algorithm(
NAME parFringe_2
SOURCE src/algorithms/parFringe/ParFringe.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parFringe_2 PRIVATE NUMBER_OF_THREADS=2)
add_algorithm(
NAME parFringe_4
SOURCE src/algorithms/parFringe/ParFringe.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parFringe_4 PRIVATE NUMBER_OF_THREADS=4)
add_algorithm(
NAME parFringe_6
SOURCE src/algorithms/parFringe/ParFringe.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parFringe_6 PRIVATE NUMBER_OF_THREADS=6)
add_algorithm(
NAME parFringe_8
SOURCE src/algorithms/parFringe/ParFringe.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parFringe_8 PRIVATE NUMBER_OF_THREADS=8)
add_algorithm(
NAME parFringe_optimal
SOURCE src/algorithms/parFringe/ParFringe.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parFringe_optimal PRIVATE NUMBER_OF_THREADS=8 OPTIMAL=true)
add_algorithm(
NAME parDivide_4
SOURCE src/algorithms/parDivide/ParDivide.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivide_4 PRIVATE NUMBER_OF_THREADS=4)
add_algorithm(
NAME parDivide_6
SOURCE src/algorithms/parDivide/ParDivide.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivide_6 PRIVATE NUMBER_OF_THREADS=6)
add_algorithm(
NAME parDivide_8
SOURCE src/algorithms/parDivide/ParDivide.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivide_8 PRIVATE NUMBER_OF_THREADS=8)
add_algorithm(
NAME parDivideUnsmooth_4
SOURCE src/algorithms/parDivide/parDivideUnsmooth.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivideUnsmooth_4 PRIVATE NUMBER_OF_THREADS=4)
add_algorithm(
NAME parDivideUnsmooth_6
SOURCE src/algorithms/parDivide/parDivideUnsmooth.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivideUnsmooth_6 PRIVATE NUMBER_OF_THREADS=6)
add_algorithm(
NAME parDivideUnsmooth_8
SOURCE src/algorithms/parDivide/parDivideUnsmooth.cc
LIBRARIES Threads::Threads tbb boost-thread)
target_compile_definitions (parDivideUnsmooth_8 PRIVATE NUMBER_OF_THREADS=8)
add_custom_target(clean_results
COMMAND rm -R -f ${CMAKE_SOURCE_DIR}/results/*)
add_custom_target(clean_worlds
COMMAND rm -R -f ${CMAKE_SOURCE_DIR}/worlds/*)