-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
49 lines (38 loc) · 2.59 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
cmake_minimum_required(VERSION 3.18)
cmake_policy(VERSION 3.18)
project(storm
LANGUAGES CXX)
find_package(bout++
REQUIRED)
add_executable(storm
storm3d/storm.cxx storm3d/boundaries.cxx storm3d/initialise.cxx storm3d/monitors.cxx storm3d/operators.cxx storm3d/utilities.cxx shared/BoutFastOutput/fast_output.cxx shared/BoutEquation/equation.cxx storm3d/neutral-rates.cxx storm3d/D-vpar.cxx storm3d/neutral-model.cxx)
target_link_libraries(storm
PRIVATE bout++::bout++)
# Write git hash and diff to ${CMAKE_CURRENT_BINARY_DIR}/include/storm_version.hxx at every build
# Original version inspired by https://stackoverflow.com/a/39960540.
# Modified because original version did not always regenerate storm_version.hxx. Problem
# seems to be fixed by putting the COMMAND directly into add_custom_target() instead of
# using add_custom_command(), and explicitly adding 'GitVersion' as a dependency of
# 'storm', rather than having
# '${CMAKE_CURRENT_BINARY_DIR}/include/storm_version.hxx' as a dependency. Modifications
# inspired by https://stackoverflow.com/a/51881170/13577592.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
target_include_directories(storm PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
# Remove storm_version.hxx from the source directory (if it exists). It may have been
# generated by a configure/make in-source build, but should not be used here. There does
# not seem to be a way to prevent the source-directory version from taking precedence
# except deleting it (changing `#include "storm_version.hxx"` to `#include
# <storm_version.hxx>` should work, but would break the configure/make build).
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/storm3d/storm_version.hxx)
add_custom_target(GitVersion
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/save_git_version.py ${PROJECT_BINARY_DIR}/include ${PROJECT_BINARY_DIR} > /dev/null
COMMENT "Generating include/storm_version.hxx")
add_dependencies(storm GitVersion)
# Copy useful scripts, etc. into build directory
add_custom_command(TARGET storm POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/storm3d/create_bg_1d $<TARGET_FILE_DIR:storm>)
# Copy tests into build directory so that we can run them locally
# See https://newbedev.com/how-to-copy-contents-of-a-directory-into-build-directory-after-make-with-cmake
add_custom_command(TARGET storm POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests3d $<TARGET_FILE_DIR:storm>/tests3d)