-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
261 lines (198 loc) · 8.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
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
#------------------------------------------------------------------------------#
# Set the minimum CMake version
#------------------------------------------------------------------------------#
cmake_minimum_required(VERSION 3.2)
cmake_policy(SET CMP0074 NEW)
include(ExternalProject)
#------------------------------------------------------------------------------#
# Setup the project
#------------------------------------------------------------------------------#
project(Contra VERSION 0.1.0)
# We need C++ 14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_EXTENSIONS off)
# cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
include(BuildType)
# project variables
set( CONTRA_TEST_TOLERANCE 1e-14 CACHE INTERNAL "")
set( CONTRA_TOOL_DIR "${PROJECT_SOURCE_DIR}/tools" CACHE INTERNAL "")
# options
option(BUILD_SHARED_LIBS "Build shared libraries." ON)
set(SUPPORTED_BACKENDS "serial")
set(THREADS_PREFER_PTHREAD_FLAG)
#------------------------------------------------------------------------------#
# configure targets
#------------------------------------------------------------------------------#
add_executable( contra )
install( TARGETS contra
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin)
#------------------------------------------------------------------------------#
# LLVM
#------------------------------------------------------------------------------#
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
target_include_directories(contra PUBLIC ${LLVM_INCLUDE_DIRS})
target_compile_definitions(contra PUBLIC ${LLVM_DEFINITIONS})
# Find the libraries that correspond to the LLVM components
# that we wish to use
if (BUILD_SHARED_LIBS)
llvm_config(contra USE_SHARED all)
else()
llvm_config(contra all)
endif()
#------------------------------------------------------------------------------#
# MPI
#------------------------------------------------------------------------------#
find_package(MPI QUIET)
if (MPI_FOUND)
if (MPI_VERSION)
MESSAGE(STATUS "Found MPI: ${MPI_VERSION}")
endif()
MESSAGE(STATUS "MPI Include Dirs: ${MPI_C_INCLUDE_DIRS}")
MESSAGE(STATUS "MPI Libraries: ${MPI_C_LIBRARIES}")
target_link_libraries(contra PUBLIC MPI::MPI_C)
list(APPEND SUPPORTED_BACKENDS "mpi")
endif()
#------------------------------------------------------------------------------#
# Legion
#------------------------------------------------------------------------------#
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(THREADS_PREFER_PTHREAD_FLAG)
find_package(Legion QUIET)
if (Legion_FOUND)
MESSAGE(STATUS "Legion includes: ${Legion_INCLUDE_DIRS}")
MESSAGE(STATUS "Legion libraries: ${Legion_LIBRARIES}")
# need pthreads
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# need zlib
find_package(ZLIB REQUIRED)
# add other necessary libaries for legion
list(APPEND Legion_LIBRARIES Threads::Threads ${ZLIB_LIBRARIES} ${CMAKE_DL_LIBS})
if(UNIX AND NOT APPLE)
list(APPEND Legion_LIBRARIES rt)
endif()
target_include_directories(contra PUBLIC ${Legion_INCLUDE_DIRS})
target_link_libraries(contra PUBLIC ${Legion_LIBRARIES})
list(APPEND SUPPORTED_BACKENDS "legion")
endif()
#------------------------------------------------------------------------------#
# Threads
#------------------------------------------------------------------------------#
find_package(Threads QUIET)
if (Threads_FOUND)
target_link_libraries(contra PUBLIC Threads::Threads)
list(APPEND SUPPORTED_BACKENDS "threads")
endif()
#------------------------------------------------------------------------------#
# Cuda toolkit
#------------------------------------------------------------------------------#
IF (CMAKE_VERSION VERSION_GREATER_EQUAL "3.17.0")
find_package(CUDAToolkit QUIET)
set(CUDA_FOUND ${CUDAToolkit_FOUND})
else()
find_package(CUDA QUIET)
endif()
if (CUDA_FOUND)
enable_language(CUDA)
add_library( contra_cuda_rt STATIC )
target_compile_options(contra_cuda_rt PRIVATE -rdc=true )
target_include_directories(contra_cuda_rt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(contra_cuda_rt PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
add_library( rtcuda )
target_include_directories(rtcuda PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(rtcuda PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
target_link_libraries(contra PRIVATE rtcuda)
install( TARGETS contra_cuda_rt rtcuda
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
if (TARGET CUDA::cudart)
target_link_libraries(contra PUBLIC CUDA::cudart CUDA::cuda_driver)
else()
target_link_libraries(contra PUBLIC ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY})
target_include_directories(contra PUBLIC ${CUDA_INCLUDE_DIRS})
endif()
list(APPEND SUPPORTED_BACKENDS "cuda")
endif()
#------------------------------------------------------------------------------#
# Hip
#------------------------------------------------------------------------------#
set(CONTRA_ROCM_DEFAULT_TARGET_CPU CACHE STRING "Default target cpu")
find_package(HIP QUIET)
if (HIP_FOUND)
include(rocm_helpers)
target_link_libraries(contra PUBLIC hip::host)
add_custom_target(contra_rocm_devlibs)
add_dependencies(contra contra_rocm_devlibs)
list(APPEND SUPPORTED_BACKENDS "rocm")
MESSAGE(STATUS "Available AMDGPU Target CPUs: ${AMDGPU_TARGETS}")
if (NOT CONTRA_ROCM_DEFAULT_TARGET_CPU)
list(GET AMDGPU_TARGETS 0 ROCM_DEFAULT_TARGET_CPU)
MESSAGE(STATUS "CONTRA_ROCM_DEFAULT_TARGET_CPU not set, using: "
"${ROCM_DEFAULT_TARGET_CPU}")
else()
set(ROCM_DEFAULT_TARGET_CPU ${CONTRA_ROCM_DEFAULT_TARGET_CPU})
endif()
find_rocm_program(
ROCM_LD_LLD_EXE
NAMES ld.lld)
find_rocm_program(ROCM_CLANG_EXE
NAMES clang)
find_package(AMDDeviceLibs REQUIRED CONFIG)
MESSAGE(STATUS "Found device libs: ${AMD_DEVICE_LIBS_TARGETS}")
endif()
#------------------------------------------------------------------------------#
# build library
#------------------------------------------------------------------------------#
MESSAGE(STATUS "Supported backends: ${SUPPORTED_BACKENDS}")
target_include_directories(contra PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(contra PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
add_subdirectory(src)
#------------------------------------------------------------------------------#
# Enable Regression Tests
#------------------------------------------------------------------------------#
include(CTest) # note: this adds a BUILD_TESTING which defaults to ON
# find python for running regression tests
find_package (Python COMPONENTS Interpreter QUIET)
if (Python_Interpreter_FOUND)
message (STATUS "Found PythonInterp: ${Python_EXECUTABLE}")
endif ()
if(BUILD_TESTING AND NOT Python_Interpreter_FOUND)
message(FATAL_ERROR "Testing requested, but python was not found")
endif()
#------------------------------------------------------------------------------#
# Add examples
#------------------------------------------------------------------------------#
if (BUILD_TESTING)
include(test)
add_subdirectory(testing)
add_subdirectory(examples)
endif()
#------------------------------------------------------------------------------#
# Export targets and package.
#------------------------------------------------------------------------------#
file(GLOB_RECURSE test_files testing "*.cta")
file(GLOB_RECURSE sample_files examples/contra "*.cta")
install( FILES ${test_files} ${sample_files} DESTINATION share/examples )
install( EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE Contra::
DESTINATION lib/cmake/${PROJECT_NAME}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_file(${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
${PROJECT_NAME}Config.cmake @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
)