|
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 |
| -set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation") |
12 |
| - |
13 |
| -option(BUILD_TESTS "Whether to include the test suite in build" OFF) |
14 |
| - |
15 |
| -if (PACKAGE_MANAGER) |
16 |
| - if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$") |
17 |
| - message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") |
18 |
| - endif () |
19 |
| -else () |
20 |
| - set(PACKAGE_MANAGER "hunter") |
21 |
| - if (CMAKE_TOOLCHAIN_FILE) |
22 |
| - get_filename_component(ACTUAL_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) |
23 |
| - if(ACTUAL_NAME STREQUAL "vcpkg.cmake") |
24 |
| - message(STATUS "vcpkg will be used because vcpkg.cmake has found") |
25 |
| - set(PACKAGE_MANAGER "vcpkg") |
26 |
| - endif () |
27 |
| - endif () |
28 |
| -endif () |
| 9 | +# Select package manager |
| 10 | +if(PACKAGE_MANAGER) |
| 11 | + if(NOT PACKAGE_MANAGER 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() |
29 | 24 | message(STATUS "Selected package manager: ${PACKAGE_MANAGER}")
|
30 | 25 |
|
31 |
| -if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") |
| 26 | +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") |
| 27 | + # find_package() uses upper-case <PACKAGENAME>_ROOT variables. |
32 | 28 | cmake_policy(SET CMP0144 NEW)
|
33 |
| -endif () |
| 29 | +endif() |
34 | 30 |
|
35 |
| -if (PACKAGE_MANAGER STREQUAL "hunter") |
36 |
| - include("cmake/Hunter/init.cmake") |
37 |
| -endif () |
| 31 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 32 | + include("cmake/Hunter/init.cmake") |
| 33 | +else() |
| 34 | + set(HUNTER_ENABLED OFF) |
| 35 | +endif() |
38 | 36 |
|
39 |
| -if(BUILD_TESTS) |
40 |
| - if (PACKAGE_MANAGER STREQUAL "vcpkg") |
41 |
| - list(APPEND VCPKG_MANIFEST_FEATURES scale-tests) |
42 |
| - endif() |
| 37 | +# Adjust vcpkg features by custom defined option (for deploy possible dependencies) |
| 38 | +if(PACKAGE_MANAGER STREQUAL "vcpkg") |
| 39 | + if(BUILD_TESTS AND NOT "scale-tests" IN_LIST VCPKG_MANIFEST_FEATURES) |
| 40 | + list(APPEND VCPKG_MANIFEST_FEATURES "scale-tests") |
| 41 | + endif() |
43 | 42 | endif()
|
44 | 43 |
|
45 |
| -project(Scale LANGUAGES CXX VERSION 2.0.0) |
| 44 | +project(Scale LANGUAGES CXX VERSION 2.0.1) |
| 45 | + |
| 46 | +include(cmake/feature_option.cmake) |
| 47 | + |
| 48 | +# Init options |
| 49 | +feature_option(JAM_COMPATIBLE "jam-compatibility" "Build compatible with JAM-codec" OFF) |
| 50 | +feature_option(CUSTOM_CONFIG_SUPPORT "configurable-coding" "Support custom config of coder" OFF) |
| 51 | +feature_option(BUILD_TESTS "scale-tests" "Whether to include the test suite in build" OFF) |
| 52 | +option(ASAN "Build tests with address sanitizer" OFF) |
| 53 | +option(TSAN "Build tests with thread sanitizer" OFF) |
| 54 | +option(UBSAN "Build tests with undefined behavior sanitizer" OFF) |
| 55 | + |
| 56 | +if((ASAN OR TSAN OR UBSAN) AND NOT BUILD_TESTS) |
| 57 | + message(FATAL_ERROR "Since SCALE is header-only, sanitizers should only be enabled for tests") |
| 58 | +endif() |
| 59 | + |
| 60 | +set(MAX_AGGREGATE_FIELDS 20 CACHE STRING "Max number of aggregates fields (1..1000); for generation") |
46 | 61 |
|
47 | 62 | set(CMAKE_CXX_STANDARD 20)
|
48 | 63 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
49 | 64 | set(CMAKE_CXX_EXTENSIONS OFF)
|
50 | 65 |
|
51 | 66 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
52 | 67 |
|
53 |
| -if (PACKAGE_MANAGER STREQUAL "hunter") |
54 |
| - hunter_add_package(Boost) |
55 |
| - find_package(Boost) |
| 68 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 69 | + hunter_add_package(Boost) |
| 70 | + find_package(Boost) |
56 | 71 | else()
|
57 |
| - find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision) |
58 |
| -endif () |
| 72 | + find_package(Boost CONFIG REQUIRED COMPONENTS endian multiprecision) |
| 73 | +endif() |
59 | 74 |
|
60 |
| -if (PACKAGE_MANAGER STREQUAL "hunter") |
61 |
| - hunter_add_package(qtils) |
62 |
| -endif () |
| 75 | +if(PACKAGE_MANAGER STREQUAL "hunter") |
| 76 | + hunter_add_package(qtils) |
| 77 | +endif() |
63 | 78 | find_package(qtils CONFIG REQUIRED)
|
64 | 79 |
|
65 |
| -SET(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}") |
| 80 | +set(JAM_COMPATIBILITY_ENABLED "${JAM_COMPATIBLE}") |
66 | 81 | set(CUSTOM_CONFIG_ENABLED "${CUSTOM_CONFIG_SUPPORT}")
|
67 | 82 | configure_file("${CMAKE_SOURCE_DIR}/include/scale/definitions.hpp.in" "${CMAKE_BINARY_DIR}/include/scale/definitions.hpp")
|
68 | 83 |
|
69 |
| -add_subdirectory(src) |
| 84 | +if(ASAN) |
| 85 | + message(STATUS "Address sanitizer will be used") |
| 86 | + add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
| 87 | + add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer) |
| 88 | +endif() |
| 89 | +if(TSAN) |
| 90 | + message(STATUS "Thread sanitizer will be used") |
| 91 | + add_compile_options(-fsanitize=thread -fno-omit-frame-pointer) |
| 92 | + add_link_options(-fsanitize=thread -fno-omit-frame-pointer) |
| 93 | +endif() |
| 94 | +if(UBSAN) |
| 95 | + message(STATUS "Undefined behavior sanitizer will be used") |
| 96 | + add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) |
| 97 | + add_link_options(-fsanitize=undefined -fno-omit-frame-pointer) |
| 98 | +endif() |
| 99 | + |
| 100 | +include(cmake/generate_decompose_and_apply.cmake) |
70 | 101 |
|
71 |
| -if (BUILD_TESTS) |
72 |
| - enable_testing() |
73 |
| - add_subdirectory(test ${CMAKE_BINARY_DIR}/test_bin) |
74 |
| -endif () |
| 102 | +add_library(scale INTERFACE |
| 103 | + ${DECOMPOSE_AND_APPLY_HPP} |
| 104 | +) |
| 105 | +target_include_directories(scale PUBLIC INTERFACE |
| 106 | + $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include> |
| 107 | + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> |
| 108 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 109 | +) |
| 110 | +target_link_libraries(scale INTERFACE |
| 111 | + Boost::boost |
| 112 | +) |
| 113 | + |
| 114 | +if(BUILD_TESTS) |
| 115 | + enable_testing() |
| 116 | + add_subdirectory(test ${CMAKE_BINARY_DIR}/test_bin) |
| 117 | +endif() |
75 | 118 |
|
76 | 119 | ###############################################################################
|
77 | 120 | # INSTALLATION
|
78 | 121 | ###############################################################################
|
79 | 122 |
|
80 | 123 | include(GNUInstallDirs)
|
81 | 124 |
|
82 |
| -install(TARGETS scale EXPORT scaleConfig |
83 |
| - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
84 |
| - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
85 |
| - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
86 |
| - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
87 |
| - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
88 |
| - FRAMEWORK DESTINATION ${CMAKE_INSTALL_PREFIX} |
89 |
| -) |
90 |
| - |
91 |
| -install(TARGETS scale_append EXPORT scaleConfig |
| 125 | +install( |
| 126 | + TARGETS scale EXPORT scaleConfig |
92 | 127 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
93 | 128 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
94 | 129 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
0 commit comments