-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
129 lines (113 loc) · 4.3 KB
/
Copy pathCMakeLists.txt
File metadata and controls
129 lines (113 loc) · 4.3 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
cmake_minimum_required(VERSION 3.22)
project(libnomp VERSION 0.0.1 DESCRIPTION "nomp runtime library" LANGUAGES C)
# Nomp options.
option(ENABLE_OPENCL "Build OpenCL Backend" OFF)
option(ENABLE_CUDA "Build CUDA Backend" OFF)
option(ENABLE_HIP "Build HIP Backend" OFF)
option(ENABLE_TESTS "Enable libnomp Unit Tests" OFF)
option(ENABLE_DOCS "Enable Documentation" OFF)
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
# Nomp compile time constants which goes in `nomp-defs.h`.
set(NOMP_MAX_BUFFER_SIZE 128)
set(NOMP_MAX_SOURCE_SIZE 16384)
set(NOMP_MAX_CFLAGS_SIZE 16384)
set(NOMP_MAX_KERNEL_ARGS_SIZE 64)
set(NOMP_MAX_SCRATCH_SIZE 32768)
set(NOMP_DEFAULT_VERBOSE 2)
set(NOMP_DEFAULT_PROFILE 0)
set(NOMP_DEFAULT_DEVICE 0)
set(NOMP_DEFAULT_PLATFORM 0)
configure_file(include/nomp-defs.h.in include/nomp-defs.h @ONLY)
# C standard options.
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
# Set cmake module path.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
# Use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# When building, don't use the install RPATH
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# Set the library location
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# Add the automatically determined parts of the RPATH which point to directories
# outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(SOURCES src/nomp.c src/loopy.c src/symengine.c src/aux.c src/log.c src/reduction.c)
if (ENABLE_OPENCL)
find_package(OpenCL REQUIRED)
if (OpenCL_FOUND)
list(APPEND SOURCES backends/opencl.c)
else()
message(FATAL_ERROR "ENABLE_OPENCL is ON but unable to find OPENCL runtime.")
endif()
endif()
if (ENABLE_CUDA)
find_package(CUDAToolkit REQUIRED)
if (CUDAToolkit_FOUND)
list(APPEND SOURCES backends/cuda.c)
else()
message(FATAL_ERROR "ENABLE_CUDA is ON but unable to find CUDA runtime.")
endif()
endif()
if (ENABLE_HIP)
find_package(HIP)
if(HIP_FOUND)
list(APPEND SOURCES backends/hip.c)
else()
message(FATAL_ERROR "ENABLE_HIP is ON but unable to find HIP runtime.")
endif()
endif()
add_library(nomp SHARED ${SOURCES})
set_target_properties(nomp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER include/nomp.h)
target_include_directories(nomp PRIVATE include ${CMAKE_BINARY_DIR}/include)
target_compile_options(nomp PRIVATE $<$<C_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
target_link_libraries(nomp PRIVATE Python3::Python)
find_package(SymEngine REQUIRED)
target_include_directories(nomp PRIVATE ${SYMENGINE_INCLUDE_DIRS})
target_link_libraries(nomp PRIVATE ${SYMENGINE_LIBRARIES})
if (ENABLE_OPENCL)
target_link_libraries(nomp PRIVATE OpenCL::OpenCL)
target_compile_definitions(nomp PRIVATE OPENCL_ENABLED)
endif()
if (ENABLE_CUDA)
target_link_libraries(nomp PRIVATE CUDA::cudart CUDA::nvrtc)
target_compile_definitions(nomp PRIVATE CUDA_ENABLED)
endif()
if (ENABLE_HIP)
target_link_libraries(nomp PRIVATE nomp::HIP)
target_compile_definitions(nomp PRIVATE HIP_ENABLED)
endif()
# Add AddressSanitizer if it is enabled and supported.
set(HAS_ADDRESS_SANITIZER FALSE)
if (ENABLE_ASAN)
include(CheckLinkerFlag)
check_linker_flag(C -fsanitize=address ASAN_SUPPORTED)
set(HAS_ADDRESS_SANITIZER ${ASAN_SUPPORTED})
if (NOT HAS_ADDRESS_SANITIZER)
message(FATAL_ERROR "AddressSanitizer is enabled but not supported.")
else()
target_compile_options(nomp PRIVATE -fsanitize=address)
target_link_options(nomp PRIVATE -fsanitize=address)
endif()
endif()
if (ENABLE_DOCS)
add_subdirectory(docs)
endif()
if (ENABLE_TESTS)
add_subdirectory(tests)
endif()
install(TARGETS nomp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/python DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY bin/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
configure_file(nomp.pc.in nomp.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/nomp.pc DESTINATION
${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)