forked from Harrm/scale-codec
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
161 lines (134 loc) · 4.89 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
#
# Copyright Quadrivium LLC
# All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required(VERSION 3.12)
# Select package manager
if(PACKAGE_MANAGER)
if(NOT PACKAGE_MANAGER MATCHES "^(hunter|vcpkg)$")
message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set")
endif()
else()
set(PACKAGE_MANAGER "hunter")
if(CMAKE_TOOLCHAIN_FILE)
get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME)
if(ACTUAL_NAME STREQUAL "vcpkg.cmake")
message(STATUS "vcpkg will be used because vcpkg.cmake has found")
set(PACKAGE_MANAGER "vcpkg")
endif()
endif()
endif()
message(STATUS "Selected package manager: ${PACKAGE_MANAGER}")
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
# find_package() uses upper-case <PACKAGENAME>_ROOT variables.
cmake_policy(SET CMP0144 NEW)
endif()
if(PACKAGE_MANAGER STREQUAL "hunter")
include("cmake/Hunter/init.cmake")
else()
set(HUNTER_ENABLED OFF)
endif()
# Adjust vcpkg features by custom defined option (for deploy possible dependencies)
if(PACKAGE_MANAGER STREQUAL "vcpkg")
if(BUILD_TESTS AND NOT "scale-tests" IN_LIST VCPKG_MANIFEST_FEATURES)
list(APPEND VCPKG_MANIFEST_FEATURES "scale-tests")
endif()
endif()
project(Scale LANGUAGES CXX VERSION 2.0.1)
include(cmake/feature_option.cmake)
# Init options
feature_option(JAM_COMPATIBLE "jam-compatibility" "Build compatible with JAM-codec" OFF)
feature_option(CUSTOM_CONFIG_SUPPORT "configurable-coding" "Support custom config of coder" OFF)
feature_option(BUILD_TESTS "scale-tests" "Whether to include the test suite in build" OFF)
option(ASAN "Build tests with address sanitizer" OFF)
option(TSAN "Build tests with thread sanitizer" OFF)
option(UBSAN "Build tests with undefined behavior sanitizer" OFF)
if((ASAN OR TSAN OR UBSAN) AND NOT BUILD_TESTS)
message(FATAL_ERROR "Since SCALE is header-only, sanitizers should only be enabled for tests")
endif()
set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(PACKAGE_MANAGER STREQUAL "hunter")
hunter_add_package(Boost)
find_package(Boost)
else()
find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision)
endif()
if(PACKAGE_MANAGER STREQUAL "hunter")
hunter_add_package(qtils)
endif()
find_package(qtils CONFIG REQUIRED)
set(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}")
set(CUSTOM_CONFIG_ENABLED "${CUSTOM_CONFIG_SUPPORT}")
configure_file("${CMAKE_SOURCE_DIR}/include/scale/definitions.hpp.in" "${CMAKE_BINARY_DIR}/include/scale/definitions.hpp")
if(ASAN)
message(STATUS "Address sanitizer will be used")
add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer)
add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer)
endif()
if(TSAN)
message(STATUS "Thread sanitizer will be used")
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
add_link_options(-fsanitize=thread -fno-omit-frame-pointer)
endif()
if(UBSAN)
message(STATUS "Undefined behavior sanitizer will be used")
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
add_link_options(-fsanitize=undefined -fno-omit-frame-pointer)
endif()
include(cmake/generate_decompose_and_apply.cmake)
add_library(scale INTERFACE
${DECOMPOSE_AND_APPLY_HPP}
)
target_include_directories(scale PUBLIC INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(scale INTERFACE
Boost::boost
)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(test ${CMAKE_BINARY_DIR}/test_bin)
endif()
###############################################################################
# INSTALLATION
###############################################################################
include(GNUInstallDirs)
install(
TARGETS scale EXPORT scaleConfig
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/scale
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
install(
DIRECTORY ${CMAKE_BINARY_DIR}/include/scale
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/scaleConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/scaleConfigVersion.cmake
DESTINATION share/scale
)
install(
EXPORT scaleConfig
DESTINATION share/scale
NAMESPACE scale::
)