forked from improbable-eng/phtree-cpp
-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
163 lines (133 loc) · 5.79 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
cmake_minimum_required(VERSION 3.14)
project(phtree VERSION 1.6.1
DESCRIPTION "PH-Tree C++"
HOMEPAGE_URL "https://github.com/tzaeschke/phtree-cpp"
LANGUAGES CXX)
cmake_policy(SET CMP0077 NEW)
# ---------------------------------------------------------------------------------------
# Set default build to release
# ---------------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif ()
# ---------------------------------------------------------------------------------------
# Build options
# ---------------------------------------------------------------------------------------
option(PHTREE_BUILD_ALL "Build examples, tests and benchmarks" OFF)
# example options
option(PHTREE_BUILD_EXAMPLES "Build examples" OFF)
# testing options
option(PHTREE_BUILD_TESTS "Build tests" OFF)
option(PHTREE_CODE_COVERAGE "Collect coverage from test library" OFF)
if (PHTREE_CODE_COVERAGE)
set(PHTREE_BUILD_TESTS ON)
endif ()
# bench options
option(PHTREE_BUILD_BENCHMARKS "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
# install options
option(PHTREE_INSTALL "Generate the install target" OFF)
# ---------------------------------------------------------------------------------------
# Compiler config
# ---------------------------------------------------------------------------------------
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
message("CCACHE is found")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
else (CCACHE_FOUND)
message("CCACHE is NOT found")
endif (CCACHE_FOUND)
# specify the C++ standard
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif ()
if (MSVC)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
set(CMAKE_CXX_FLAGS_RELEASE "/O2")
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
add_compile_options(/bigobj)
endif ()
# For google benchmark
if (PHTREE_BUILD_BENCHMARKS) # OR PHTREE_BUILD_ALL)
# This still doesn't work. This also breaks gtest
# See for example
# https://stackoverflow.com/questions/55376111/how-to-build-and-link-google-benchmark-using-cmake-in-windows
# https://github.com/google/benchmark/issues/1348
# https://github.com/google/benchmark/issues/639
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# set(BUILD_SHARED_LIBS TRUE) #=TRUE
# set(BENCHMARK_DOWNLOAD_DEPENDENCIES on)
# set(BENCHMARK_ENABLE_GTEST_TESTS OFF)
endif ()
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
if (PHTREE_BUILD_BENCHMARKS)
# Enable vectorization and TZCNT/CTZ
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mavx -mbmi2 -pthread")
else ()
# Enable vectorization and TZCNT/CTZ
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mavx -mbmi2 ")
endif ()
if (PHTREE_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # -Wa,-mbig-obj")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif ()
endif ()
# ---------------------------------------------------------------------------------------
# Build binaries
# ---------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------
# Header only version
# ---------------------------------------------------------------------------------------
add_library(phtree INTERFACE)
add_library(phtree::phtree ALIAS phtree)
target_compile_features(phtree INTERFACE cxx_std_17)
target_include_directories(phtree INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if (PHTREE_BUILD_EXAMPLES OR PHTREE_BUILD_ALL)
message(STATUS "Generating examples")
add_subdirectory(examples)
endif ()
if ((PHTREE_BUILD_BENCHMARKS OR PHTREE_BUILD_ALL) AND NOT MSVC)
message(STATUS "Generating benchmarks")
add_subdirectory(benchmark)
endif ()
if (PHTREE_BUILD_TESTS OR PHTREE_BUILD_ALL)
message(STATUS "Generating tests")
enable_testing()
include(GoogleTest)
add_subdirectory(test)
endif ()
# ---------------------------------------------------------------------------------------
# Install
# ---------------------------------------------------------------------------------------
if (PHTREE_INSTALL)
include(GNUInstallDirs)
install(TARGETS phtree
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file("phtreeConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE phtree::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/phtree
DESTINATION include
PATTERN "BUILD" EXCLUDE
PATTERN "*.md" EXCLUDE)
endif ()