forked from richefeu/rockable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·386 lines (315 loc) · 11.3 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
cmake_minimum_required(VERSION 3.23)
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_COMPILER_ID "GNU")
set(CMAKE_CXX_COMPILER "g++-14")
message(STATUS "On apple computers, you need to install the last g++ compiler (g++-14)")
endif()
project(Rockable LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# All compiled applications will be in the BUILD folder
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
######################################################################
# OPTIONS
option(ROCKABLE_USE_FT_CORR "add objectivity correction to tangent forces" OFF)
option(ROCKABLE_USE_TESTING "add tests" ON)
option(ROCKABLE_ENABLE_PROFILING "enable the time profiling" OFF)
option(ROCKABLE_ENABLE_BOUNDARY "enable the special boundaries like Ball or Cylinder" OFF)
option(ROCKABLE_ENABLE_SOFT_PARTICLES "enable strainning of particles" OFF)
option(ROCKABLE_ENABLE_PERIODIC "enable full periodic boundary conditions" OFF)
option(ROCKABLE_COMPILE_POSTPRO "Compile the application to run post-processing commands" OFF)
option(ROCKABLE_COMPILE_SEE "Compile the glut application to visualize the conf-files" ON)
option(ROCKABLE_COMPILE_SEE2 "Compile the glfw application to visualize the conf-files" OFF)
option(ROCKABLE_COMPILE_SEE3 "Compile the application to edit graphically the input files" OFF)
option(ROCKABLE_COMPILE_PREPRO "Compile the preprocessing tools" ON)
option(ROCKABLE_COMPILE_CONF2VTK "Convert conf files to VTK" ON)
######################################################################
# compilation flags
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
message(STATUS "Build type is set to Release")
endif()
if(ROCKABLE_USE_FT_CORR)
add_definitions(-DFT_CORR)
endif()
if(ROCKABLE_ENABLE_PROFILING)
add_compile_options(-DROCKABLE_ENABLE_PROFILING)
endif()
if(ROCKABLE_ENABLE_BOUNDARY)
add_compile_options(-DROCKABLE_ENABLE_BOUNDARY)
endif()
# get the git tag of Rockable
execute_process(
COMMAND git describe --abbrev=0 --tags
OUTPUT_VARIABLE ROCKABLE_GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions(-DROCKABLE_GIT_TAG="${ROCKABLE_GIT_TAG}")
message(STATUS "ROCKABLE_GIT_TAG = " ${ROCKABLE_GIT_TAG})
# the default mode is release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
include(FetchContent)
set(FETCHCONTENT_BASE_DIR ${CMAKE_SOURCE_DIR}/deps)
#include(ExternalProject)
######################################################################
##### Fetching TOOFUS
FetchContent_Declare (
toofus
GIT_REPOSITORY https://github.com/richefeu/toofus.git
GIT_TAG main
)
FetchContent_GetProperties(toofus)
if(NOT toofus_POPULATED)
message(STATUS "Fetching toofus")
FetchContent_MakeAvailable(toofus)
endif()
######################################################################
##### Fetching fmt
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master
GIT_PROGRESS TRUE
USES_TERMINAL_DOWNLOAD TRUE
)
FetchContent_GetProperties(fmt)
if(NOT fmt_POPULATED)
message(STATUS "Fetching fmt")
FetchContent_MakeAvailable(fmt)
endif()
######################################################################
##### MATools
if(ROCKABLE_ENABLE_PROFILING)
FetchContent_Declare (
matools
GIT_REPOSITORY https://github.com/rprat-pro/MATools
GIT_TAG v1.1
)
FetchContent_GetProperties(matools)
if(NOT matools_POPULATED)
message(STATUS "Fetching MATools")
FetchContent_MakeAvailable(matools)
SET(MATOOLS_MPI OFF CACHE BOOL "Use some expat option")
add_subdirectory(${FETCHCONTENT_BASE_DIR}/matools-src)
endif()
endif()
######################################################################
##### tclap
FetchContent_Declare (
tclap
GIT_REPOSITORY https://github.com/xguerin/tclap.git
GIT_TAG v1.2.5
)
FetchContent_GetProperties(tclap)
if(NOT tclap_POPULATED)
message(STATUS "Fetching tclap")
FetchContent_MakeAvailable(tclap)
endif()
######################################################################
##### nlohmann-json
FetchContent_Declare (
nlohmann-json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
)
FetchContent_GetProperties(nlohmann-json)
if(NOT nlohmann-json_POPULATED)
message(STATUS "Fetching nlohmann-json")
FetchContent_MakeAvailable(nlohmann-json)
endif()
######################################################################
##### imgui
if(ROCKABLE_COMPILE_SEE3)
FetchContent_Declare (
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.89.5
)
FetchContent_GetProperties(imgui)
if(NOT imgui_POPULATED)
message(STATUS "Fetching imgui")
FetchContent_MakeAvailable(imgui)
endif()
endif() # end of ROCKABLE_COMPILE_SEE3
####################################################################
### Chaiscript
#FetchContent_Declare (
# ChaiScript
# GIT_REPOSITORY https://github.com/ChaiScript/ChaiScript.git
# GIT_TAG v6.1.0
#)
#FetchContent_GetProperties(ChaiScript)
#if(NOT chaiscript_POPULATED)
# message(STATUS "Fetching ChaiScript")
# FetchContent_Populate(ChaiScript)
# add_subdirectory(${chaiscript_SOURCE_DIR})
#endif()
######################################################################
##### OpenMP
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
######################################################################
##### OpenGL
find_package(OpenGL REQUIRED)
if(OPENGL_FOUND)
message(STATUS "OPENGL_INCLUDE_DIR = " ${OPENGL_INCLUDE_DIR})
message(STATUS "OPENGL_LIBRARIES = " ${OPENGL_LIBRARIES})
endif()
######################################################################
#### glut
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
# here, we do not uses find_package(glut) so that the version installed by apple is NOT used
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLUT REQUIRED glut>=3.4.0)
if(GLUT_FOUND)
message(STATUS "GLUT as been found with PkgConfig")
message(STATUS "GLUT_LIBRARY_DIRS = " ${GLUT_LIBRARY_DIRS})
message(STATUS "GLUT_INCLUDE_DIRS = " ${GLUT_INCLUDE_DIRS})
message(STATUS "GLUT_LIBRARIES = " ${GLUT_LIBRARIES})
endif()
else()
find_package(GLUT REQUIRED)
if(GLUT_FOUND)
message(STATUS "GLUT_INCLUDE_DIRS = " ${GLUT_INCLUDE_DIRS})
message(STATUS "GLUT_LIBRARIES = " ${GLUT_LIBRARIES})
endif()
endif()
######################################################################
#### glfw
if(ROCKABLE_COMPILE_SEE2 OR ROCKABLE_COMPILE_SEE3)
#find_package(glfw3 CONFIG REQUIRED)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw
)
FetchContent_GetProperties(glfw)
if(NOT glfw_POPULATED)
FetchContent_MakeAvailable(glfw)
set(GLFW_BUILD_EXAMPLES OFF CACHE INTERNAL "Build the GLFW example programs")
set(GLFW_BUILD_TESTS OFF CACHE INTERNAL "Build the GLFW test programs")
set(GLFW_BUILD_DOCS OFF CACHE INTERNAL "Build the GLFW documentation")
set(GLFW_INSTALL OFF CACHE INTERNAL "Generate installation target")
add_subdirectory(${glfw_SOURCE_DIR} ${glfw_BINARY_DIR})
endif()
endif()
######################################################################
##### libRockable_core
set(CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
include_directories(
${CMAKE_SOURCE_DIR}
${toofus_SOURCE_DIR}
${tclap_SOURCE_DIR}/include
${fmt_SOURCE_DIR}/include
)
file(GLOB core_object_files
${CMAKE_SOURCE_DIR}/BodyForces/*.cpp
${CMAKE_SOURCE_DIR}/Core/*.cpp
${CMAKE_SOURCE_DIR}/DataExtractors/*.cpp
${CMAKE_SOURCE_DIR}/ForceLaws/*.cpp
${CMAKE_SOURCE_DIR}/PostProcessors/*.cpp
${CMAKE_SOURCE_DIR}/PreproCommands/*.cpp
${CMAKE_SOURCE_DIR}/ProcessingTools/*.cpp
)
if(ROCKABLE_ENABLE_BOUNDARY)
file(GLOB boundaries_files ${CMAKE_SOURCE_DIR}
/Boundaries/*.cpp
)
list(APPEND core_object_files ${boundaries_files})
endif() # end of ROCKABLE_ENABLE_BOUNDARY
add_library(Rockable_core STATIC ${core_object_files})
if(ROCKABLE_ENABLE_PROFILING)
target_link_libraries(Rockable_core MATools)
endif()
######################################################################
##### rockable executable (to run simulations from the console)
add_executable(rockable ${CMAKE_SOURCE_DIR}/Apps/run.cpp)
target_link_libraries(rockable PUBLIC Rockable_core)
install(TARGETS rockable DESTINATION ./)
######################################################################
##### postpro
if(ROCKABLE_COMPILE_POSTPRO)
add_executable(postpro ${CMAKE_SOURCE_DIR}/Apps/postpro.cpp)
target_link_libraries(postpro PUBLIC Rockable_core)
endif()
######################################################################
##### visualiser see (it uses glut)
if(ROCKABLE_COMPILE_SEE)
find_package(PNG REQUIRED)
if(PNG_FOUND)
message(STATUS "libpng found: ${PNG_INCLUDE_DIRS}")
else()
message(STATUS "libpng not found")
endif()
add_executable(see ${CMAKE_SOURCE_DIR}/Apps/see.cpp)
if(PNG_FOUND)
# Pour le moment on compile sans libpng car il y a un problème sur mac
# Les screenshots seront sauvegardés en tga
# target_compile_options(see PRIVATE -DPNG_H)
endif()
target_include_directories(see PRIVATE
${OPENGL_INCLUDE_DIR}
${GLUT_INCLUDE_DIRS}
${nlohmann-json_SOURCE_DIR}/include
${PNG_INCLUDE_DIRS}
)
target_link_directories(see PRIVATE
${GLUT_LIBRARY_DIRS}
${PNG_LIBRARY}
)
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (see PUBLIC OpenGL::GL OpenGL::GLU ${GLUT_LIBRARIES} Rockable_core PNG::PNG)
else()
target_link_libraries (see PUBLIC OpenGL::GL OpenGL::GLU ${GLUT_LIBRARIES} Rockable_core PNG::PNG)
endif()
install(TARGETS see DESTINATION ./)
endif()
######################################################################
##### interactive preprocessing (TODO see3 -> will be renamed something like 'craft' or 'look')
##### Before, the use of glfw will be replaced by glut (to avoid issues with macosx)
if(ROCKABLE_COMPILE_SEE3)
set(see3_files
${CMAKE_SOURCE_DIR}/Apps/see3.cpp
${imgui_SOURCE_DIR}/imgui.cpp
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)
add_executable(see3 ${see3_files})
target_include_directories(see3 PUBLIC
${OPENGL_INCLUDE_DIR}
${imgui_SOURCE_DIR}
${imgui_SOURCE_DIR}/backends
${nlohmann-json_SOURCE_DIR}/include
)
if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (see3 PUBLIC glfw OpenGL::GL OpenGL::GLU Rockable_core)
else()
target_link_libraries (see3 PUBLIC glfw OpenGL::GL OpenGL::GLU Rockable_core)
endif()
install(TARGETS see3 DESTINATION ./)
endif() # end of ROCKABLE_COMPILE_SEE3
######################################################################
#####
if(ROCKABLE_COMPILE_CONF2VTK)
add_executable(conftovtk ${CMAKE_SOURCE_DIR}/Apps/conftovtk.cpp)
target_link_libraries (conftovtk Rockable_core)
install(TARGETS conftovtk DESTINATION ./)
endif()
######################################################################
##### Enable non regression tests
if(ROCKABLE_USE_TESTING)
enable_testing()
add_subdirectory(test)
endif()
######################################################################
##### Pre-processing tools
if(ROCKABLE_COMPILE_PREPRO)
add_subdirectory(prepro)
endif()