From 09cf18a64610100f29889fd51469fd5168cc2225 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 9 Apr 2020 17:31:35 -0700 Subject: [PATCH] Add C++11 tests to cmake - Add simdjson-flags target so callers don't have flags forced on them --- .appveyor.yml | 2 +- CMakeLists.txt | 105 +++++++++++++++++----- benchmark/CMakeLists.txt | 4 +- examples/quickstart/CMakeLists.txt | 56 ++++++++++-- fuzz/CMakeLists.txt | 2 +- include/CMakeLists.txt | 69 ++------------- include/simdjson/common_defs.h | 3 +- src/CMakeLists.txt | 38 +++++--- tests/CMakeLists.txt | 116 ++++++++++++++----------- tests/readme_examples.cpp | 4 +- tests/readme_examples_noexceptions.cpp | 4 +- tools/CMakeLists.txt | 3 +- 12 files changed, 244 insertions(+), 162 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 59299e7d..a4f30cc5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,7 +20,7 @@ build_script: - mkdir build - cd build - cmake -DSIMDJSON_BUILD_STATIC=%SIMDJSON_BUILD_STATIC% -DSIMDJSON_ENABLE_THREADS=%SIMDJSON_ENABLE_THREADS% -DCMAKE_BUILD_TYPE=%Configuration% -DCMAKE_GENERATOR_PLATFORM=x64 -DSIMDJSON_GOOGLE_BENCHMARKS=OFF .. - - cmake --build . --config %Configuration% + - cmake --verbose --build . --config %Configuration% test_script: - ctest --verbose --output-on-failure -C %Configuration% diff --git a/CMakeLists.txt b/CMakeLists.txt index 256bcf4d..5c292cbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,20 +12,6 @@ project(simdjson LANGUAGES CXX C ) -# LTO seems to create all sorts of fun problems. Let us -# disable temporarily. -#include(CheckIPOSupported) -#check_ipo_supported(RESULT ltoresult) -#if(ltoresult) -# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) -#endif() - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_MACOSX_RPATH OFF) -set(CMAKE_THREAD_PREFER_PTHREAD ON) -set(THREADS_PREFER_PTHREAD_FLAG ON) - set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 3) set(PROJECT_VERSION_PATCH 1) @@ -34,7 +20,7 @@ set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion") if(MSVC) option(SIMDJSON_BUILD_STATIC "Build a static library" ON) # turning it on disables the production of a dynamic library - option(SIMDJSON_COMPETITION "Compile competitive benchmarks" OFF) + set(SIMDJSON_COMPETITION CACHE STRING "Compile competitive benchmarks" OFF) else() option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON) @@ -43,11 +29,85 @@ option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake") +# We compile tools, tests, etc. with C++ 17. Override yourself if you need on a target. +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_MACOSX_RPATH OFF) +set(CMAKE_THREAD_PREFER_PTHREAD ON) +set(THREADS_PREFER_PTHREAD_FLAG ON) + +# LTO seems to create all sorts of fun problems. Let us +# disable temporarily. +#include(CheckIPOSupported) +#check_ipo_supported(RESULT ltoresult) +#if(ltoresult) +# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +#endif() + +# +# Flags used by exes and by the simdjson library (project-wide flags) +# +add_library(simdjson-flags INTERFACE) +if(MSVC) + target_compile_options(simdjson-flags INTERFACE /nologo /D_CRT_SECURE_NO_WARNINGS) + target_compile_options(simdjson-flags INTERFACE /W3 /wd4005 /wd4996 /wd4267 /wd4244 /wd4113) +else() + target_compile_options(simdjson-flags INTERFACE -fPIC) + target_compile_options(simdjson-flags INTERFACE -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self) +endif() + +# Optional flags +option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON) +if(NOT SIMDJSON_IMPLEMENTATION_HASWELL) + target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_HASWELL=0) +endif() +option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON) +if(NOT SIMDJSON_IMPLEMENTATION_WESTMERE) + target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_WESTMERE=0) +endif() +option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON) +if(NOT SIMDJSON_IMPLEMENTATION_ARM64) + target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_ARM64=0) +endif() +option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON) +if(NOT SIMDJSON_IMPLEMENTATION_FALLBACK) + target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_IMPLEMENTATION_FALLBACK=0) +endif() + +option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON) +if(NOT SIMDJSON_EXCEPTIONS) + message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.") + target_compile_definitions(simdjson-flags INTERFACE SIMDJSON_EXCEPTIONS=0) +endif() + +option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON) +if(SIMDJSON_ENABLE_THREADS) + find_package(Threads REQUIRED) + target_link_libraries(simdjson-flags INTERFACE Threads::Threads) +endif() + +option(SIMDJSON_SANITIZE "Sanitize addresses" OFF) +if(SIMDJSON_SANITIZE) + # Not sure which + target_compile_options(simdjson-flags INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + target_link_libraries(simdjson-flags INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) + + # Ubuntu bug for GCC 5.0+ (safe for all versions) + if (CMAKE_COMPILER_IS_GNUCC) + target_link_libraries(simdjson-flags INTERFACE -fuse-ld=gold) + endif() +endif() + +# prevent shared libraries from depending on Intel provided libraries +if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel") +endif() + # # Create the top level simdjson library (must be done at this level to use both src/ and include/ # directories) # -add_subdirectory(windows) add_subdirectory(include) add_subdirectory(src) @@ -60,10 +120,11 @@ add_library(test-data INTERFACE) target_compile_definitions(test-data INTERFACE SIMDJSON_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/") target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/") +add_subdirectory(windows) add_subdirectory(dependencies) -add_subdirectory(tools) add_subdirectory(tests) add_subdirectory(examples) +add_subdirectory(tools) add_subdirectory(benchmark) # for fuzzing, read the comments in the fuzz/CMakeLists.txt file @@ -72,11 +133,9 @@ if(ENABLE_FUZZING) add_subdirectory(fuzz) endif() -if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc - # prevent shared libraries from depending on Intel provided libraries - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel") -endif() - +# +# CPack +# set(CPACK_PACKAGE_VENDOR "Daniel Lemire") set(CPACK_PACKAGE_CONTACT "lemire@gmail.com") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Parsing gigabytes of JSON per second") @@ -91,5 +150,3 @@ set(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_SOURCE_GENERATOR "TGZ;ZIP") include(CPack) - - diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 523f0773..93e59484 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories( . linux ) -link_libraries(simdjson) -# add_executable(benchfeatures benchfeatures.cpp) +link_libraries(simdjson simdjson-flags) +# add_executable(benchfeatures benchfeatures.cpp) # doesn't presently compile at all add_executable(get_corpus_benchmark get_corpus_benchmark.cpp) add_executable(perfdiff perfdiff.cpp) add_executable(parse parse.cpp) diff --git a/examples/quickstart/CMakeLists.txt b/examples/quickstart/CMakeLists.txt index ced2aa31..edf3a054 100644 --- a/examples/quickstart/CMakeLists.txt +++ b/examples/quickstart/CMakeLists.txt @@ -1,6 +1,52 @@ -if(SIMDJSON_EXCEPTIONS) - add_executable(quickstart quickstart.cpp) - target_link_libraries(quickstart PRIVATE simdjson) +# +# Quickstart compile tests don't require any flags +# + +# TODO run amalgamate first! + +function(add_quickstart_test TEST_NAME SOURCE_FILE) + # Second argument is C++ standard name + if (${ARGV2}) + if (MSVC) + set(QUICKSTART_FLAGS /std:${ARGV2}) + else() + set(QUICKSTART_FLAGS -Werror -std=${ARGV2}) + endif() + else() + if(MSVC) + set(QUICKSTART_FLAGS "") + else() + set(QUICKSTART_FLAGS -Werror) + endif() + endif() + + # Third argument tells whether to compile with -fno-exceptions + if (${ARGV3}) + if (NOT MSVC) + set(QUICKSTART_FLAGS "${QUICKSTART_FLAGS} -fno-exceptions") + endif() + endif() + + add_test( + NAME ${TEST_NAME} + COMMAND ${CMAKE_CXX_COMPILER} ${QUICKSTART_FLAGS} -I${PROJECT_SOURCE_DIR}/include -I${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/simdjson.cpp ${SOURCE_FILE} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/examples/quickstart + ) + set_property( + TEST ${TEST_NAME} + APPEND PROPERTY DEPENDS simdjson-source ${PROJECT_SOURCE_DIR}/examples/quickstart/quickstart.cpp + ) +endfunction(add_quickstart_test) + +if (SIMDJSON_EXCEPTIONS) + add_quickstart_test(quickstart quickstart.cpp) + add_quickstart_test(quickstart11 quickstart.cpp c++11) + add_quickstart_test(quickstart14 quickstart.cpp c++14) + set_property( TEST quickstart quickstart11 APPEND PROPERTY LABELS quicktests ) + set_property( TEST quickstart14 APPEND PROPERTY LABELS slowtests ) endif() -add_executable(quickstart_noexceptions quickstart_noexceptions.cpp) -target_link_libraries(quickstart_noexceptions PRIVATE simdjson) + +add_quickstart_test(quickstart_noexceptions quickstart_noexceptions.cpp "" true) +add_quickstart_test(quickstart_noexceptions11 quickstart_noexceptions.cpp c++11 true) +set_property( TEST quickstart_noxceptions APPEND PROPERTY LABELS quicktests ) +set_property( TEST quickstart_noexceptions11 APPEND PROPERTY LABELS slowtests ) diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index c0b36c8a..d0606ec7 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -44,7 +44,7 @@ macro(implement_fuzzer sourcefile) if (SIMDJSON_FUZZ_LINKMAIN) target_sources(${name} PRIVATE main.cpp) endif () - target_link_libraries(${name} PRIVATE simdjson) + target_link_libraries(${name} PRIVATE simdjson simdjson-flags) if (SIMDJSON_FUZZ_LDFLAGS) target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS}) endif () diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7c10d422..0b44920b 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,68 +1,15 @@ # -# simdjson headers and flags required to compile them +# Provides the simdjson headers. +# +# target_link_libraries(my-project simdjson-headers) grants the headers. It does not provide the +# source, libraries or any compiler flags. # - add_library(simdjson-headers INTERFACE) - -# Include directory +target_compile_features(simdjson-headers INTERFACE cxx_std_11) # headers require at least C++11 target_include_directories(simdjson-headers INTERFACE - $ - $) - -# Flags absolutely needed to compile simdjson at all -target_compile_features(simdjson-headers INTERFACE cxx_std_17) -if(MSVC) # Windows - # C++ standard flags - target_compile_options(simdjson-headers INTERFACE /std:c++17) - # Base flags - target_compile_options(simdjson-headers INTERFACE /nologo) - # Warning flags - target_compile_options(simdjson-headers INTERFACE /W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /wd4267 /wd4244 /wd4113) -else() # Linux - # Base flags - target_compile_options(simdjson-headers INTERFACE -fPIC) - # C++ standard flags - target_compile_options(simdjson-headers INTERFACE -std=c++17) - # Warning flags - target_compile_options(simdjson-headers INTERFACE -Wall -Wextra -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self) - # Debug and release specific flags - target_compile_options(simdjson-headers INTERFACE $<$:-ggdb>) - target_compile_options(simdjson-headers INTERFACE $<$:-O3 -DNDEBUG>) -endif() - - -# Optional flags -option(SIMDJSON_IMPLEMENTATION_HASWELL "Include the haswell implementation" ON) -option(SIMDJSON_IMPLEMENTATION_WESTMERE "Include the westmere implementation" ON) -option(SIMDJSON_IMPLEMENTATION_ARM64 "Include the arm64 implementation" ON) -option(SIMDJSON_IMPLEMENTATION_FALLBACK "Include the fallback implementation" ON) - -option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON) -if(NOT SIMDJSON_EXCEPTIONS) - message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.") - target_compile_definitions(simdjson-headers INTERFACE SIMDJSON_EXCEPTIONS=0) - if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") - endif(UNIX) -endif() - -option(SIMDJSON_ENABLE_THREADS "Enable threaded operation" ON) -if(SIMDJSON_ENABLE_THREADS) - find_package(Threads REQUIRED) - target_link_libraries(simdjson-headers INTERFACE Threads::Threads) -endif() - -option(SIMDJSON_SANITIZE "Sanitize addresses" OFF) -if(SIMDJSON_SANITIZE) - # Not sure which - target_compile_options(simdjson-headers INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) - target_link_libraries(simdjson-headers INTERFACE -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all) - - # Ubuntu bug for GCC 5.0+ (safe for all versions) - if (CMAKE_COMPILER_IS_GNUCC) - target_link_libraries(simdjson-headers INTERFACE -fuse-ld=gold) - endif() -endif() + $ + $ +) install(TARGETS simdjson-headers EXPORT simdjson-headers-config diff --git a/include/simdjson/common_defs.h b/include/simdjson/common_defs.h index 1df0822c..ce82844c 100644 --- a/include/simdjson/common_defs.h +++ b/include/simdjson/common_defs.h @@ -108,7 +108,8 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024; SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \ SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \ SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \ - SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) + SIMDJSON_DISABLE_GCC_WARNING(-Wimplicit-fallthrough) \ + SIMDJSON_DISABLE_GCC_WARNING(-Wreturn-type) #define SIMDJSON_PRAGMA(P) _Pragma(#P) #define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING) #define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6bcbccdf..f16f2fc9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,29 @@ # -# simdjson as a library +# For callers who intend to #include simdjson.cpp. +# +# target_link_libraries(my-program simdjson-include-source) gives you the header and source +# directories. It does not specify any compiler flags. +# +add_library(simdjson-include-source INTERFACE) +target_link_libraries(simdjson-include-source INTERFACE simdjson-headers) +target_include_directories(simdjson-include-source INTERFACE .) + +# +# For callers who intend to compile simdjson.cpp themselves. +# +# target_link_libraries(my-object simdjson-source) gives you the header and source directories, plus +# the .cpp sources. It does not specify any compiler flags. +# +add_library(simdjson-source INTERFACE) +target_sources(simdjson-source INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/simdjson.cpp) +target_link_libraries(simdjson-source INTERFACE simdjson-include-source) + +# +# simdjson is the distributed library compiled with flags. +# +# target_link_libraries(my-object simdjson) gives you the .so or .a to link against, plus the header +# directory. It does not specify any compiler flags, even though simdjson.so/a was compiled with +# target_link_libraries(simdjson PRIVATE simdjson-flags). # if(SIMDJSON_BUILD_STATIC) @@ -15,9 +39,8 @@ else() endif() endif() -target_sources(simdjson PRIVATE simdjson.cpp) -target_link_libraries(simdjson PUBLIC simdjson-headers) -target_include_directories(simdjson PRIVATE .) +target_link_libraries(simdjson PRIVATE simdjson-source simdjson-flags) +target_link_libraries(simdjson INTERFACE simdjson-headers) # Only expose the headers, not sources if(NOT MSVC) ## We output the library at the root of the current directory where cmake is invoked @@ -26,13 +49,6 @@ if(NOT MSVC) MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR}) endif() -# -# simdjson to be compiled into your exe as source (you must #include simdjson.cpp) -# -add_library(simdjson-source INTERFACE) -target_link_libraries(simdjson-source INTERFACE simdjson-headers) -target_include_directories(simdjson-source INTERFACE .) - # # Installation # diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 39276f88..ac67feac 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,42 +1,60 @@ # Helper so we don't have to repeat ourselves so much function(add_cpp_test TEST_NAME TEST_FILE) + # If a source file is passed, add an executable add_executable(${TEST_NAME} ${TEST_FILE}) add_test(${TEST_NAME} ${TEST_NAME}) -endfunction(add_cpp_test) + if ($ARGN) + set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN}) + else() + set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests) + endif() +endfunction() + +function(add_compile_test TEST_NAME TEST_FILE) + add_executable(${TEST_NAME} ${TEST_FILE}) + set_target_properties(${TEST_NAME} PROPERTIES + EXCLUDE_FROM_ALL TRUE + EXCLUDE_FROM_DEFAULT_BUILD TRUE) + add_test( + NAME ${TEST_NAME} + COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + if (${ARGN}) # Labels + set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS ${ARGN}) + else() + set_property(TEST ${TEST_NAME} APPEND PROPERTY LABELS slowtests) + endif() +endfunction(add_compile_test) # Most tests need test data, and many need windows headers. -link_libraries(test-data simdjson-windows-headers) +link_libraries(simdjson-flags test-data simdjson-windows-headers) # -# These test explicitly do #include "simdjson.cpp" so they can override stuff +# These tests explicitly do #include "simdjson.cpp" so they can override stuff # if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason. add_cpp_test(numberparsingcheck numberparsingcheck.cpp quicktests) - target_link_libraries(numberparsingcheck simdjson-source) + target_link_libraries(numberparsingcheck simdjson-include-source) add_cpp_test(stringparsingcheck stringparsingcheck.cpp quicktests) - target_link_libraries(stringparsingcheck simdjson-source) + target_link_libraries(stringparsingcheck simdjson-include-source) endif() # All remaining tests link with simdjson proper link_libraries(simdjson) - -add_cpp_test(basictests basictests.cpp) -add_cpp_test(errortests errortests.cpp) -add_cpp_test(integer_tests integer_tests.cpp) -add_cpp_test(jsoncheck jsoncheck.cpp) -add_cpp_test(parse_many_test parse_many_test.cpp) +add_cpp_test(basictests basictests.cpp quicktests) +add_cpp_test(errortests errortests.cpp quicktests) +add_cpp_test(integer_tests integer_tests.cpp quicktests) +add_cpp_test(jsoncheck jsoncheck.cpp quicktests) +add_cpp_test(parse_many_test parse_many_test.cpp quicktests) add_cpp_test(pointercheck pointercheck.cpp quicktests) add_cpp_test(extracting_values_example extracting_values_example.cpp quicktests) -set_property( - TEST basictests errortests integer_tests jsoncheck parse_many_test pointercheck - APPEND PROPERTY LABELS quicktests -) - -# -# json2json test -# +# Script tests if (NOT MSVC) # Can't run .sh on windows + # + # json2json test + # add_test( NAME testjson2json COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testjson2json.sh @@ -44,46 +62,44 @@ if (NOT MSVC) # Can't run .sh on windows ) set_property(TEST testjson2json APPEND PROPERTY DEPENDS minify json2json) set_property(TEST testjson2json APPEND PROPERTY LABELS slowtests) + + # + # Competition parse test + # + if (SIMDJSON_COMPETITION) + add_executable(allparserscheckfile allparserscheckfile.cpp) + target_link_libraries(allparserscheckfile competition-all) + + add_test(issue150 ${CMAKE_CURRENT_SOURCE_DIR}/issue150.sh) + set_property(TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile) + set_property(TEST issue150 APPEND PROPERTY LABELS slowtests) + endif() endif() # -# Competition parse test +# Compile-only tests with simdjson flags on # -if (SIMDJSON_COMPETITION) - add_executable(allparserscheckfile allparserscheckfile.cpp) - target_link_libraries(allparserscheckfile competition-all) - - add_test(issue150 ${CMAKE_CURRENT_SOURCE_DIR}/issue150.sh) - set_property(TEST issue150 APPEND PROPERTY DEPENDS allparserscheckfile) - set_property(TEST issue150 APPEND PROPERTY LABELS slowtests) -endif() - -# -# Compile-only tests -# -function(add_compile_test TEST_NAME TEST_FILE) - add_executable(${TEST_NAME} ${TEST_FILE}) - set_target_properties(${TEST_NAME} PROPERTIES - EXCLUDE_FROM_ALL TRUE - EXCLUDE_FROM_DEFAULT_BUILD TRUE) - add_test(NAME ${TEST_NAME} - COMMAND ${CMAKE_COMMAND} --build . --target ${TEST_NAME} --config $ - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) -endfunction(add_compile_test) # Don't add the tests if we're on VS2017 or older; they don't succeed. if(NOT (MSVC AND MSVC_VERSION LESS 1920)) -if(SIMDJSON_EXCEPTIONS) - add_compile_test(readme_examples readme_examples.cpp quicktests) - set_property( - TEST readme_examples - APPEND PROPERTY LABELS quicktests - ) -endif() + if(SIMDJSON_EXCEPTIONS) + add_compile_test(readme_examples readme_examples.cpp quicktests) + set_property( + TEST readme_examples + APPEND PROPERTY LABELS quicktests + ) + endif() add_compile_test(readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests) + add_compile_test(readme_examples11 readme_examples.cpp quicktests) + set_target_properties(readme_examples11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF) + target_compile_options(readme_examples11 PRIVATE -Werror) + add_compile_test(readme_examples_noexceptions11 readme_examples_noexceptions.cpp quicktests) + set_target_properties(readme_examples_noexceptions11 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF) + target_compile_options(readme_examples_noexceptions11 PRIVATE -Werror) + # Compile tests that *should fail* - add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp) + add_compile_test(readme_examples_will_fail_with_exceptions_off readme_examples.cpp quicktests) target_compile_definitions(readme_examples_will_fail_with_exceptions_off PRIVATE SIMDJSON_EXCEPTIONS=0) set_tests_properties(readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE) set_property( @@ -112,7 +128,7 @@ endif() ## This causes problems # add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp) -# target_link_libraries(singleheader simdjson) +# target_link_libraries(singleheader simdjson simdjson-flags) # add_test(singleheader singleheader) add_subdirectory(compilation_failure_tests) diff --git a/tests/readme_examples.cpp b/tests/readme_examples.cpp index 70624de2..88fcc404 100644 --- a/tests/readme_examples.cpp +++ b/tests/readme_examples.cpp @@ -109,7 +109,7 @@ namespace treewalk_1 { } } -#if (SIMDJSON_CPLUSPLUS >= 201703L) +#ifdef SIMDJSON_CPLUSPLUS17 void basics_cpp17_1() { dom::parser parser; padded_string json = R"( { "foo": 1, "bar": 2 } )"_padded; @@ -179,7 +179,7 @@ void performance_1() { cout << doc2 << endl; } -#if (SIMDJSON_CPLUSPLUS >= 201703L) +#ifdef SIMDJSON_CPLUSPLUS17 // The web_request part of this is aspirational, so we compile as much as we can here void performance_2() { dom::parser parser(1024*1024); // Never grow past documents > 1MB diff --git a/tests/readme_examples_noexceptions.cpp b/tests/readme_examples_noexceptions.cpp index e6c965c8..473cac17 100644 --- a/tests/readme_examples_noexceptions.cpp +++ b/tests/readme_examples_noexceptions.cpp @@ -4,7 +4,7 @@ using namespace std; using namespace simdjson; -#if (SIMDJSON_CPLUSPLUS >= 201703L) +#ifdef SIMDJSON_CPLUSPLUS17 void basics_error_1() { dom::parser parser; auto json = "1"_padded; @@ -76,7 +76,7 @@ void basics_error_3() { } } -#if (SIMDJSON_CPLUSPLUS >= 201703L) +#ifdef SIMDJSON_CPLUSPLUS17 void basics_error_3_cpp17() { auto cars_json = R"( [ { "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] }, diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b952a7f1..60ab48cf 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,5 +1,4 @@ -link_libraries(simdjson) -link_libraries(simdjson-windows-headers) +link_libraries(simdjson simdjson-flags simdjson-windows-headers) add_executable(json2json json2json.cpp) add_executable(jsonstats jsonstats.cpp)