-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
123 lines (100 loc) · 4.16 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
cmake_minimum_required(VERSION 3.9...3.12)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
cmake_policy(VERSION 3.12)
endif()
project(sd1d LANGUAGES CXX)
# Extra CMake scripts in cmake/ subdirectory
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Update submodules
# Adapted from https://cliutils.gitlab.io/modern-cmake/chapters/projects/submodule.html
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} -c submodule.recurse=false 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 failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
# Get the Git revision
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC SD1D_REVISION)
if(SD1D_REVISION STREQUAL "GITDIR-NOTFOUND")
set(SD1D_REVISION "Unknown")
endif()
message(STATUS "Git revision: ${SD1D_REVISION}")
# BOUT++ is a dependency
add_subdirectory(external/BOUT-dev)
set(SD1D_SOURCES
sd1d.cxx
div_ops.cxx
loadmetric.cxx
radiation.cxx
atomicpp/ImpuritySpecies.cxx
atomicpp/Prad.cxx
atomicpp/RateCoefficient.cxx
atomicpp/sharedFunctions.cxx
div_ops.hxx
loadmetric.hxx
radiation.hxx
atomicpp/ImpuritySpecies.hxx
atomicpp/json.hxx
atomicpp/Prad.hxx
atomicpp/RateCoefficient.hxx
atomicpp/sharedFunctions.hxx
)
# The main executable target
add_executable(sd1d
${SD1D_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/revision.hxx)
target_link_libraries(sd1d PRIVATE bout++::bout++)
target_include_directories(sd1d PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
# Build the file containing just the commit hash
# This will be rebuilt on every commit!
configure_file(
"${PROJECT_SOURCE_DIR}/revision.hxx.in"
"${PROJECT_BINARY_DIR}/revision.hxx")
# Once built, copy the data and test directories
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/case-01 $<TARGET_FILE_DIR:${PROJECT_NAME}>/case-01)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/case-02 $<TARGET_FILE_DIR:${PROJECT_NAME}>/case-02)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/case-03 $<TARGET_FILE_DIR:${PROJECT_NAME}>/case-03)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/case-04 $<TARGET_FILE_DIR:${PROJECT_NAME}>/case-04)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/case-05 $<TARGET_FILE_DIR:${PROJECT_NAME}>/case-05)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/json_database $<TARGET_FILE_DIR:${PROJECT_NAME}>/json_database)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/impurity_user_input.json $<TARGET_FILE_DIR:${PROJECT_NAME}>/impurity_user_input.json)
# Tests
option(SD1D_TESTS "Build the tests" ON)
if(SD1D_TESTS)
enable_testing()
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/tests $<TARGET_FILE_DIR:${PROJECT_NAME}>/tests)
# Integrated tests
function(sd1d_add_integrated_test TESTNAME)
add_test(NAME ${TESTNAME}
WORKING_DIRECTORY tests/${TESTNAME}
COMMAND runtest)
endfunction()
sd1d_add_integrated_test(case-01)
endif()