-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
370 lines (305 loc) · 11.6 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
#================================================================================================
#Project details
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
#KS: Store some handy cmake functions
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/NuOscillatorUtils.cmake)
# By default GPU is off
DefineEnabledRequiredSwitch(UseGPU 0)
set(NUOSCILLATOR_VERSION 1.1.0)
if(${UseGPU} EQUAL 0)
project(NUOSCILLATOR VERSION ${NUOSCILLATOR_VERSION} LANGUAGES CXX)
else()
project(NUOSCILLATOR VERSION ${NUOSCILLATOR_VERSION} LANGUAGES CXX CUDA)
endif()
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
#Changes default install path to be a subdirectory of the build dir.
#Can set build dir at configure time with -DCMAKE_INSTALL_PREFIX=/install/path
if(CMAKE_INSTALL_PREFIX STREQUAL "" OR CMAKE_INSTALL_PREFIX STREQUAL
"/usr/local")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}")
elseif(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/${CMAKE_SYSTEM_NAME}")
endif()
#================================================================================================
#Custom variable sanitisation
add_library(NuOscillatorCompilerOptions INTERFACE)
# download CPM.cmake
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
DefineEnabledRequiredSwitch(UseMultithreading 1)
DefineEnabledRequiredSwitch(UseDoubles 1)
DefineEnabledRequiredSwitch(UseCUDAProb3 0)
DefineEnabledRequiredSwitch(UseCUDAProb3Linear 0)
DefineEnabledRequiredSwitch(UseProb3ppLinear 0)
DefineEnabledRequiredSwitch(UseProbGPULinear 0)
DefineEnabledRequiredSwitch(UseNuFASTLinear 0)
DefineEnabledRequiredSwitch(UseOscProb 0)
# KS: NuFastLinear by default
if(UseCUDAProb3 EQUAL 0 AND
UseCUDAProb3Linear EQUAL 0 AND
UseProb3ppLinear EQUAL 0 AND
UseProbGPULinear EQUAL 0 AND
UseNuFASTLinear EQUAL 0 AND
UseOscProb EQUAL 0)
set(UseNuFASTLinear 1)
endif()
LIST(APPEND ALL_Engines
CUDAProb3
CUDAProb3Linear
Prob3ppLinear
ProbGPULinear
NuFASTLinear
OscProb
)
cmessage(STATUS "NuOscillator Features: ")
foreach(f ${ALL_Engines})
cmessage(STATUS " ${f}: ${Use${f}}")
endforeach()
cmessage(STATUS "Required variables being used:")
if(${UseGPU} EQUAL 1)
cmessage(STATUS "\tUsing GPU")
else()
cmessage(STATUS "\tNot using GPU")
if(${UseProbGPULinear} EQUAL 1)
cmessage(FATAL_ERROR "ProbGPULinear calculator can only be used when using GPU")
endif()
endif()
if(${UseMultithreading} EQUAL 1)
cmessage(STATUS "\tUsing Multithreading with nThreads=$ENV{OMP_NUM_THREADS}")
else()
cmessage(STATUS "\tNot using Multithreading")
endif()
if(${UseDoubles} EQUAL 1)
cmessage(STATUS "\tUsing FLOAT_T=double")
else()
cmessage(STATUS "\tUsing FLOAT_T=float")
endif()
if(${UseCUDAProb3} EQUAL 1 AND ${UseCUDAProb3Linear} EQUAL 1)
cmessage(FATAL_ERROR "CUDAProb3 and CUDAProb3Linear and not able to be built at the same time")
endif()
if(${UseMultithreading} EQUAL 1)
target_compile_options(NuOscillatorCompilerOptions INTERFACE -fopenmp)
target_link_libraries(NuOscillatorCompilerOptions INTERFACE gomp)
endif()
if(NOT DEFINED NuOscillator_Compiler_Flags)
set(NuOscillator_Compiler_Flags "")
endif()
separate_arguments(NuOscillator_Compiler_Flags)
cmessage(STATUS "Set compiler options: ${NuOscillator_Compiler_Flags}")
add_compile_options(${NuOscillator_Compiler_Flags})
if(${UseGPU} EQUAL 1)
#KS: Allow user to define CMAKE_CUDA_ARCHITECTURES
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
#KS: See this for more info https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html
if( ${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.23 )
set(CMAKE_CUDA_ARCHITECTURES all )
#KS: Consider using native, requires cmake 3.24... will be terrible for containers but should results in more optimised code
#set(CMAKE_CUDA_ARCHITECTURES native )
else()
#KS: Apparently with newer cmake and GPU
set(CMAKE_CUDA_ARCHITECTURES 60 61 70 75 80 86)
endif()
#KS: Bit hacky but to properly pass cuda flags we need
string(REPLACE ";" " " CMAKE_CUDA_ARCHITECTURES_STRING "${CMAKE_CUDA_ARCHITECTURES}")
else()
#KS this may look hacky however CPM isn't build for passing stuff like this. If CMAKE_CUDA_ARCHITECTURES is passed CPM it will be string not list. Thus we convert it to list
set(CMAKE_CUDA_ARCHITECTURES_STRING ${CMAKE_CUDA_ARCHITECTURES})
string(REPLACE " " ";" CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
endif()
cmessage(STATUS "Set CUDA ARCHITECTURES options: ${CMAKE_CUDA_ARCHITECTURES_STRING}")
endif()
#================================================================================================
#Setup Deps
set(YAML_CPP_VERSION 0.8.0)
CPMAddPackage(
NAME yaml-cpp
VERSION ${YAML_CPP_VERSION}
GITHUB_REPOSITORY "jbeder/yaml-cpp"
GIT_TAG "${YAML_CPP_VERSION}"
OPTIONS
"YAML_CPP_INSTALL ON"
"YAML_CPP_BUILD_TESTS OFF"
"YAML_CPP_BUILD_CONTRIB OFF"
"YAML_BUILD_SHARED_LIBS ON"
)
if(NOT TARGET yaml-cpp::yaml-cpp)
cmessage(FATAL_ERROR "NuOscillator Expected dependency target: yaml-cpp::yaml-cpp")
endif()
find_package(ROOT 6.18 REQUIRED)
if(${UseCUDAProb3} EQUAL 1)
CPMFindPackage(
NAME CUDAProb3
GITHUB_REPOSITORY "dbarrow257/CUDAProb3"
GIT_TAG "develop"
DOWNLOAD_ONLY
)
if(NOT CUDAProb3_ADDED)
cmessage(FATAL_ERROR "Could not download CUDAProb3")
endif()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseCUDAProb3=1)
endif()
if(${UseCUDAProb3Linear} EQUAL 1)
if(${UseGPU} EQUAL 1)
CPMFindPackage(
NAME CUDAProb3
GITHUB_REPOSITORY "mach3-software/CUDAProb3"
GIT_TAG "main"
OPTIONS
"GPU_ON ON"
"CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES_STRING}"
)
else()
CPMFindPackage(
NAME CUDAProb3
GITHUB_REPOSITORY "mach3-software/CUDAProb3"
GIT_TAG "main"
OPTIONS
"CPU_ONLY ON"
"GPU_ON OFF"
)
# KS: Terrible hack because CUDAProb3Beam is mess :(
install(TARGETS CUDAProb3Beam
EXPORT NuOscillator-targets
LIBRARY DESTINATION lib/
PUBLIC_HEADER DESTINATION include/CUDAProb3Beam)
endif()
if(NOT TARGET CUDAProb3Beam OR NOT TARGET CUDAProb3Atmos)
cmessage(FATAL_ERROR "Could not find CUDAProb3Linear")
endif()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseCUDAProb3Linear=1)
endif()
if(${UseGPU} EQUAL 1)
if(${UseProbGPULinear} EQUAL 1)
CPMFindPackage(
NAME ProbGPU
GIT_TAG main
GITHUB_REPOSITORY dbarrow257/ProbGPU
OPTIONS
"CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES_STRING}"
)
if(NOT TARGET ProbGPU)
cmessage(FATAL_ERROR "Could not find ProbGPU")
endif()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseProbGPULinear=1)
endif()
endif()
if(${UseProb3ppLinear} EQUAL 1)
CPMAddPackage(
NAME Prob3plusplus
VERSION 3.10.4
GITHUB_REPOSITORY rogerwendell/Prob3plusplus
GIT_TAG main
)
if(NOT TARGET Prob3plusplus)
cmessage(FATAL_ERROR "Could not find Prob3plusplus")
endif()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseProb3ppLinear=1)
install(TARGETS Prob3plusplus
EXPORT NuOscillator-targets
LIBRARY DESTINATION lib/)
endif()
if(${UseNuFASTLinear} EQUAL 1)
CPMAddPackage(
NAME NuFAST
GIT_TAG v1.0
GITHUB_REPOSITORY PeterDenton/NuFast
DOWNLOAD_ONLY
)
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseNuFASTLinear=1)
endif()
if(${UseOscProb} EQUAL 1)
CPMAddPackage(
NAME OscProb
GITHUB_REPOSITORY joaoabcoelho/OscProb
GIT_TAG master
)
CPMAddPackage(
NAME Eigen
VERSION 3.4.0
URL https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
DOWNLOAD_ONLY YES
)
if(Eigen_ADDED)
add_library(Eigen INTERFACE IMPORTED)
target_include_directories(Eigen INTERFACE ${Eigen_SOURCE_DIR})
endif()
execute_process(COMMAND make WORKING_DIRECTORY ${OscProb_SOURCE_DIR})
add_library(OSCPROB INTERFACE IMPORTED)
target_include_directories(OSCPROB INTERFACE ${OscProb_SOURCE_DIR})
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseOscProb=1)
set(OSCPROB_LIB_DIR ${OscProb_SOURCE_DIR}/lib)
endif()
if(${UseGPU} EQUAL 1)
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseGPU=1)
else()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseGPU=0)
endif()
if(${UseMultithreading} EQUAL 1)
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseMultithreading=1)
else()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseMultithreading=0)
endif()
if(${UseDoubles} EQUAL 1)
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseDoubles=1)
else()
target_compile_definitions(NuOscillatorCompilerOptions INTERFACE UseDoubles=0)
endif()
#================================================================================================
#Subdirectories to add
add_subdirectory(OscProbCalcer)
add_subdirectory(Oscillator)
add_subdirectory(Apps)
#================================================================================================
set(LIBDEST ${CMAKE_INSTALL_PREFIX}/lib)
configure_file(cmake/Templates/setup.NuOscillator.sh.in "${PROJECT_BINARY_DIR}/setup.NuOscillator.sh" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/setup.NuOscillator.sh" DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(DIRECTORY Configs DESTINATION ${CMAKE_INSTALL_PREFIX}/)
install(DIRECTORY Inputs DESTINATION ${CMAKE_INSTALL_PREFIX}/)
install(DIRECTORY Constants DESTINATION ${CMAKE_INSTALL_PREFIX}/)
set_target_properties(NuOscillatorCompilerOptions PROPERTIES EXPORT_NAME CompilerOptions)
install(TARGETS NuOscillatorCompilerOptions
EXPORT NuOscillator-targets
LIBRARY DESTINATION lib/)
#================================================================================================
#This is to export the target properties of NuOscillator
#Anything that links to "NuOscillator" will get all of these target properties
add_library(NuOscillator INTERFACE)
target_link_libraries(NuOscillator INTERFACE Oscillator OscProbCalcer NuOscillatorCompilerOptions)
set_target_properties(NuOscillator PROPERTIES EXPORT_NAME All)
install(TARGETS NuOscillator
EXPORT NuOscillator-targets
LIBRARY DESTINATION lib/)
install(EXPORT NuOscillator-targets
FILE NuOscillatorTargets.cmake
NAMESPACE NuOscillator::
DESTINATION ${CMAKE_INSTALL_PREFIX}/
)
install(DIRECTORY
Configs
DESTINATION ${CMAKE_BINARY_DIR}/NuOscillatorConfigs)
add_library(NuOscillator::All ALIAS NuOscillator)
############################ Install ####################################
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/NuOscillatorConfig.cmake.in ${CMAKE_BINARY_DIR}/NuOscillatorConfig.cmake
INSTALL_DESTINATION
/this/is/ignored/for/some/reason/thanks/kitware
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/NuOscillatorConfigVersion.cmake
VERSION ${NUOSCILLATOR_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES
${CMAKE_BINARY_DIR}/NuOscillatorConfig.cmake
${CMAKE_BINARY_DIR}/NuOscillatorConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/NuOscillator)
include(nuoscillator-config)