File: CMakeLists.txt

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

# this library provides main() for compilers that do not have libfuzzer (everyone except clang)
# so the source code is compiled regardless of compiler, which prevents code rot.
# also, the library provides a way to invoke the fuzzer on external data which is
# useful to run the fuzz corpus through code also when not using clang.
add_library(main STATIC main.cpp)
target_compile_features(main PRIVATE cxx_std_23)

# see if libfuzzer is supported - this gets more complicated than just checking
# for clang, because apple clang does not seem to support it and windows also
# support clang nowadays (and perhaps libfuzzer)

include(CheckSourceCompiles)
set(CMAKE_REQUIRED_LINK_OPTIONS -fsanitize=fuzzer)
check_source_compiles(CXX "
    #include <cstddef>
    #include <cstdint>
    extern \"C\" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
    { return 0;}
    " haslibfuzzer)


macro(create_fuzztest testname)
    add_executable(fuzz_${testname} ${testname}.cpp)
    target_link_libraries(fuzz_${testname} PRIVATE glaze::glaze)

    if(haslibfuzzer)
        target_compile_options(fuzz_${testname} PUBLIC -fsanitize=fuzzer)
        target_link_options(fuzz_${testname} PUBLIC -fsanitize=fuzzer)
    else()
        # supply a separate main
        target_link_libraries(fuzz_${testname} PRIVATE main)
    endif()

    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
        target_compile_options(fuzz_${testname} PUBLIC -fsanitize=address,undefined -fno-sanitize-recover=all )
        target_link_options(fuzz_${testname} PUBLIC -fsanitize=address,undefined -fno-sanitize-recover=all )
    else()
        target_link_libraries(fuzz_${testname} PRIVATE main)
    endif()
endmacro()

create_fuzztest(binary_reflection)
create_fuzztest(cbor_reflection)
create_fuzztest(cbor_roundtrip_floating)
create_fuzztest(cbor_roundtrip_int)
create_fuzztest(cbor_roundtrip_string)
create_fuzztest(msgpack_reflection)
create_fuzztest(msgpack_roundtrip_floating)
create_fuzztest(msgpack_roundtrip_int)
create_fuzztest(msgpack_roundtrip_string)
create_fuzztest(csv_parsing)
create_fuzztest(json_generic)
create_fuzztest(json_jmespath)
create_fuzztest(json_minify)
create_fuzztest(json_prettify)
create_fuzztest(json_reflection)
create_fuzztest(json_roundtrip_floating)
create_fuzztest(json_roundtrip_int)
create_fuzztest(json_roundtrip_string)
create_fuzztest(json_with_comments)

macro(create_exhaustive_test testname)
    add_executable(${testname} ${testname}.cpp)
    target_link_libraries(${testname} PRIVATE glaze::glaze)
    # do not set sanitizers here - CI needs to run as fast as possible,
    # manual running may want sanitizers and debug.
    if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
        #target_compile_options(${testname} PRIVATE -O2)
        #target_compile_options(${testname} PRIVATE -fsanitize=address,undefined  -fno-sanitize-recover=all )
        #target_link_options(${testname} PRIVATE -fsanitize=address,undefined  -fno-sanitize-recover=all )
    endif()
endmacro()

create_exhaustive_test(json_exhaustive_roundtrip_int)
create_exhaustive_test(json_exhaustive_roundtrip_float)