|
6 | 6 |
|
7 | 7 | cmake_minimum_required(VERSION 3.12) |
8 | 8 |
|
9 | | -option(JAM_COMPATIBLE "Build compatible with JAM-codec" OFF) |
10 | | -option(CUSTOM_CONFIG_SUPPORT "Support custom config of coder" OFF) |
11 | | -option(BUILD_TESTS "Whether to include the test suite in build" OFF) |
| 9 | +# Select package manager |
| 10 | +if(PACKAGE_MANAGER) |
| 11 | + if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$") |
| 12 | + message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") |
| 13 | + endif() |
| 14 | +else() |
| 15 | + set(PACKAGE_MANAGER "hunter") |
| 16 | + if(CMAKE_TOOLCHAIN_FILE) |
| 17 | + get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) |
| 18 | + if(ACTUAL_NAME STREQUAL "vcpkg.cmake") |
| 19 | + message(STATUS "vcpkg will be used because vcpkg.cmake has found") |
| 20 | + set(PACKAGE_MANAGER "vcpkg") |
| 21 | + endif() |
| 22 | + endif() |
| 23 | +endif() |
| 24 | +message(STATUS "Selected package manager: ${PACKAGE_MANAGER}") |
12 | 25 |
|
13 | | -option(SCALE_ASAN "Build with address sanitizer" OFF) |
14 | | -option(SCALE_UBSAN "Build with undefined behavior sanitizer" OFF) |
15 | | -option(SCALE_TSAN "Build with thread sanitizer" OFF) |
| 26 | +# Default values of options |
| 27 | +set(JAM_COMPATIBLE_DEFAULT OFF) |
| 28 | +set(CUSTOM_CONFIG_SUPPORT_DEFAULT OFF) |
| 29 | +set(BUILD_TESTS_DEFAULT OFF) |
| 30 | +set(ASAN_DEFAULT OFF) |
| 31 | +set(TSAN_DEFAULT OFF) |
| 32 | +set(UBSAN_DEFAULT OFF) |
| 33 | + |
| 34 | +# Adjust value by vcpkg manifest if any |
| 35 | +if(PACKAGE_MANAGER STREQUAL "vcpkg") |
| 36 | + if("jam-compatibility" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 37 | + set(JAM_COMPATIBLE_DEFAULT ON) |
| 38 | + endif() |
| 39 | + if("configurable-coding" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 40 | + set(CUSTOM_CONFIG_SUPPORT_DEFAULT ON) |
| 41 | + endif() |
| 42 | + if("scale-tests" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 43 | + set(BUILD_TESTS_DEFAULT ON) |
| 44 | + endif() |
| 45 | + if("asan" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 46 | + set(ASAN_DEFAULT ON) |
| 47 | + endif() |
| 48 | + if("tsan" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 49 | + set(TSAN_DEFAULT ON) |
| 50 | + endif() |
| 51 | + if("ubsan" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 52 | + set(UBSAN_DEFAULT ON) |
| 53 | + endif() |
| 54 | +endif() |
16 | 55 |
|
17 | | -set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation") |
| 56 | +# Init options |
| 57 | +option(JAM_COMPATIBLE "Build compatible with JAM-codec" ${JAM_COMPATIBLE_DEFAULT}) |
| 58 | +option(CUSTOM_CONFIG_SUPPORT "Support custom config of coder" ${CUSTOM_CONFIG_SUPPORT_DEFAULT}) |
| 59 | +option(BUILD_TESTS "Whether to include the test suite in build" ${BUILD_TESTS_DEFAULT}) |
| 60 | +option(ASAN "Build tests with address sanitizer" ${ASAN_DEFAUL}) |
| 61 | +option(TSAN "Build tests with thread sanitizer" ${TSAN_DEFAUL}) |
| 62 | +option(UBSAN "Build tests with undefined behavior sanitizer" ${UBSAN_DEFAUL}) |
| 63 | +if(ASAN OR TSAN OR UBSAN) |
| 64 | + if(NOT BUILD_TESTS) |
| 65 | + message(FATAL_ERROR "Sanitizer required but build of test is not set") |
| 66 | + endif() |
| 67 | +endif() |
18 | 68 |
|
19 | | -if (PACKAGE_MANAGER) |
20 | | - if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$") |
21 | | - message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") |
22 | | - endif () |
23 | | -else () |
24 | | - set(PACKAGE_MANAGER "hunter") |
25 | | - if (CMAKE_TOOLCHAIN_FILE) |
26 | | - get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) |
27 | | - if(ACTUAL_NAME STREQUAL "vcpkg.cmake") |
28 | | - message(STATUS "vcpkg will be used because vcpkg.cmake has found") |
29 | | - set(PACKAGE_MANAGER "vcpkg") |
30 | | - endif () |
31 | | - endif () |
32 | | -endif () |
33 | | -message(STATUS "Selected package manager: ${PACKAGE_MANAGER}") |
| 69 | +# Adjust vcpkg features by custom defined option (for deploy possible dependencies) |
| 70 | +if(PACKAGE_MANAGER STREQUAL "vcpkg") |
| 71 | + if(BUILD_TESTS AND NOT "scale-tests" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 72 | + list(APPEND VCPKG_MANIFEST_FEATURES "scale-tests") |
| 73 | + endif() |
| 74 | +endif() |
34 | 75 |
|
35 | | -if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") |
36 | | - cmake_policy(SET CMP0144 NEW) |
37 | | -endif () |
| 76 | +set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation") |
38 | 77 |
|
39 | | -if (PACKAGE_MANAGER STREQUAL "hunter") |
40 | | - include("cmake/Hunter/init.cmake") |
41 | | -endif () |
| 78 | +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") |
| 79 | + cmake_policy(SET CMP0144 NEW) |
| 80 | +endif() |
42 | 81 |
|
43 | | -if(BUILD_TESTS) |
44 | | - if (PACKAGE_MANAGER STREQUAL "vcpkg") |
45 | | - list(APPEND VCPKG_MANIFEST_FEATURES scale-tests) |
46 | | - endif() |
| 82 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 83 | + include("cmake/Hunter/init.cmake") |
| 84 | +else() |
| 85 | + set(HUNTER_ENABLED OFF) |
47 | 86 | endif() |
48 | 87 |
|
49 | | -project(Scale LANGUAGES CXX VERSION 2.0.0) |
| 88 | +project(Scale LANGUAGES CXX VERSION 2.0.1) |
50 | 89 |
|
51 | 90 | set(CMAKE_CXX_STANDARD 20) |
52 | 91 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
53 | 92 | set(CMAKE_CXX_EXTENSIONS OFF) |
54 | 93 |
|
55 | 94 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
56 | 95 |
|
57 | | -if (PACKAGE_MANAGER STREQUAL "hunter") |
58 | | - hunter_add_package(Boost) |
59 | | - find_package(Boost) |
| 96 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 97 | + hunter_add_package(Boost) |
| 98 | + find_package(Boost) |
60 | 99 | else() |
61 | | - find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision) |
62 | | -endif () |
| 100 | + find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision) |
| 101 | +endif() |
63 | 102 |
|
64 | | -if (PACKAGE_MANAGER STREQUAL "hunter") |
65 | | - hunter_add_package(qtils) |
66 | | -endif () |
| 103 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 104 | + hunter_add_package(qtils) |
| 105 | +endif() |
67 | 106 | find_package(qtils CONFIG REQUIRED) |
68 | 107 |
|
69 | | -SET(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}") |
| 108 | +set(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}") |
70 | 109 | set(CUSTOM_CONFIG_ENABLED "${CUSTOM_CONFIG_SUPPORT}") |
71 | 110 | configure_file("${CMAKE_SOURCE_DIR}/include/scale/definitions.hpp.in" "${CMAKE_BINARY_DIR}/include/scale/definitions.hpp") |
72 | 111 |
|
73 | | -if (SCALE_ASAN) |
74 | | - add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
75 | | - add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
| 112 | +if(ASAN) |
| 113 | + message(STATUS "Address sanitizer will be used") |
| 114 | + add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
| 115 | + add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
76 | 116 | endif() |
77 | | -if (SCALE_UBSAN) |
78 | | - add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) |
79 | | - add_link_options(-fsanitize=undefined -fno-omit-frame-pointer) |
| 117 | +if(TSAN) |
| 118 | + message(STATUS "Thread sanitizer will be used") |
| 119 | + add_compile_options(-fsanitize=thread -fno-omit-frame-pointer) |
| 120 | + add_link_options(-fsanitize=thread -fno-omit-frame-pointer) |
80 | 121 | endif() |
81 | | -if (SCALE_TSAN) |
82 | | - add_compile_options(-fsanitize=thread -fno-omit-frame-pointer) |
83 | | - add_link_options(-fsanitize=thread -fno-omit-frame-pointer) |
| 122 | +if(UBSAN) |
| 123 | + message(STATUS "Undefined behavior sanitizer will be used") |
| 124 | + add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) |
| 125 | + add_link_options(-fsanitize=undefined -fno-omit-frame-pointer) |
84 | 126 | endif() |
85 | 127 |
|
86 | 128 | add_subdirectory(src) |
87 | 129 |
|
88 | | -if (BUILD_TESTS) |
89 | | - enable_testing() |
90 | | - add_subdirectory(test ${CMAKE_BINARY_DIR}/test_bin) |
91 | | -endif () |
| 130 | +if(BUILD_TESTS) |
| 131 | + enable_testing() |
| 132 | + add_subdirectory(test ${CMAKE_BINARY_DIR}/test_bin) |
| 133 | +endif() |
92 | 134 |
|
93 | 135 | ############################################################################### |
94 | 136 | # INSTALLATION |
95 | 137 | ############################################################################### |
96 | 138 |
|
97 | 139 | include(GNUInstallDirs) |
98 | 140 |
|
99 | | -install(TARGETS scale EXPORT scaleConfig |
| 141 | +install( |
| 142 | + TARGETS scale EXPORT scaleConfig |
100 | 143 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
101 | 144 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
102 | 145 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
|
0 commit comments