forked from petalo-project/nest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
178 lines (143 loc) · 5.55 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
# Set minimum CMake version required and prevent building in source
cmake_minimum_required(VERSION 3.8...3.16 FATAL_ERROR)
############### Get version from git #####################
execute_process(COMMAND git describe --tag
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
function(get_versions versionString version)
if ("${versionString}" STREQUAL "")
set(version "0.0.0" PARENT_SCOPE)
return()
endif ()
string(REGEX REPLACE "v([0-9]*)([.][0-9]*[.][0-9]*-?.*)$" "\\1" numbers ${versionString})
set(major ${numbers})
string(REGEX REPLACE "v([0-9]*[.])([0-9]*)([.][0-9]*-?.*)$" "\\2" numbers ${versionString})
set(minor ${numbers})
string(REGEX REPLACE "v([0-9]*[.][0-9]*[.])([0-9]*)(-?.*)$" "\\2" numbers ${versionString})
set(patch ${numbers})
set(version "${major}.${minor}.${patch}" PARENT_SCOPE)
endfunction()
get_versions("${PROJECT_GIT_VERSION}" version)
set(PROJECT_GIT_VERSION ${version})
############### project name and version #####################
project(NEST VERSION ${PROJECT_GIT_VERSION} LANGUAGES CXX)
option(G4 "Build integration with Geant4" OFF)
option(BUILD_ROOT "Build ROOT tools" OFF)
option(BUILD_EXAMPLES "Build NEST examples" ON)
option(BUILD_GARFIELD "Build integration with Garfield++" ON)
# enable position independent code so shared libraries can link against
# the static version of NEST::Core
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(cmake/gcem.cmake)
set(NEST_CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/NEST.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/RandomGen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestSpectra.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VDetector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GammaHandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ValidityTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LArNEST.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LArDetector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestLArSpectra.cpp
)
set(NEST_CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/NEST.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/RandomGen.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/TestSpectra.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/Detectors/VDetector.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/Detectors/LArDetector.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/GammaHandler.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/ValidityTests.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/LArNEST.hh
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/TestLArSpectra.hh
)
add_library(NESTCore ${NEST_CORE_SOURCES} ${NEST_CORE_HEADERS})
add_library(NEST::Core ALIAS NESTCore)
target_link_libraries(NESTCore PUBLIC gcem)
list(APPEND NEST_TARGETS "NESTCore")
list(APPEND NEST_LIBRARY_TARGETS "NEST::Core")
target_include_directories(
NESTCore PUBLIC
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/NEST>
$<INSTALL_INTERFACE:include/Detectors>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/NEST>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Detectors>
)
target_compile_features(NESTCore PUBLIC cxx_std_17)
add_executable(execNEST
${CMAKE_CURRENT_SOURCE_DIR}/src/execNEST.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/NEST/execNEST.hh
)
target_link_libraries(execNEST PUBLIC NEST::Core)
list(APPEND NEST_TARGETS "execNEST")
## scripts
configure_file(examples/loopNEST.in loopNEST)
configure_file(examples/220RnCalib.in 220RnCalib)
## Optional targets
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_GARFIELD)
add_subdirectory(GarfieldppIntegration)
endif()
if(G4)
add_subdirectory(G4integration)
list(APPEND NEST_TARGETS "NESTG4")
set(NEST_LIBRARY_TARGETS "${NEST_LIBRARY_TARGETS} NEST::NESTG4")
endif()
# installation, Targets.cmake and Config.cmake
message(STATUS "NEST_LIBRARY_TARGETS: ${NEST_LIBRARY_TARGETS}")
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/NEST)
write_basic_package_version_file(
NESTConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY ExactVersion
)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/NESTConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/NESTConfig.cmake
INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/NESTConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/NESTConfigVersion.cmake
DESTINATION ${INSTALL_CONFIGDIR}
)
message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_LIBDIR}")
message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_BINDIR}")
message(STATUS "CMAKE_INSTALL_LIBDIR: ${CMAKE_INSTALL_INCLUDEDIR}")
install(
TARGETS ${NEST_TARGETS}
EXPORT NEST-Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
EXPORT NEST-Targets
FILE NESTTargets.cmake
NAMESPACE NEST::
DESTINATION ${INSTALL_CONFIGDIR}
)
## install scripts
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/loopNEST
${CMAKE_CURRENT_BINARY_DIR}/220RnCalib
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
##############################################
export(
EXPORT NEST-Targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/NESTTargets.cmake
NAMESPACE NEST::
)
# Register package in user's package registry
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE NEST)