-
Notifications
You must be signed in to change notification settings - Fork 36
/
CMakeLists.txt
451 lines (392 loc) · 17.7 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
cmake_minimum_required (VERSION 3.25)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the type of build, options are: Debug Release
RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of
build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
Release RelWithDebInfo MinSizeRel.")
ELSE()
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")
ENDIF()
########## OPTIONS
project(DynamO) #Project name
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
enable_testing() #Enable build of test executables and 'make test' command
include(CTest)
######################################################################
########## Packaging
######################################################################
include(SystemInformation)
include(GetGitRevisionDescription)
find_package(Python3 COMPONENTS Interpreter NumPy)
git_describe(GIT_RESULT --match initial-commit)
message(STATUS "Git description is ${GIT_RESULT}")
string(REGEX MATCH "[0-9]+" BUILD_NUMBER ${GIT_RESULT})
message(STATUS "Build number is ${BUILD_NUMBER}")
if(NOT DEFINED CPACK_GENERATOR)
set(CPACK_GENERATOR ${SPECIFIC_SYSTEM_PREFERED_CPACK_GENERATOR})
endif()
set(PACKAGE_SUFFIX "" CACHE STRING "A suffix to add to the end of the built packages")
set(CPACK_PACKAGE_NAME "dynamomd")
set(CPACK_PACKAGE_VERSION_MAJOR 1)
set(CPACK_PACKAGE_VERSION_MINOR 7)
set(CPACK_PACKAGE_VERSION_PATCH ${BUILD_NUMBER})
set(CPACK_PACKAGE_CONTACT "Marcus Bannerman <support@dynamomd.org>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Event-driven particle simulation sofware")
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/description.txt)
set(CPACK_PACKAGE_DESCRIPTION "This package includes the DynamO executables and scripts. DynamO is an event driven simulator capable of performing molecular and granular dynamics simulations")
if(Python3_FOUND)
set(CPACK_DEBIAN_PACKAGE_DEPENDS " python3")
endif()
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}${PACKAGE_SUFFIX})
set(CPACK_DEBIAN_PACKAGE_SECTION "science")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://dynamomd.org")
#Get Debian packages to automatically figure out the dependencies
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_WIX_UPGRADE_GUID "c70e546c-a36a-429f-a2df-f5e6cf787bb4")
set(CPACK_WIX_PRODUCT_GUID "36fe5a30-bd03-423b-822a-f505d0fa6564")
include(CPack) #Enable build of packages
install(FILES ${CMAKE_SOURCE_DIR}/copyright DESTINATION share/doc/${CPACK_PACKAGE_NAME})
######################################################################
########## Git submodules
######################################################################
########## Check we have git submodules installed!
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/stator/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
######################################################################
########## COMPILER FLAGS
######################################################################
########## RELEASE MODE
if(WIN32)
add_definitions(-D_USE_MATH_DEFINES)
add_definitions(-DNOMINMAX)
endif()
if(NOT WIN32)
link_libraries(debug dl)
endif()
if(MSVC)
#MSVC has crazy warnings for -Wall, we'll build up support to the higher warning levels
add_compile_options(-W1)
#Enable the math defines (like M_PI!)
add_definitions(-D_USE_MATH_DEFINES)
#MSVC Crazily has "min" and "max" (yes, lowercase!) Macros defined
#which conflict with the C++ standard algorithms! This define
#instructs the compiler to not be an idiot and define those macros
add_definitions(-DNOMINMAX)
else()
add_compile_options(-Wall)
endif()
########## DEBUG MODE
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDYNAMO_DEBUG -DMAGNET_DEBUG")
######################################################################
########## COMPILER C++11/C++0x SUPPORT TESTS
######################################################################
### First check if the compiler supports C++11 or C++0x at all
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++14" COMPILER_SUPPORT_CXX11)
if(COMPILER_SUPPORT_CXX11)
add_compile_options(-std=c++14)
else()
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORT_CXX0X)
if(COMPILER_SUPPORT_CXX0X)
add_compile_options(-std=c++0x)
check_cxx_source_compiles("int main(int, const char**) {int array[5] = {1,2,3,4,5}; for(int& x: array) x *= 2;}" CXX0X_RANGE_BASED_FOR)
if(NOT CXX0X_RANGE_BASED_FOR)
message(SEND_ERROR "The compiler ${CMAKE_CXX_COMPILER} has limited C++11 support. You must install a more modern C++ compiler.")
endif()
else()
message(SEND_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. You must install a more modern C++ compiler.")
endif()
endif()
include_directories(./extern/stator/)
include_directories(./extern/)
######################################################################
# Stack trace support
######################################################################
include(CheckIncludeFiles)
check_include_files(execinfo.h STACKTRACE_AVAILABLE)
if(STACKTRACE_AVAILABLE)
add_definitions(-DMAGNET_STACKTRACE)
endif()
######################################################################
########## Boost support
######################################################################
if(WIN32)
set (Boost_USE_STATIC_LIBS ON)
endif()
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
cmake_policy(SET CMP0167 NEW) # Use the new boost configuration
find_package(Boost 1.70.0 REQUIRED system filesystem program_options unit_test_framework)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
######################################################################
# Determine the supported system thread library and link to it
######################################################################
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
message(STATUS "Adding -pthread as a compile argument")
add_compile_options(-pthread)
endif()
if(CMAKE_THREAD_LIBS_INIT)
message(STATUS "Adding ${CMAKE_THREAD_LIBS_INIT} as a linker argument")
link_libraries(${CMAKE_THREAD_LIBS_INIT})
endif()
######################################################################
# Test for libjudy requirements
######################################################################
check_include_files(Judy.h JUDY_H_AVAILABLE)
include(CheckLibraryExists)
check_library_exists(Judy Judy1FreeArray "" JUDY_LIB_AVAILABLE)
include(CheckTypeSize)
check_type_size(size_t SIZEOF_SIZE_T)
set(LIBJUDY_SUPPORT FALSE)
if(SIZEOF_SIZE_T LESS 8)
message(STATUS "libJudy support disabled (no 64 bit support).")
elseif(JUDY_H_AVAILABLE AND JUDY_LIB_AVAILABLE)
message(STATUS "Enabling libJudy support.")
set(LIBJUDY_SUPPORT TRUE)
add_definitions(-DDYNAMO_JUDY)
link_libraries(Judy)
else()
message(STATUS "libJudy header/library missing.")
endif()
######################################################################
# Visualiser support
######################################################################
INCLUDE (CheckIncludeFiles)
set(OpenGL_GL_PREFERENCE "LEGACY")
find_package(OpenGL)
find_package(GLUT)
find_package(GLEW)
find_package(AVCodec)
find_package(PNG)
find_package(Eigen3)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
set(VISUALIZER_SUPPORT TRUE CACHE BOOL "Attempt to enable the visualiser")
function(visualiser_dependency varname message)
if(${varname})
message(STATUS "${message} found.")
else()
message(STATUS "${message} not found - visualiser will not be built.")
set(VISUALIZER_SUPPORT FALSE PARENT_SCOPE)
endif()
endfunction(visualiser_dependency)
visualiser_dependency(OPENGL_FOUND "OpenGL libraries")
visualiser_dependency(GTKMM_FOUND "GTK/GTKMM 3 library")
visualiser_dependency(PNG_FOUND "libPNG library")
visualiser_dependency(GLUT_FOUND "GLUT/freeGLUT library")
visualiser_dependency(GLEW_FOUND "GLEW library")
#visualiser_dependency(GLX_FOUND "GLX library")
find_path(CAIROMM_INCLUDE_PATH "cairomm.h" PATH_SUFFIXES "cairomm" "cairomm-1.0/cairomm")
find_path(CAIROMM_CONFIG_PATH "cairommconfig.h" PATHS "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}" "/usr/lib64/${CMAKE_LIBRARY_ARCHITECTURE}" PATH_SUFFIXES "cairomm" "cairomm-1.0/cairomm" "cairomm-1.0/include" "lib/cairomm-1.0/include")
if(${CAIROMM_INCLUDE_PATH} STREQUAL "CAIROMM_INCLUDE_PATH-NOTFOUND" OR ${CAIROMM_CONFIG_PATH} STREQUAL "CAIROMM_CONFIG_PATH-NOTFOUND")
message("-- Cairomm headers not found - visualiser will not be built")
unset(CAIROMM_INCLUDE_PATH CACHE)
unset(CAIROMM_CONFIG_PATH CACHE)
set(VISUALIZER_SUPPORT FALSE)
else()
message("-- Cairomm headers found")
endif()
if(VISUALIZER_SUPPORT)
check_include_files(cwiid.h CWIID_H_AVAILABLE)
check_library_exists(cwiid cwiid_open "" CWIID_LIB_AVAILABLE)
if(CWIID_H_AVAILABLE AND CWIID_LIB_AVAILABLE)
message(STATUS "Enabling Wiimote head tracking support")
add_definitions(-DCOIL_wiimote)
link_libraries(cwiid)
endif()
find_package(OpenVR)
if(OPENVR_FOUND)
message("OpenVR found!")
add_definitions(-DCOIL_OpenVR)
include_directories(${OPENVR_INCLUDE_DIRS})
link_libraries(${OPENVR_LIBRARY})
else()
message("OpenVR not found (try setting OPENVR_ROOT_DIR to the location of the openvr git repository")
endif()
add_definitions(${OPENGL_DEFINITONS} ${GLUT_DEFINITIONS} ${GLEW_DEFINITIONS} ${GTKMM_DEFINITIONS})
include_directories(${GTKMM_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${CAIROMM_INCLUDE_PATH} ${CAIROMM_CONFIG_PATH} ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
link_libraries(${GTKMM_LIBRARIES} ${CAIROMM_LIBRARIES} ${PNG_LIBRARIES} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARIES})
endif()
######################################################################
########## HEADER DIRECTORIES
######################################################################
include_directories(${PROJECT_SOURCE_DIR}/src/magnet)
include_directories(${PROJECT_SOURCE_DIR}/src/ext_include)
######################################################################
######### TARGETS
######################################################################
### Magnet library
function(magnet_test name) #Registers a magnet unit-test
add_executable(magnet_${name}_exe ${CMAKE_CURRENT_SOURCE_DIR}/src/magnet/tests/${name}.cpp)
target_link_libraries(magnet_${name}_exe)
add_test(magnet_${name} magnet_${name}_exe)
endfunction(magnet_test)
#magnet_test(scan_test : tests/scan_test.cpp magnet /opencl//OpenCL)
#magnet_test(radixsort_NVIDIA_test : tests/radixsort_NVIDIA_test.cpp magnet /opencl//OpenCL scan_test ;
#magnet_test(radixsort_AMD_test : tests/radixsort_AMD_test.cpp magnet /opencl//OpenCL scan_test ;
#magnet_test(bitonicsort_test : tests/bitonicsort_test.cpp magnet /opencl//OpenCL ;
#magnet_test(heapsort_test : tests/heapsort_test.cpp magnet /opencl//OpenCL ;
#magnet_test(sorter_test : tests/sorter_test.cpp magnet /opencl//OpenCL ;
magnet_test(threadpool_test)
#SET_TARGET_PROPERTIES(magnet_threadpool_test_exe PROPERTIES LINK_FLAGS -Wl,--no-as-needed) #Fix for a bug in gcc
target_link_libraries(magnet_threadpool_test_exe ${CMAKE_THREAD_LIBS_INIT})
magnet_test(cubic_quartic_test)
magnet_test(vector_test)
magnet_test(quaternion_test)
magnet_test(dilate_test)
magnet_test(splinetest)
magnet_test(plane_intersection)
magnet_test(triangle_intersection)
magnet_test(intersection_genalg)
magnet_test(offcenterspheres)
magnet_test(stack_vector_test)
if(JUDY_SUPPORT)
magnet_test(judy_test)
endif(JUDY_SUPPORT)
if(AVCodec_FOUND)
set(CMAKE_REQUIRED_INCLUDES ${AVCodec_INCLUDE_DIRS})
check_cxx_source_compiles("#include <libavcodec/avcodec.h>
int main() { &avcodec_send_frame; return 0; }" AVCodec_Send_Frame_Avail)
if(${AVCodec_Send_Frame_Avail})
message(STATUS "Found suitable libAVCodec version")
link_libraries(${AVCodec_LIBRARIES})
include_directories(${AVCodec_INCLUDE_DIRS})
add_definitions(-DMAGNET_FFMPEG_SUPPORT)
else()
message(STATUS "libAVCodec version is out of date or incompatible - recording will be disabled")
endif()
endif()
### DynamO
file(GLOB_RECURSE dynamo_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/dynamo/*.cpp)
add_library(dynamo STATIC ${dynamo_SRC})
target_link_libraries(dynamo PUBLIC Boost::program_options Boost::system Boost::filesystem Eigen3::Eigen)
target_include_directories(dynamo PUBLIC ${PROJECT_SOURCE_DIR}/src/dynamo/)
######################################################################
# Test for libbz2 (for compressed files)
######################################################################
if(NOT WIN32)
find_package(BZip2)
if(BZIP2_FOUND)
target_include_directories(dynamo PRIVATE ${BZIP2_INCLUDE_DIR})
target_link_libraries(dynamo PRIVATE ${BZIP2_LIBRARIES})
target_compile_definitions(dynamo PUBLIC DDYNAMO_bzip2_support=1)
endif()
endif()
### Coil
# configuration
if(VISUALIZER_SUPPORT)
message(STATUS "Visualiser dependencies satisfied.")
# Coil library
file(GLOB_RECURSE coil_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/coil/coil/*.cpp)
add_library(coil STATIC ${coil_SRC})
target_link_libraries(coil PUBLIC Boost::program_options)
target_include_directories(coil PUBLIC ${PROJECT_SOURCE_DIR}/src/coil/)
add_definitions(-DDYNAMO_visualizer)
# Make dynamo depend on the coil library
target_link_libraries(dynamo PUBLIC coil)
# Add coilvol as a dependency
add_executable(coilvol ${CMAKE_CURRENT_SOURCE_DIR}/src/coil/programs/coilvol.cpp)
target_link_libraries(coilvol PUBLIC coil Boost::program_options Boost::filesystem Boost::system)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/coilvol DESTINATION bin)
endif()
function(dynamo_exe name) #Registers a dynamo executable given the source file name
add_executable(${name} ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/${name}.cpp)
target_link_libraries(${name} dynamo)
install(PROGRAMS $<TARGET_FILE:${name}> DESTINATION bin)
endfunction(dynamo_exe)
dynamo_exe(dynarun)
dynamo_exe(dynamod)
dynamo_exe(dynahist_rw)
dynamo_exe(dynapotential)
#dynamo_exe(dynacollide)
if(VISUALIZER_SUPPORT)
#we do dynavis by hand, as its just dynarun with some changes
add_executable(dynavis ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynarun.cpp)
set_target_properties(dynavis PROPERTIES COMPILE_DEFINITIONS "DYNAMO_loadvisualiser")
target_link_libraries(dynavis dynamo)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dynavis DESTINATION bin)
endif()
# scripts
if(Python3_FOUND)
if(Python3_NumPy_FOUND)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynatransport DESTINATION bin)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynarmsd DESTINATION bin)
message(STATUS "Python NumPy found, installing dynatransport, dynamaprmsd, and dynarmsd")
else()
message(WARNING "Python NumPy library not found, disabling install of dynatransport, dynamaprmsd, and dynarmsd")
endif()
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynamo2xyz DESTINATION bin)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynamaprmsd DESTINATION bin)
else()
message(WARNING "Python 3 not found, cannot install all DynamO tools.")
endif()
# unit tests
function(dynamo_test name) #Registers a unit test of DynamO
add_executable(dynamo_${name}_exe ${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/tests/${name}.cpp)
target_link_libraries(dynamo_${name}_exe dynamo)
add_test(dynamo_${name} dynamo_${name}_exe)
endfunction(dynamo_test)
dynamo_test(hardsphere_test)
dynamo_test(shearing_test)
dynamo_test(binaryhardsphere_test)
dynamo_test(squarewell_test)
dynamo_test(2dstepped_potential_test)
dynamo_test(infmass_spheres_test)
dynamo_test(lines_test)
dynamo_test(static_spheres_test)
dynamo_test(gravityplate_test)
dynamo_test(polymer_test)
dynamo_test(swingspheres_test)
dynamo_test(squarewellwall_test)
dynamo_test(thermalisedwalls_test)
dynamo_test(event_sorters_test)
if(Python3_Interpreter_FOUND)
add_test(NAME dynamo_replica_exchange
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/tests/replex_test.py
--dynarun=$<TARGET_FILE:dynarun>
--dynamod=$<TARGET_FILE:dynamod>
--dynahist_rw=$<TARGET_FILE:dynahist_rw>)
add_test(NAME dynamo_multicanonical_cmap
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/tests/multicanonical_cmap_test.py
--dynarun=$<TARGET_FILE:dynarun>
--dynamod=$<TARGET_FILE:dynamod>
--dynahist_rw=$<TARGET_FILE:dynahist_rw>)
if(Python3_NumPy_FOUND)
add_test(NAME dynamo_dynatransport
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/tests/dynatransport_test.py
--dynarun=$<TARGET_FILE:dynarun>
--dynamod=$<TARGET_FILE:dynamod>
--dynahist_rw=$<TARGET_FILE:dynahist_rw>
--dynatransport=${CMAKE_CURRENT_SOURCE_DIR}/src/dynamo/programs/dynatransport
--python=${Python3_EXECUTABLE}
)
endif()
endif()