-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCMakeLists.txt
143 lines (118 loc) · 4.29 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
# Cmake config largely taken from catch2
cmake_minimum_required(VERSION 3.5)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
cmake_policy(SET CMP0135 NEW)
endif()
# detect if Catch is being bundled,
# disable testsuite in that case
if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON)
# If RapidFuzz is not being used as a subproject via `add_subdirectory`,
# usually installation is required
option(RAPIDFUZZ_INSTALL "Install rapidfuzz" ON)
else()
set(NOT_SUBPROJECT OFF)
# If RapidFuzz is being used as a subproject via `add_subdirectory`,
# chances are that the "main project" does not include RapidFuzz headers
# in any of its headers, in which case installation is not needed.
option(RAPIDFUZZ_INSTALL "Install rapidfuzz (Projects embedding rapidfuzz may want to turn this OFF.)" OFF)
endif()
option(RAPIDFUZZ_BUILD_TESTING "Build tests" OFF)
option(RAPIDFUZZ_ENABLE_LINTERS "Enable Linters for the test builds" OFF)
option(RAPIDFUZZ_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(RAPIDFUZZ_BUILD_FUZZERS "Build fuzzers" OFF)
# RapidFuzz's build breaks if done in-tree. You probably should not build
# things in tree anyway, but we can allow projects that include RapidFuzz
# as a subproject to build in-tree as long as it is not in our tree.
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()
project(rapidfuzz LANGUAGES CXX VERSION 3.2.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Basic paths
set(BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SOURCES_DIR ${BASE_DIR}/rapidfuzz)
set(TEST_DIR ${BASE_DIR}/test)
set(BENCHMARK_DIR ${BASE_DIR}/tests/bench)
set(EXAMPLES_DIR ${BASE_DIR}/examples)
add_library(rapidfuzz INTERFACE)
# provide a namespaced alias for clients to 'link' against if RapidFuzz is included as a sub-project
add_library(rapidfuzz::rapidfuzz ALIAS rapidfuzz)
target_compile_features(rapidfuzz INTERFACE cxx_std_17)
target_include_directories(rapidfuzz
INTERFACE
$<BUILD_INTERFACE:${SOURCES_DIR}/..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# Build tests only if requested
if(RAPIDFUZZ_BUILD_TESTING AND NOT_SUBPROJECT)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
# Build examples only if requested
if(RAPIDFUZZ_BUILD_EXAMPLES)
#add_subdirectory(examples)
endif()
# Build benchmarks only if requested
if(RAPIDFUZZ_BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()
# Build fuzz tests only if requested
if(RAPIDFUZZ_BUILD_FUZZERS)
add_subdirectory(fuzzing)
endif()
if (RAPIDFUZZ_INSTALL)
set(RAPIDFUZZ_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/rapidfuzz")
install(
TARGETS
rapidfuzz
EXPORT
rapidfuzzTargets
DESTINATION
${CMAKE_INSTALL_LIBDIR}
)
install(
EXPORT
rapidfuzzTargets
NAMESPACE
rapidfuzz::
DESTINATION
${RAPIDFUZZ_CMAKE_CONFIG_DESTINATION}
)
install(
DIRECTORY
rapidfuzz
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.impl"
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${RAPIDFUZZ_CMAKE_CONFIG_DESTINATION}
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${RAPIDFUZZ_CMAKE_CONFIG_DESTINATION}
)
# CPack/CMake started taking the package version from project version 3.12
# So we need to set the version manually for older CMake versions
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
endif()
set(CPACK_PACKAGE_VENDOR "Max Bachmann")
set(CPACK_PACKAGE_CONTACT "https://github.com/rapidfuzz/rapidfuzz-cpp")
include(CPack)
endif(RAPIDFUZZ_INSTALL)