-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
99 lines (88 loc) · 3.01 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
# ~~~
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
# ~~~
cmake_minimum_required(VERSION 3.21)
cmake_policy(SET CMP0091 NEW)
if(SKBUILD)
project(
${SKBUILD_PROJECT_NAME}
VERSION ${SKBUILD_PROJECT_VERSION}
LANGUAGES CXX
)
add_definitions(-DSCIPP_VERSION="${SKBUILD_PROJECT_VERSION_FULL}")
message(STATUS "Got version from SKBUILD: ${SKBUILD_PROJECT_VERSION_FULL}")
else()
execute_process(
COMMAND git describe --tags --exclude nightly
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE HAVE_GIT_VERSION_INFO
OUTPUT_VARIABLE GIT_VERSION_INFO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# We get something like 23.08.0-266-g068b161fe, remove the -g<hash> part
string(REGEX REPLACE "-g[0-9a-f]+$" "" GIT_VERSION_INFO ${GIT_VERSION_INFO})
# Replace '-' with '.dev' for PEP440 compatibility
string(REGEX REPLACE "-" ".dev" SCIPP_VERSION_PEP440 ${GIT_VERSION_INFO})
# Cmake does not like letters, remove the dev, will act as "tweak" number
string(REGEX REPLACE "-" "" SCIPP_VERSION_CMAKE ${GIT_VERSION_INFO})
project(
scipp
VERSION ${SCIPP_VERSION_CMAKE}
LANGUAGES CXX
)
if(${HAVE_GIT_VERSION_INFO} EQUAL 0)
message(STATUS "Got version from Git: ${GIT_VERSION_INFO}")
add_definitions(-DSCIPP_VERSION="${SCIPP_VERSION_PEP440}")
endif()
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
"Release"
CACHE
STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Custom install target for docs to depend on.
add_custom_target(
install-scipp COMMAND cmake --build ${CMAKE_CURRENT_BINARY_DIR} --target
install
)
include(docs)
add_docs_target(docs BUILDER html DEPENDS install-scipp)
add_docs_target(doctest BUILDER doctest DEPENDS docs)
add_docs_target(linkcheck BUILDER linkcheck DEPENDS docs)
add_custom_target(
cleanup_docs_html
COMMENT "Remove unnecessary .ipynb files from built HTML documentation."
COMMAND find "${CMAKE_BINARY_DIR}/html" -type f -name "*.ipynb" -not -path
"${CMAKE_BINARY_DIR}/html/_sources/*" -delete
VERBATIM
)
add_dependencies(cleanup_docs_html docs)
include(GNUInstallDirs)
if(DEFINED ENV{SP_DIR}) # Defined by conda-build
file(TO_CMAKE_PATH $ENV{SP_DIR}/scipp PYTHONDIR)
file(TO_CMAKE_PATH $ENV{SP_DIR} ARCHIVEDIR)
else()
set(PYTHONDIR scipp)
set(ARCHIVEDIR .)
endif()
set(INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
if(SKBUILD)
set(PYTHONDIR .)
# scikit-build will not include files outside the directory of the Python
# module, ensure our shared objects are installed there.
set(RELATIVE_LIB ".")
# Note that we do not install src/scipp when making a `pip` package. It will
# simply use the source directory directly. C++ libraries get installed into
# the source dir.
else()
install(DIRECTORY "src/scipp/" DESTINATION ${PYTHONDIR})
set(RELATIVE_LIB "..")
endif()
enable_testing()
add_subdirectory(lib)