-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
128 lines (102 loc) · 4.47 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
cmake_minimum_required(VERSION 3.15...3.21 FATAL_ERROR)
# -- project setup -------------------------------------------------------------
project(
libfilter
VERSION 0.1.0
DESCRIPTION "High-speed Bloom filters and taffy filters for C and C++"
HOMEPAGE_URL "https://github.com/jbapple/libfilter"
LANGUAGES C CXX)
# -- sanity checks -------------------------------------------------------------
# Prohibit in-source builds.
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not allowed.")
endif ()
# Ensure that CMAKE_INSTALL_PREFIX is not a relative path.
if (NOT IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}")
message(
FATAL_ERROR
"CMAKE_INSTALL_PREFIX must be an absolute path: ${CMAKE_INSTALL_PREFIX}")
endif ()
# -- includes ------------------------------------------------------------------
include(CMakePackageConfigHelpers)
include(CMakePrintHelpers)
include(GNUInstallDirs)
# -- project configuration -----------------------------------------------------
# Determine whether we're building libfilter as a subproject. This is used to
# determine good default values for many options. libfilter should not modify
# global CMake if built as a subproject, unless explicitly requested to do so
# with options.
get_directory_property(_libfilter_PARENT_DIRECTORY PARENT_DIRECTORY)
if (_libfilter_PARENT_DIRECTORY)
set(libfilter_IS_SUBPROJECT ON)
set(libfilter_IS_NOT_SUBPROJECT OFF)
else ()
set(libfilter_IS_SUBPROJECT OFF)
set(libfilter_IS_NOT_SUBPROJECT ON)
endif ()
unset(_libfilter_PARENT_DIRECTORY)
# -- internal target -----------------------------------------------------------
# Create the internal target that is used for option/property propagation.
add_library(libfilter_internal INTERFACE)
set_target_properties(libfilter_internal PROPERTIES EXPORT_NAME internal)
add_library(libfilter::internal ALIAS libfilter_internal)
install(TARGETS libfilter_internal EXPORT libfilterTargets)
# Require standard C++20.
target_compile_features(libfilter_internal INTERFACE cxx_std_14)
# -- developer mode ------------------------------------------------------------
# Build libfilter in developer mode. This is enabled by default when not building
# libfilter as a subproject. The developer mode contains CCache support and many
# other niceties.
option(libfilter_ENABLE_DEVELOPER_MODE
"Enables build settings for a nicer development environment"
"${libfilter_IS_NOT_SUBPROJECT}")
if (libfilter_ENABLE_DEVELOPER_MODE)
# Support tools like clang-tidy by creating a compilation database and
# copying it to the project root.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Force colored output for the Ninja generator
if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(libfilter_internal
INTERFACE -fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options(libfilter_internal INTERFACE -fcolor-diagnostics)
endif ()
endif ()
# Keep make output sane
set(CMAKE_VERBOSE_MAKEFILE
OFF
CACHE STRING "Show all outputs including compiler lines." FORCE)
endif ()
if (libfilter_ENABLE_DEVELOPER_MODE OR libfilter_ENABLE_BUILDID)
# Relocate debug paths to a common prefix for CCache users that work from
# multiple worktrees.
# The debug paths affect the build-id, we rewrite them to get a more
# reproducible build.
target_compile_options(
libfilter_internal
INTERFACE "-fdebug-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.")
endif ()
add_subdirectory(c)
add_subdirectory(cpp)
# -- cmake export/config installations -----------------------------------------
export(
EXPORT libfilterTargets
FILE libfilterTargets.cmake
NAMESPACE libfilter::)
install(
EXPORT libfilterTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libfilter"
NAMESPACE libfilter::)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/libfilterConfigVersion.cmake"
VERSION "${libfilter_VERSION_MAJOR}.${libfilter_VERSION_MINOR}.${libfilter_VERSION_PATCH}"
COMPATIBILITY ExactVersion)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/libfilterConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/libfilterConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libfilter")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/libfilterConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libfilterConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libfilter")