-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
157 lines (134 loc) · 5.4 KB
/
CMakeLists.txt
File metadata and controls
157 lines (134 loc) · 5.4 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
cmake_minimum_required(VERSION 3.28)
project(PyTNL
LANGUAGES CXX
)
# Declare all CMake options for the project
option(PyTNL_EXPORT_INTERFACE_TARGETS "Instruct CMake to generate rules to export the interface target" ${PROJECT_IS_TOP_LEVEL})
option(PyTNL_ENABLE_INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimization (IPO/LTO) for PyTNL targets" ON)
option(PyTNL_USE_CUDA "Build with CUDA support" ON)
# make cache variables for install destinations
include(GNUInstallDirs)
# install paths relative to the cmake's prefix
if (SKBUILD_DATA_DIR)
set(PyTNL_TARGET_CMAKE_DIRECTORY "${SKBUILD_DATA_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
else()
set(PyTNL_TARGET_CMAKE_DIRECTORY "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif()
# Set the install path for Python modules
find_package(Python 3 COMPONENTS Interpreter Development REQUIRED)
if (SKBUILD_PLATLIB_DIR)
set(PyTNL_PYTHON_SITE_PACKAGES_DIR "${SKBUILD_PLATLIB_DIR}")
else()
# Make cache variable so it can be used in downstream projects
set(PyTNL_PYTHON_SITE_PACKAGES_DIR lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages
CACHE INTERNAL "Path where PyTNL Python packages are installed")
endif()
# Require C++17, and disable compiler-specific extensions (if possible).
foreach(lang CXX)
set(CMAKE_${lang}_STANDARD 17)
set(CMAKE_${lang}_STANDARD_REQUIRED ON)
set(CMAKE_${lang}_EXTENSIONS OFF)
endforeach()
# Set build flags for CXX
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG}")
# Check and enable CUDA
if(PyTNL_USE_CUDA)
# Set one default GPU architecture to avoid building for all GPU architectures
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES "native")
endif()
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(PyTNL_BUILD_CUDA TRUE)
# Set C++ standard
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_EXTENSIONS OFF)
# Set project-specific (i.e. not exported) build options
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wall")
set(CMAKE_CUDA_FLAGS_DEBUG "-g")
set(CMAKE_CUDA_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELEASE} ${CMAKE_CUDA_FLAGS_DEBUG}")
# Enable separable compilation
set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
# nanobind sets only the CXX_VISIBILITY_PRESET cmake target property to hidden,
# which does not affect intermediate CUDA objects
set(CMAKE_CUDA_VISIBILITY_PRESET hidden)
endif()
endif()
# make cache variable so it can be used in downstream projects
set(PyTNL_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/include"
CACHE INTERNAL "Directories where PyTNL headers are located")
# create the exported targets
add_library(PyTNL INTERFACE)
# aliases to match exported targets
add_library(PyTNL::PyTNL ALIAS PyTNL)
# add the include directory to the interface
if(PROJECT_IS_TOP_LEVEL)
set(PyTNL_SYSTEM "")
else()
set(PyTNL_SYSTEM SYSTEM)
endif()
target_include_directories(PyTNL ${PyTNL_SYSTEM}
INTERFACE $<BUILD_INTERFACE:${PyTNL_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# add compiler features to the interface
target_compile_features(PyTNL INTERFACE cxx_std_17)
if(PyTNL_EXPORT_INTERFACE_TARGETS)
# export the interface targets
install(TARGETS PyTNL EXPORT PyTNLTargets)
# install a CMake file for the interface target
install(EXPORT PyTNLTargets
NAMESPACE PyTNL::
DESTINATION ${PyTNL_TARGET_CMAKE_DIRECTORY})
# install the PyTNLConfig.cmake file
include(CMakePackageConfigHelpers)
configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${PyTNL_TARGET_CMAKE_DIRECTORY})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${PyTNL_TARGET_CMAKE_DIRECTORY})
endif()
# Set position independent code for all targets, including dependencies
# downloaded and built by FetchContent. Otherwise, linking to static libraries
# without PIC fails.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Find or fetch dependencies
include(FetchContent)
FetchContent_Declare(TNL
GIT_REPOSITORY https://gitlab.com/tnl-project/tnl.git
GIT_TAG 0.2.0
SYSTEM
EXCLUDE_FROM_ALL
)
set(TNL_EXPORT_INTERFACE_TARGETS ON) # needed for adding to the interface target
FetchContent_MakeAvailable(TNL)
FetchContent_Declare(nanobind
GIT_REPOSITORY https://github.com/wjakob/nanobind.git
GIT_TAG v2.12.0
SYSTEM
FIND_PACKAGE_ARGS
)
FetchContent_MakeAvailable(nanobind)
FetchContent_Declare(
tinyxml2
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
GIT_TAG 11.0.0
SYSTEM
FIND_PACKAGE_ARGS
)
set(tinyxml2_BUILD_TESTING OFF)
FetchContent_MakeAvailable(tinyxml2)
find_package(MPI COMPONENTS CXX REQUIRED)
find_package(ZLIB REQUIRED)
# Add dependencies to the interface target
target_link_libraries(PyTNL INTERFACE TNL::TNL)
# Add subdirectories
add_subdirectory(include)
add_subdirectory(src)