-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
146 lines (110 loc) · 4.49 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
# structure and content of CMakeLists.txt files adapted from
# https://stackoverflow.com/questions/55635294/how-to-create-packages-with-cmake
cmake_minimum_required(VERSION 3.16.0)
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
include(CMakePackageConfigHelpers)
include(CheckLanguage)
#-------------------------------------------------------------
# Read the line containing 'version =' from pyproject.toml
file(STRINGS pyproject.toml versionLine REGEX "^version = ")
# Extract the version number from the matched line
if("${versionLine}" MATCHES "^version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"")
set(PARALLELPROJ_VERSION "${CMAKE_MATCH_1}")
message(STATUS "BUILDING VERSION: ${PARALLELPROJ_VERSION}")
else()
message(FATAL_ERROR "Version not found in pyproject.toml")
endif()
#-------------------------------------------------------------
project(parallelproj VERSION ${PARALLELPROJ_VERSION} LANGUAGES C)
include(CTest)
enable_testing()
# get standard paths for installation
include(GNUInstallDirs)
set (CMAKE_BUILD_TYPE Release CACHE STRING "build type" FORCE)
#-------------------------------------------------------------
# define INSTALL dirs for libraries, public headers and documentation
# by default we use the GNUInstallDirs
# variable whether to build with auto-generated IDL wrappers
set(PARALLELPROJ_BUILD_WITH_IDL_WRAPPERS FALSE CACHE BOOL "include auto-generated IDL wrapper sources in build")
set(SKIP_OPENMP_LIB FALSE CACHE BOOL "do not build the openmp lib")
set(SKIP_CUDA_LIB FALSE CACHE BOOL "do not build the cuda lib")
set(SKIP_DOCS FALSE CACHE BOOL "do not build the documentation")
# skip build of the CUDA lib, if CUDA is not available
check_language(CUDA)
if(NOT CMAKE_CUDA_COMPILER)
message(STATUS "CUDA not available skipping build of CUDA LIB")
set(SKIP_CUDA_LIB TRUE)
endif()
#-------------------------------------------------------------
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
#-------------------------------------------------------------
# check if Doxygen is installed
find_package(Doxygen)
#-------------------------------------------------------------
# build the C/OpenMP lib
if (NOT SKIP_OPENMP_LIB)
add_subdirectory(c)
else()
message(STATUS "Skipping build of openMP lib")
endif()
if(NOT SKIP_CUDA_LIB)
add_subdirectory(cuda)
else(NOT SKIP_CUDA_LIB)
message(STATUS "Skipping build of cuda lib")
endif(NOT SKIP_CUDA_LIB)
#-------------------------------------------------------------
# install the targets
install(
EXPORT parallelprojTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/parallelproj
NAMESPACE parallelproj::
FILE parallelprojTargets.cmake # Not sure if this is still needed
)
#-------------------------------------------------------------
# build the documentation with Doxygen
if (NOT SKIP_DOCS)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
# note the option ALL which allows to build the docs together with the application
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
endif (DOXYGEN_FOUND)
else()
message(STATUS "skipping build of documentation")
endif()
#-------------------------------------------------------------
# generate and install cmake package and version files
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/parallelprojConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/parallelproj
PATH_VARS
CMAKE_INSTALL_LIBDIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/parallelprojConfigVersion.cmake
VERSION ${parallelproj_VERSION}
COMPATIBILITY SameMajorVersion
)
# Install Config and ConfigVersion files
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/parallelprojConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/parallelprojConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/parallelproj"
)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()