-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
170 lines (143 loc) · 4.64 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
cmake_minimum_required (VERSION 3.9)
project (camp
LANGUAGES CXX C
VERSION 0.4.0)
set(camp_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(camp_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(camp_VERSION_PATCH ${PROJECT_VERSION_PATCH})
# Default to C++11 if not set so GTest/GMock can build
if (NOT BLT_CXX_STD)
set(BLT_CXX_STD "c++14" CACHE STRING "")
else()
set(_unsupported_cxx "c++98" "c++11")
if (BLT_CXX_STD IN_LIST _unsupported_cxx)
message(FATAL_ERROR "CAMP and the RAJA framework no longer support c++11, select a c++ standard of 14 or higher")
endif()
endif()
include(cmake/load_blt.cmake)
cmake_dependent_option(CAMP_ENABLE_TESTS "Build tests" On "ENABLE_TESTS" Off)
# if ENABLE_TESTS is defined by a parent project, and
# CAMP_ENABLE_TESTS has not been set to OFF set the
# value of CAMP_ENABLE_TESTS to the value of ENABLE_TESTS.
if (CAMP_ENABLE_TESTS AND DEFINED ENABLE_TESTS)
set(CAMP_ENABLE_TESTS ${ENABLE_TESTS})
endif()
if (WIN32)
# use git-bash for windows, wsl is not populated on azure
set(BASH "C:/Program Files/Git/bin/bash.exe")
else()
set(BASH "bash")
endif()
# generate list of headers at configure time, no this is not perfect
# note that this *DOES* work on windows if bash is installed, which
# it is on azure
execute_process(COMMAND ${BASH} ${PROJECT_SOURCE_DIR}/scripts/gen-header-list.sh
OUTPUT_FILE ${PROJECT_BINARY_DIR}/camp_headers.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
include(${PROJECT_BINARY_DIR}/camp_headers.cmake)
list (APPEND camp_headers ${PROJECT_BINARY_DIR}/include/camp/config.hpp)
# backends
set (camp_depends)
set (camp_backends openmp cuda hip sycl)
# NOTE: camp itself doesn't require a hip or cuda compiler,
# but some of its features are activated by having a device compiler
set (camp_runtime_backends cuda hip)
foreach (backend ${camp_backends})
string(TOUPPER "${backend}" suffix)
if ("${ENABLE_${suffix}}")
set ("CAMP_ENABLE_${suffix}" On)
endif()
if (${CAMP_ENABLE_${suffix}})
if (backend IN_LIST camp_runtime_backends)
set (backend ${backend}_runtime)
endif()
if (TARGET blt::${backend})
set (backend blt::${backend})
endif()
list (APPEND camp_depends ${backend})
endif()
endforeach()
if (CAMP_ENABLE_TARGET_OPENMP)
if (NOT CAMP_ENABLE_OPENMP)
message(FATAL_ERROR "OpenMP must be enabled if TARGET_OPENMP is enabled")
endif ()
endif ()
if (ENABLE_CUDA)
if("${CUDA_VERSION_STRING}" VERSION_LESS "10.1")
message(FATAL_ERROR "Trying to use CUDA version ${CUDA_VERSION_STRING}. CAMP requires CUDA version 10.1 or newer.")
endif()
if(ENABLE_NV_TOOLS_EXT)
set(camp_depends
${camp_depends}
nvtoolsext)
endif ()
endif ()
if (ENABLE_HIP)
if("${hip_VERSION}" VERSION_LESS "3.5")
message(FATAL_ERROR "Trying to use HIP/ROCm version ${hip_VERSION}. CAMP requires HIP/ROCm version 3.5 or newer. ")
endif()
endif ()
# end backends
# Configure the config header file to allow config time options
configure_file(${PROJECT_SOURCE_DIR}/include/camp/config.in.hpp
${PROJECT_BINARY_DIR}/include/camp/config.hpp)
blt_add_library (
NAME camp
HEADERS ${camp_headers}
SOURCES ./src/errors.cpp
DEPENDS_ON ${camp_depends}
)
if (COMPILER_FAMILY_IS_MSVC)
if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(camp PUBLIC WIN_STATIC_BUILD)
else (NOT BUILD_SHARED_LIBS)
target_compile_definitions(camp PRIVATE CAMP_DLL_EXPORTS)
endif (NOT BUILD_SHARED_LIBS)
endif ()
target_include_directories (camp PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties (camp PROPERTIES
INTERFACE_LIB_VERSION ${PROJECT_VERSION}
INTERFACE_COMPILE_FEATURES cxx_std_14)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/campConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(TARGETS
camp
EXPORT campTargets
RUNTIME DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/campConfig.cmake.in"
"${PROJECT_BINARY_DIR}/campConfig.cmake"
INSTALL_DESTINATION
lib/cmake/camp
)
install(EXPORT campTargets
DESTINATION lib/cmake/camp)
install(FILES
"${PROJECT_BINARY_DIR}/campConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/campConfig.cmake"
DESTINATION
lib/cmake/camp)
install(DIRECTORY
${PROJECT_SOURCE_DIR}/include/
DESTINATION
include)
install(FILES
"${PROJECT_BINARY_DIR}/include/camp/config.hpp"
DESTINATION
include/camp)
if(CAMP_ENABLE_TESTS)
enable_testing()
add_subdirectory(test)
endif()