-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
169 lines (148 loc) · 5.74 KB
/
CMakeLists.txt
File metadata and controls
169 lines (148 loc) · 5.74 KB
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.18)
project(Proteus
VERSION 0.1.0
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
option(PROTEUS_ENABLE_HIP "Enable HIP" OFF)
option(PROTEUS_ENABLE_CUDA "Enable CUDA" OFF)
option(PROTEUS_ENABLE_MPI "Enable MPI support for shared caching" OFF)
option(PROTEUS_ENABLE_MLIR "Enable MLIR backend" OFF)
option(BUILD_SHARED "Builds the JIT library as shared" OFF)
option(ENABLE_TESTS "Enable tests" OFF)
option(ENABLE_COVERAGE "Enable host-side coverage instrumentation" OFF)
option(ENABLE_DEVELOPER_COMPILER_FLAGS "Enable developer compiler flags: -Wall -Wextra -Werror" OFF)
option(PROTEUS_INSTALL_IMPL_HEADERS "Install implementation headers" OFF)
# Enforce LLVM_INSTALL_DIR requirement.
if(NOT DEFINED LLVM_INSTALL_DIR OR LLVM_INSTALL_DIR STREQUAL "")
message(FATAL_ERROR
"LLVM_INSTALL_DIR is required but not defined. "
"Please specify it with: cmake -DLLVM_INSTALL_DIR=/path/to/llvm/install ...")
endif()
# Verify LLVM_INSTALL_DIR exists.
if(NOT EXISTS "${LLVM_INSTALL_DIR}")
message(FATAL_ERROR
"LLVM_INSTALL_DIR points to non-existent directory: ${LLVM_INSTALL_DIR}")
endif()
message(STATUS "Using LLVM installation: ${LLVM_INSTALL_DIR}")
if (ENABLE_DEVELOPER_COMPILER_FLAGS)
add_compile_options(-Wall -Wextra -Werror "-Wno-error=\#warnings" -Wno-error=unknown-cuda-version)
endif()
if(ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:-g>"
"$<$<COMPILE_LANGUAGE:CXX>:-g>"
"$<$<COMPILE_LANGUAGE:C>:--coverage>"
"$<$<COMPILE_LANGUAGE:CXX>:--coverage>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xarch_host -g>"
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xarch_host --coverage>"
"$<$<COMPILE_LANGUAGE:HIP>:SHELL:-Xarch_host -g>"
"$<$<COMPILE_LANGUAGE:HIP>:SHELL:-Xarch_host --coverage>"
)
add_link_options(--coverage)
else()
message(FATAL_ERROR
"ENABLE_COVERAGE is only supported with Clang compilers.")
endif()
endif()
if(PROTEUS_ENABLE_HIP)
add_definitions("-DPROTEUS_ENABLE_HIP")
find_package(hip REQUIRED CONFIG)
find_package(hiprtc REQUIRED CONFIG)
message(STATUS "HIP Version: ${hip_VERSION}")
message(STATUS "hiprtc Version: ${hiprtc_VERSION}")
if(hip_VERSION VERSION_LESS "6.2.0")
message(FATAL_ERROR "HIP found: ${hip_VERSION} is less than minimum required version 6.2.0.")
endif()
# Find ROCm device library bitcode (ocml/ockl/oclc_*), typically under
# <ROCm>/amdgcn/bitcode. We rely on the ROCm-provided CMake package
# (rocm-device-libs) rather than hard-coding filesystem layout.
find_package(AMDDeviceLibs REQUIRED CONFIG
HINTS
${HIP_PACKAGE_PREFIX_DIR}
${HIP_PACKAGE_PREFIX_DIR}/..
${LLVM_INSTALL_DIR}
${LLVM_INSTALL_DIR}/..
)
message(STATUS "Found AMDDeviceLibs package in: ${AMDDeviceLibs_DIR}")
if(NOT TARGET ocml)
message(FATAL_ERROR "AMDDeviceLibs package did not define expected imported target: ocml")
endif()
get_target_property(_ocml_bc ocml IMPORTED_LOCATION)
if(NOT _ocml_bc OR NOT EXISTS "${_ocml_bc}")
message(FATAL_ERROR
"AMDDeviceLibs ocml imported target has missing IMPORTED_LOCATION: ${_ocml_bc}")
endif()
get_filename_component(PROTEUS_ROCM_AMDGCN_BITCODE_DIR "${_ocml_bc}" DIRECTORY)
message(STATUS "Found ROCm AMDGCN bitcode dir: ${PROTEUS_ROCM_AMDGCN_BITCODE_DIR}")
endif()
if(PROTEUS_ENABLE_MPI)
find_package(MPI REQUIRED)
message(STATUS "MPI Version: ${MPI_CXX_VERSION}")
endif()
if(PROTEUS_ENABLE_CUDA)
add_definitions("-DPROTEUS_ENABLE_CUDA")
find_package(CUDAToolkit 12 REQUIRED)
set(PROTEUS_NVCC_BIN "${PROTEUS_NVCC_BIN}" CACHE FILEPATH
"Path to nvcc used for CppJitCudaCompiler::Nvcc")
if(NOT PROTEUS_NVCC_BIN)
if(CUDAToolkit_NVCC_EXECUTABLE)
set(PROTEUS_NVCC_BIN "${CUDAToolkit_NVCC_EXECUTABLE}" CACHE FILEPATH
"Path to nvcc used for CppJitCudaCompiler::Nvcc" FORCE)
else()
find_program(PROTEUS_NVCC_BIN
NAMES nvcc
HINTS
"${CUDAToolkit_BIN_DIR}"
)
endif()
endif()
if(PROTEUS_NVCC_BIN)
message(STATUS "Found nvcc: ${PROTEUS_NVCC_BIN}")
else()
message(STATUS "nvcc not found; CppJitCudaCompiler::Nvcc will be unavailable at runtime")
endif()
find_file(LIBDEVICE_BC_FILE
NAMES libdevice.10.bc
PATHS "${CUDAToolkit_TARGET_DIR}/nvvm/libdevice"
NO_DEFAULT_PATH
)
if(NOT LIBDEVICE_BC_FILE)
message(FATAL_ERROR
"Could not locate libdevice bitcode under ${CUDAToolkit_TARGET_DIR}/nvvm/libdevice")
endif()
message(STATUS "Found libdevice bitcode: ${LIBDEVICE_BC_FILE}")
endif()
include(cmake/SetupLLVM.cmake)
include(cmake/ProteusFunctions.cmake)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
add_subdirectory(src)
if(ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/proteusConfig.cmake.in"
"${PROJECT_BINARY_DIR}/proteusConfig.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/proteus)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/proteusConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)
install(EXPORT proteusTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/proteus)
install(FILES
"${PROJECT_BINARY_DIR}/proteusConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/proteusConfig.cmake"
"${PROJECT_SOURCE_DIR}/cmake/ProteusFunctions.cmake"
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/proteus)