forked from SimulationEverywhere/cadmium_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
75 lines (70 loc) · 3.27 KB
/
CMakeLists.txt
File metadata and controls
75 lines (70 loc) · 3.27 KB
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
cmake_minimum_required(VERSION 3.1)
project(cadmium)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
add_library(cadmium INTERFACE)
target_include_directories(cadmium INTERFACE include/ json/include)
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/main_*.cpp)
foreach(exampleSrc ${Examples})
get_filename_component(exampleName ${exampleSrc} NAME_WE)
get_filename_component(dirname ${exampleSrc} DIRECTORY)
file(GLOB directorySrc CONFIGURE_DEPENDS "${dirname}/src/*.cpp")
add_executable(${exampleName} ${exampleSrc} ${directorySrc})
target_include_directories(${exampleName} PUBLIC "${dirname}/include")
target_link_libraries(${exampleName} cadmium)
endforeach(exampleSrc)
if(APPLE)
# Apple Clang does not pack OpenMP. We must install it via HomeBrew and link it manually
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
endif()
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
if (APPLE)
# HomeBrew leaves a symlink to the installed version of OpenMP in these directories
include_directories("/usr/local/opt/libomp/include")
link_directories("/usr/local/opt/libomp/lib")
endif()
FILE(GLOB Examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} example/*/parallel_main_*.cpp)
foreach(exampleSrc ${Examples})
get_filename_component(exampleName ${exampleSrc} NAME_WE)
get_filename_component(dirname ${exampleSrc} DIRECTORY)
file(GLOB directorySrc CONFIGURE_DEPENDS "${dirname}/src/*.cpp")
add_executable(${exampleName} ${exampleSrc} ${directorySrc})
target_include_directories(${exampleName} PUBLIC "${dirname}/include")
target_link_libraries(${exampleName} PUBLIC cadmium OpenMP::OpenMP_CXX)
endforeach(exampleSrc)
else()
message(STATUS "OpenMP not found. You won't be able to use parallel simulation.")
endif()
find_package(Boost COMPONENTS system filesystem unit_test_framework)
if(Boost_FOUND)
add_definitions(-DBOOST_TEST_DYN_LINK)
enable_testing()
FILE(GLOB Tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test/*/test_*.cpp)
foreach(testSrc ${Tests})
get_filename_component(testName ${testSrc} NAME_WE)
string(REGEX MATCH "[a-z]+$" useCase ${testName})
file(GLOB directorySrc CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/example/${useCase}/src/*.cpp")
add_executable(${testName} ${testSrc} ${directorySrc})
target_include_directories(${testName} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/example/${useCase}/include")
target_link_libraries(${testName} cadmium ${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
add_test(NAME ${testName} COMMAND ${testName})
endforeach(testSrc)
else()
message(STATUS "Boost not found. You won't be able to run nor develop tests for Cadmium.")
endif()