forked from man-group/sparrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
210 lines (170 loc) · 7.77 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
# Copyright 2024 Man Group Operations Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.27)
# This is better specified per target, but cmake keeps ignoring these language version
# specification when building this project by itself, in particular the gnu extensions,
# so here we go.
# This will affects all following targets being defined.
set(CMAKE_CXX_EXTENSIONS OFF)
cmake_policy(SET CMP0091 NEW)
project(sparrow CXX)
include(CMakeDependentOption)
set(SPARROW_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Versionning
# ===========
file(STRINGS "${SPARROW_INCLUDE_DIR}/sparrow/config/sparrow_version.hpp" sparrow_version_defines
REGEX "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH)")
foreach(ver ${sparrow_version_defines})
if(ver MATCHES "constexpr int SPARROW_VERSION_(MAJOR|MINOR|PATCH) = ([0-9]+);$")
set(SPARROW_VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
endif()
endforeach()
set(${PROJECT_NAME}_VERSION
${SPARROW_VERSION_MAJOR}.${SPARROW_VERSION_MINOR}.${SPARROW_VERSION_PATCH})
message(STATUS "Building sparrow v${${PROJECT_NAME}_VERSION}")
# Build options
# =============
OPTION(BUILD_TESTS "Build sparrow test suite" OFF)
OPTION(BUILD_DOCS "Build sparrow documentation" OFF)
OPTION(BUILD_EXAMPLES "Build sparrow examples" OFF)
OPTION(USE_DATE_POLYFILL "Use date polyfill implementation" ON)
include(CheckCXXSymbolExists)
if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(header version)
else()
set(header ciso646)
endif()
check_cxx_symbol_exists(_LIBCPP_VERSION ${header} LIBCPP)
if(LIBCPP)
message(STATUS "Using libc++")
# Allow the use of not visible yet availabile features, such
# as some formatter for new types.
add_compile_definitions(_LIBCPP_DISABLE_AVAILABILITY)
endif()
# Linter options
# =============
OPTION(ACTIVATE_LINTER "Create targets to run clang-format" OFF)
cmake_dependent_option(ACTIVATE_LINTER_DURING_COMPILATION "Run linter during the compilation" ON "ACTIVATE_LINTER" OFF)
if(ACTIVATE_LINTER)
include(cmake/clang-format.cmake)
include(cmake/clang-tidy.cmake)
endif()
# Sanitizers
# ==========
include(cmake/sanitizers.cmake)
# Dependencies
# ============
set(SPARROW_INTERFACE_DEPENDENCIES "" CACHE STRING "List of dependencies to be linked to the sparrow target")
if (USE_DATE_POLYFILL)
find_package(date CONFIG REQUIRED)
list(APPEND SPARROW_INTERFACE_DEPENDENCIES date::date date::date-tz)
add_compile_definitions(SPARROW_USE_DATE_POLYFILL)
endif()
# Build
# =====
set(SPARROW_HEADERS
${SPARROW_INCLUDE_DIR}/sparrow/array.hpp
${SPARROW_INCLUDE_DIR}/sparrow/c_interface.hpp
${SPARROW_INCLUDE_DIR}/sparrow/sparrow.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/array_common.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/array_data.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/array_data_concepts.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/external_array_data.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/array_data_factory.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/data_traits.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/data_type.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/data_storages.hpp
${SPARROW_INCLUDE_DIR}/sparrow/array/typed_array.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_array_schema_utils.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_array.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_array/deleter.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_array/private_data.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_array/smart_pointers.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_schema.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_schema/deleter.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_schema/private_data.hpp
${SPARROW_INCLUDE_DIR}/sparrow/arrow_interface/arrow_schema/smart_pointers.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer/allocator.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer/buffer.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer/buffer_adaptor.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer/buffer_view.hpp
${SPARROW_INCLUDE_DIR}/sparrow/buffer/dynamic_bitset.hpp
${SPARROW_INCLUDE_DIR}/sparrow/config/config.hpp
${SPARROW_INCLUDE_DIR}/sparrow/config/sparrow_version.hpp
${SPARROW_INCLUDE_DIR}/sparrow/layout/dictionary_encoded_layout.hpp
${SPARROW_INCLUDE_DIR}/sparrow/layout/fixed_size_layout.hpp
${SPARROW_INCLUDE_DIR}/sparrow/layout/layout_iterator.hpp
${SPARROW_INCLUDE_DIR}/sparrow/layout/null_layout.hpp
${SPARROW_INCLUDE_DIR}/sparrow/layout/variable_size_binary_layout.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/algorithm.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/contracts.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/iterator.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/memory.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/mp_utils.hpp
${SPARROW_INCLUDE_DIR}/sparrow/utils/nullable.hpp
${SPARROW_INCLUDE_DIR}/sparrow/details/3rdparty/float16_t.hpp
)
add_library(sparrow INTERFACE ${SPARROW_HEADERS})
target_include_directories(sparrow INTERFACE
$<BUILD_INTERFACE:${SPARROW_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)
target_link_libraries(sparrow INTERFACE ${SPARROW_INTERFACE_DEPENDENCIES})
# We do not use non-standard C++
set_target_properties(sparrow PROPERTIES CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(sparrow INTERFACE cxx_std_20)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif ()
# Docs
# ====
if(BUILD_DOCS)
add_subdirectory(docs)
endif()
# Examples
# ========
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Installation
# ============
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS sparrow
EXPORT ${PROJECT_NAME}-targets)
# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
install(DIRECTORY ${SPARROW_INCLUDE_DIR}/sparrow
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set(SPARROW_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_NAME}" CACHE
STRING "install path for sparrowConfig.cmake")
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${SPARROW_CMAKECONFIG_INSTALL_DIR})
# sparrow is header-only and does not depend on the architecture.
# Remove CMAKE_SIZEOF_VOID_P from sparrowConfigVersion.cmake so that an sparrowConfig.cmake
# generated for a 64 bit target can be used for 32 bit targets and vice versa.
set(_SPARROW_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${${PROJECT_NAME}_VERSION}
COMPATIBILITY AnyNewerVersion)
set(CMAKE_SIZEOF_VOID_P ${_SPARROW_CMAKE_SIZEOF_VOID_P})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${SPARROW_CMAKECONFIG_INSTALL_DIR})
install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${SPARROW_CMAKECONFIG_INSTALL_DIR})