-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
211 lines (157 loc) · 6.63 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
cmake_minimum_required(VERSION 3.18..3.21)
project(GooseFEM)
string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPER)
# Command-line options
# ====================
option(BUILD_ALL "${PROJECT_NAME}: Build tests, Python API & docs" OFF)
option(BUILD_TESTS "${PROJECT_NAME}: Build tests" OFF)
option(BUILD_PYTHON "${PROJECT_NAME}: Build Python API" OFF)
option(BUILD_DOCS "${PROJECT_NAME}: Build docs (use `make html`)" OFF)
option(USE_WARNINGS "${PROJECT_NAME}: Build with runtime warnings" ON)
option(USE_ASSERT "${PROJECT_NAME}: Build with assertions" ON)
option(USE_DEBUG "${PROJECT_NAME}: Build in debug mode" OFF)
option(USE_SIMD "${PROJECT_NAME}: Build with hardware optimization" OFF)
if(SKBUILD)
set(BUILD_ALL 0)
set(BUILD_TESTS 0)
set(BUILD_PYTHON 1)
set(BUILD_DOCS 0)
endif()
# Read version
# ============
if (DEFINED ENV{SETUPTOOLS_SCM_PRETEND_VERSION})
set(PROJECT_VERSION $ENV{SETUPTOOLS_SCM_PRETEND_VERSION})
message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION} (read from SETUPTOOLS_SCM_PRETEND_VERSION)")
else()
execute_process(
COMMAND python -c "from setuptools_scm import get_version; print(get_version())"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Building ${PROJECT_NAME} ${PROJECT_VERSION}")
endif()
# Set target
# ==========
find_package(xtensor REQUIRED)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_link_libraries(${PROJECT_NAME} INTERFACE xtensor)
target_compile_definitions(${PROJECT_NAME} INTERFACE
${PROJECT_NAME_UPPER}_VERSION="${PROJECT_VERSION}")
# Libraries
# =========
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(CTest)
include("${PROJECT_NAME}Config.cmake")
# Installation headers / CMake / pkg-config
# =========================================
if(NOT SKBUILD)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include)
configure_file("include/${PROJECT_NAME}/version.h"
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/version.h"
DESTINATION "include/${PROJECT_NAME}/")
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets)
install(
EXPORT ${PROJECT_NAME}-targets
FILE "${PROJECT_NAME}Targets.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(${PROJECT_NAME}_TMP ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion)
set(CMAKE_SIZEOF_VOID_P ${${PROJECT_NAME}_TMP})
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig/")
endif()
# Build tests
# ===========
if(BUILD_TESTS OR BUILD_ALL)
enable_testing()
add_subdirectory(tests/basic)
endif()
# Build Python API
# ================
if(BUILD_PYTHON OR BUILD_ALL)
# The C++ functions are build to a library with name "_${PROJECT_NAME}"
# The Python library simply loads all functions
set(PYPROJECT_NAME "_${PROJECT_NAME}")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
find_package(pybind11 REQUIRED CONFIG)
find_package(xtensor-python REQUIRED)
if (SKBUILD)
find_package(NumPy REQUIRED)
else()
find_package(Python REQUIRED COMPONENTS Interpreter Development NumPy)
endif()
pybind11_add_module(${PYPROJECT_NAME} python/main.cpp)
target_compile_definitions(${PYPROJECT_NAME} PUBLIC VERSION_INFO=${PROJECT_VERSION})
target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME} xtensor-python)
if (SKBUILD)
target_include_directories(${PYPROJECT_NAME} PUBLIC ${NumPy_INCLUDE_DIRS})
else()
target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME} pybind11::module Python::NumPy)
endif()
if (USE_WARNINGS)
target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME}::warnings)
message(STATUS "Compiling ${PROJECT_NAME}-Python with run-time warnings")
endif()
if (USE_ASSERT)
target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME}::assert)
message(STATUS "Compiling ${PROJECT_NAME}-Python with assertions")
endif()
if (USE_DEBUG)
target_link_libraries(${PYPROJECT_NAME} PUBLIC ${PROJECT_NAME}::debug)
message(STATUS "Compiling ${PROJECT_NAME}-Python in debug mode")
endif()
if (USE_SIMD)
find_package(xtensor REQUIRED)
find_package(xsimd REQUIRED)
target_link_libraries(${PYPROJECT_NAME} PUBLIC xtensor::optimize xtensor::use_xsimd)
message(STATUS "Compiling ${PROJECT_NAME}-Python with hardware optimization")
endif()
if (SKBUILD)
if(APPLE)
set_target_properties(${PYPROJECT_NAME} PROPERTIES INSTALL_RPATH "@loader_path/${CMAKE_INSTALL_LIBDIR}")
else()
set_target_properties(${PYPROJECT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/${CMAKE_INSTALL_LIBDIR}")
endif()
install(TARGETS ${PYPROJECT_NAME} DESTINATION .)
endif()
endif()
# Build documentation
# ===================
if(BUILD_DOCS OR BUILD_ALL)
find_package(Doxygen REQUIRED)
set(DOXYGEN_EXCLUDE_SYMBOLS detail)
set(DOXYGEN_CASE_SENSE_NAMES YES)
set(DOXYGEN_USE_MATHJAX YES)
set(DOXYGEN_GENERATE_TREEVIEW YES)
set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
set(DOXYGEN_MACRO_EXPANSION YES)
set(DOXYGEN_SOURCE_BROWSER YES)
set(DOXYGEN_GENERATE_XML YES)
set(DOXYGEN_QUIET YES)
set(DOXYGEN_WARN_IF_UNDOCUMENTED YES)
set(DOXYGEN_WARN_AS_ERROR NO)
set(DOXYGEN_HTML_COLORSTYLE TOGGLE)
set(DOXYGEN_WARN_LOGFILE "${CMAKE_CURRENT_BINARY_DIR}/doxygen_warnings.log")
set(DOXYGEN_ALIASES "license=@par License:")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "README.md")
set(DOXYGEN_STRIP_FROM_INC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(DOXYGEN_STRIP_FROM_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
doxygen_add_docs(html "${CMAKE_CURRENT_SOURCE_DIR}/include" "README.md")
endif()