File: CMakeLists.txt

package info (click to toggle)
glaze 7.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,036 kB
  • sloc: cpp: 142,035; sh: 109; ansic: 26; makefile: 12
file content (199 lines) | stat: -rw-r--r-- 7,784 bytes parent folder | download | duplicates (3)
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
include(FetchContent)

find_package(openalgz-ut CONFIG REQUIRED)

# Setup ASIO dependency (used by networking tests)
# This must be defined here before glz_test_common/glz_test_exceptions
#
# Search order:
#   1. Boost.Asio (via find_package(Boost))
#   2. Standalone Asio (via find_package(Asio) using our FindAsio.cmake)
#   3. FetchContent (if glaze_USE_BUNDLED_ASIO is ON)
#
# Distro maintainers can set -Dglaze_USE_BUNDLED_ASIO=OFF to require system packages.

option(glaze_USE_BUNDLED_ASIO
    "Download ASIO via FetchContent if not found on system (disable for distro builds)"
    ON
)

# First, try Boost.Asio
find_package(Boost QUIET CONFIG)

if(Boost_FOUND)
    message(STATUS "Using Boost.Asio")
    add_library(glz_asio INTERFACE)
    # Boost.Asio is header-only, just need Boost headers
    # Boost::system was removed in Boost 1.89 (it was header-only since 1.69)
    if(TARGET Boost::headers)
        target_link_libraries(glz_asio INTERFACE Boost::headers)
    elseif(TARGET Boost::boost)
        target_link_libraries(glz_asio INTERFACE Boost::boost)
    endif()
