-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
110 lines (90 loc) · 3.71 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
cmake_minimum_required(VERSION 3.24)
project(dicomnode_c LANGUAGES CXX)
include(ProcessorCount)
ProcessorCount(NUMBER_OF_PROCESSORS)
if(NOT NUMBER_OF_PROCESSORS EQUAL 0)
message(STATUS "Processors ${NUMBER_OF_PROCESSORS}")
set(CMAKE_BUILD_PARALLEL_LEVEL ${NUMBER_OF_PROCESSORS})
set_property(GLOBAL PROPERTY JOB_POOLS compile_pool=${NUMBER_OF_PROCESSORS})
set(CMAKE_JOB_POOL_COMPILE compile_pool)
endif()
set(VERSION_INFO 0.0.1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 REQUIRED)
function(add_py_object_library name source)
add_library(${name} OBJECT ${source})
target_link_libraries(${name} PRIVATE pybind11::module Python::Python utilities)
target_include_directories(${name} PRIVATE ${pybind11_INCLUDE_DIRS} ${Python_INCLUDE_DIRS})
target_compile_options(${name} PRIVATE -O3)
set_property(TARGET ${name} PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${name} PROPERTY CUDA_ARCHITECTURES native)
endfunction()
# Create object libraries for each source file
# -----------------------------------------------------------------------
# Checking for CUDA
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
message(STATUS "CUDA enabled!")
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
#
message(status ${PYTHON_INCLUDE_DIRS})
add_library(utilities OBJECT low_level_src/python/utilities.cu)
target_link_libraries(utilities PRIVATE pybind11::module Python::Python)
target_include_directories(utilities PRIVATE ${pybind11_INCLUDE_DIRS} ${Python_INCLUDE_DIRS})
target_compile_options(utilities PRIVATE -O3)
set_property(TARGET utilities PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET utilities PROPERTY CUDA_ARCHITECTURES native)
set(CUDA_LIBRARIES
bounding_box low_level_src/python/python_bounding_box.cu
cuda_management low_level_src/python/python_cuda_management.cu
mirror low_level_src/python/python_mirror.cu
interpolation low_level_src/python/python_interpolation.cu
)
set(OBJECT_TARGETS)
list(LENGTH CUDA_LIBRARIES LIBRARY_COUNT)
math(EXPR LIBRARY_COUNT "${LIBRARY_COUNT} - 1")
foreach(INDEX RANGE 0 ${LIBRARY_COUNT} 2)
math(EXPR SOURCE_INDEX "${INDEX} + 1")
list(GET CUDA_LIBRARIES ${INDEX} LIBRARY_NAME)
list(GET CUDA_LIBRARIES ${SOURCE_INDEX} SOURCE_FILE)
add_py_object_library(${LIBRARY_NAME} ${SOURCE_FILE})
list(APPEND OBJECT_TARGETS $<TARGET_OBJECTS:${LIBRARY_NAME}>)
endforeach()
pybind11_add_module(_cuda SHARED
low_level_src/python_entry_point.cu
$<TARGET_OBJECTS:utilities>
${OBJECT_TARGETS}
)
target_compile_options(_cuda PRIVATE -O3)
set_property(TARGET _cuda PROPERTY CUDA_ARCHITECTURES native)
# In debug create tests:
if(NOT DEFINED NO_TESTING)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG e397860
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
#set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
add_executable(cu_tests low_level_src/test_initiator.cu)
target_link_libraries(
cu_tests
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(cu_tests)
# Sadly Coverage for GPU code is not supported...
# https://docs.nvidia.com/cuda/cuda-features-archive/index.html#bullseye-support
endif()
else()
message(STATUS "No Cuda Compiler!")
endif()
# -----------------------------------------------------------------------