else()
    # Second, try standalone Asio
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
    find_package(Asio QUIET)

    if(Asio_FOUND)
        message(STATUS "Using standalone Asio ${Asio_VERSION}")
        add_library(glz_asio INTERFACE)
        target_link_libraries(glz_asio INTERFACE Asio::Asio)
    elseif(glaze_USE_BUNDLED_ASIO)
        # Third, fetch via FetchContent
        message(STATUS "Fetching standalone Asio via FetchContent")
        FetchContent_Declare(
            asio
            GIT_REPOSITORY https://github.com/chriskohlhoff/asio.git
            GIT_TAG asio-1-36-0
            GIT_SHALLOW TRUE
        )
        FetchContent_MakeAvailable(asio)
        add_library(glz_asio INTERFACE)
        target_include_directories(glz_asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
    else()
        message(FATAL_ERROR
            "ASIO not found and bundling is disabled (glaze_USE_BUNDLED_ASIO=OFF).\n"
            "Options:\n"
            "  - Install Boost with the 'system' component\n"
            "  - Install standalone Asio (headers in standard location)\n"
            "  - Set Asio_INCLUDE_DIR to your Asio headers location\n"
            "  - Set glaze_USE_BUNDLED_ASIO=ON to download via FetchContent"
        )
    endif()
endif()

include(../cmake/code-coverage.cmake)
add_code_coverage_all_targets()

add_library(glz_test_common INTERFACE)
target_compile_features(glz_test_common INTERFACE cxx_std_23)
target_link_libraries(glz_test_common INTERFACE openalgz-ut::openalgz-ut glaze::glaze glz_asio)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(glz_test_common INTERFACE -fno-exceptions -fno-rtti)
    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
        if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13)
            target_compile_options(glz_test_common INTERFACE -Wall -Wextra -pedantic)
        else()
            target_compile_options(glz_test_common INTERFACE -Wall -Wextra -pedantic $<$<CONFIG:Debug>:-Werror>)
        endif()
    elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        target_compile_options(glz_test_common INTERFACE -Wall -Wextra -pedantic $<$<CONFIG:Debug>:-Werror>)
    else()
        target_compile_options(glz_test_common INTERFACE -Wall -Wextra -pedantic)
    endif()

        if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
      target_compile_options(glz_test_common INTERFACE -ftime-trace -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
      target_link_options(glz_test_common INTERFACE -ftime-trace -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined)
    endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    target_compile_options(glz_test_common INTERFACE /GR- /bigobj) #/fsanitize=address
    target_compile_options(glz_test_common INTERFACE /W4 /wd4459 /wd4805)
endif()

add_library(glz_test_exceptions INTERFACE)
target_compile_features(glz_test_exceptions INTERFACE cxx_std_23)
target_link_libraries(glz_test_exceptions INTERFACE openalgz-ut::openalgz-ut glaze::glaze glz_asio)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(glz_test_exceptions INTERFACE)
    target_compile_options(glz_test_exceptions INTERFACE -Wall -Wextra -pedantic)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    target_compile_options(glz_test_exceptions INTERFACE /GR- /bigobj) #/fsanitize=address
    target_compile_options(glz_test_exceptions INTERFACE /W4 /wd4459 /wd4805)
endif()

add_subdirectory(api_test)
add_subdirectory(beve_test)
add_subdirectory(cbor_test)
add_subdirectory(buffer_pool_test)
add_subdirectory(cli_menu_test)
add_subdirectory(compare_test)
add_subdirectory(csv_test)
add_subdirectory(eigen_test)
add_subdirectory(example_json)
add_subdirectory(exceptions_test)
add_subdirectory(inplace_vector)
option(glaze_BUILD_PERFORMANCE_TESTS "Build performance tests" ON)
if(glaze_BUILD_PERFORMANCE_TESTS)
    add_subdirectory(int_parsing)
endif()
add_subdirectory(jmespath)
add_subdirectory(jsonrpc_test)
add_subdirectory(key_transformers_test)
add_subdirectory(lib_test)
add_subdirectory(mock_json_test)
add_subdirectory(reflection)
add_subdirectory(roundtrip)
add_subdirectory(stencil)
add_subdirectory(threading_test)
add_subdirectory(toml_test)
add_subdirectory(utility_formats)
add_subdirectory(yaml_test)
add_subdirectory(msgpack_test)
add_subdirectory(ostream_buffer_test)
add_subdirectory(istream_buffer_test)

# simple_float_test runs exhaustive tests over all 2^32 float values
# Disabled by default - run via dedicated CI workflow in Release mode
option(glaze_SIMPLE_FLOAT_TEST "Build simple_float exhaustive tests (slow, Release mode recommended)" OFF)
if(glaze_SIMPLE_FLOAT_TEST)
    add_subdirectory(simple_float_test)
endif()

# JSON Tests
add_subdirectory(chrono_test)
add_subdirectory(json_conformance)
if(glaze_BUILD_PERFORMANCE_TESTS)
    add_subdirectory(json_performance)
endif()
add_subdirectory(json_reflection_test)
add_subdirectory(json_test)

option(glaze_BUILD_NETWORKING_TESTS "Build networking tests (requires OpenSSL)" ON)
if(glaze_BUILD_NETWORKING_TESTS)
    add_subdirectory(networking_tests)
endif()

if(glaze_EETF_FORMAT)
    add_subdirectory(eetf_test)
endif(glaze_EETF_FORMAT)

# We don't run find_package_test or glaze-install_test with MSVC/Windows, because the Github action runner often chokes
# Don't run find_package on Clang, because Linux runs with Clang try to use GCC standard library and have errors before Clang 18
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
    add_test(
    NAME glaze-install_test
    COMMAND
    "${CMAKE_COMMAND}"
    --install "${PROJECT_BINARY_DIR}"
    --prefix "${CMAKE_CURRENT_BINARY_DIR}/install"
    --config $<CONFIG>
    --verbose
    )

    add_test(
    NAME find_package_test
    COMMAND
    "${CMAKE_CTEST_COMMAND}"
    --verbose
    --output-on-failure
    --build-noclean
    --build-project "${PROJECT_NAME}" # helps msvc when --build-target
    --build-generator "${CMAKE_GENERATOR}"
    --build-config $<CONFIG>
    --build-and-test
    "${CMAKE_CURRENT_SOURCE_DIR}/find_package"
    "${CMAKE_CURRENT_BINARY_DIR}/find_package"
    --build-options
    "-Dglaze_ROOT:PATH=${CMAKE_CURRENT_BINARY_DIR}/install"
    "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
    "-DBUILD_TESTING=ON"
    "$<$<BOOL:${glaze_EETF_FORMAT}>:-Dglaze_EETF_FORMAT=ON>"
    "$<$<BOOL:${glaze_EETF_FORMAT}>:-DEXTERNAL_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake>"
    --test-command "${CMAKE_CTEST_COMMAND}" --verbose --output-on-failure # inner ctest command
    )

    set_tests_properties(glaze-install_test PROPERTIES FIXTURES_SETUP glaze-install-fixture)
    set_tests_properties(find_package_test PROPERTIES FIXTURES_REQUIRED glaze-install-fixture)
endif()