Add C++11 tests to cmake
- Add simdjson-flags target so callers don't have flags forced on them
This commit is contained in:
parent
326c175dcb
commit
09cf18a646
|
@ -20,7 +20,7 @@ build_script:
|
||||||
- mkdir build
|
- mkdir build
|
||||||
- cd 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 -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:
|
test_script:
|
||||||
- ctest --verbose --output-on-failure -C %Configuration%
|
- ctest --verbose --output-on-failure -C %Configuration%
|
||||||
|
|
105
CMakeLists.txt
105
CMakeLists.txt
|
@ -12,20 +12,6 @@ project(simdjson
|
||||||
LANGUAGES CXX C
|
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_MAJOR 0)
|
||||||
set(PROJECT_VERSION_MINOR 3)
|
set(PROJECT_VERSION_MINOR 3)
|
||||||
set(PROJECT_VERSION_PATCH 1)
|
set(PROJECT_VERSION_PATCH 1)
|
||||||
|
@ -34,7 +20,7 @@ set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion")
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
option(SIMDJSON_BUILD_STATIC "Build a static library" ON) # turning it on disables the production of a dynamic library
|
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()
|
else()
|
||||||
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
|
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)
|
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")
|
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/
|
# Create the top level simdjson library (must be done at this level to use both src/ and include/
|
||||||
# directories)
|
# directories)
|
||||||
#
|
#
|
||||||
add_subdirectory(windows)
|
|
||||||
add_subdirectory(include)
|
add_subdirectory(include)
|
||||||
add_subdirectory(src)
|
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_TEST_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")
|
||||||
target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
|
target_compile_definitions(test-data INTERFACE SIMDJSON_BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/")
|
||||||
|
|
||||||
|
add_subdirectory(windows)
|
||||||
add_subdirectory(dependencies)
|
add_subdirectory(dependencies)
|
||||||
add_subdirectory(tools)
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
add_subdirectory(examples)
|
add_subdirectory(examples)
|
||||||
|
add_subdirectory(tools)
|
||||||
add_subdirectory(benchmark)
|
add_subdirectory(benchmark)
|
||||||
|
|
||||||
# for fuzzing, read the comments in the fuzz/CMakeLists.txt file
|
# for fuzzing, read the comments in the fuzz/CMakeLists.txt file
|
||||||
|
@ -72,11 +133,9 @@ if(ENABLE_FUZZING)
|
||||||
add_subdirectory(fuzz)
|
add_subdirectory(fuzz)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc
|
#
|
||||||
# prevent shared libraries from depending on Intel provided libraries
|
# CPack
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel")
|
#
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
|
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
|
||||||
set(CPACK_PACKAGE_CONTACT "lemire@gmail.com")
|
set(CPACK_PACKAGE_CONTACT "lemire@gmail.com")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Parsing gigabytes of JSON per second")
|
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")
|
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
|
||||||
|
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
include_directories( . linux )
|
include_directories( . linux )
|
||||||
link_libraries(simdjson)
|
link_libraries(simdjson simdjson-flags)
|
||||||
# add_executable(benchfeatures benchfeatures.cpp)
|
# add_executable(benchfeatures benchfeatures.cpp) # doesn't presently compile at all
|
||||||
add_executable(get_corpus_benchmark get_corpus_benchmark.cpp)
|
add_executable(get_corpus_benchmark get_corpus_benchmark.cpp)
|
||||||
add_executable(perfdiff perfdiff.cpp)
|
add_executable(perfdiff perfdiff.cpp)
|
||||||
add_executable(parse parse.cpp)
|
add_executable(parse parse.cpp)
|
||||||
|
|
|
@ -1,6 +1,52 @@
|
||||||
if(SIMDJSON_EXCEPTIONS)
|
#
|
||||||
add_executable(quickstart quickstart.cpp)
|
# Quickstart compile tests don't require any flags
|
||||||
target_link_libraries(quickstart PRIVATE simdjson)
|
#
|
||||||
|
|
||||||
|
# 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()
|
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 )
|
||||||
|
|
|
@ -44,7 +44,7 @@ macro(implement_fuzzer sourcefile)
|
||||||
if (SIMDJSON_FUZZ_LINKMAIN)
|
if (SIMDJSON_FUZZ_LINKMAIN)
|
||||||
target_sources(${name} PRIVATE main.cpp)
|
target_sources(${name} PRIVATE main.cpp)
|
||||||
endif ()
|
endif ()
|
||||||
target_link_libraries(${name} PRIVATE simdjson)
|
target_link_libraries(${name} PRIVATE simdjson simdjson-flags)
|
||||||
if (SIMDJSON_FUZZ_LDFLAGS)
|
if (SIMDJSON_FUZZ_LDFLAGS)
|
||||||
target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS})
|
target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -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)
|
add_library(simdjson-headers INTERFACE)
|
||||||
|
target_compile_features(simdjson-headers INTERFACE cxx_std_11) # headers require at least C++11
|
||||||
# Include directory
|
|
||||||
target_include_directories(simdjson-headers INTERFACE
|
target_include_directories(simdjson-headers INTERFACE
|
||||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
# 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 $<$<CONFIG:DEBUG>:-ggdb>)
|
|
||||||
target_compile_options(simdjson-headers INTERFACE $<$<CONFIG:RELEASE>:-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
|
install(TARGETS simdjson-headers
|
||||||
EXPORT simdjson-headers-config
|
EXPORT simdjson-headers-config
|
||||||
|
|
|
@ -108,7 +108,8 @@ constexpr size_t DEFAULT_MAX_DEPTH = 1024;
|
||||||
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
|
SIMDJSON_DISABLE_GCC_WARNING(-Wextra) \
|
||||||
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
|
SIMDJSON_DISABLE_GCC_WARNING(-Wshadow) \
|
||||||
SIMDJSON_DISABLE_GCC_WARNING(-Wunused-parameter) \
|
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_PRAGMA(P) _Pragma(#P)
|
||||||
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
|
#define SIMDJSON_DISABLE_GCC_WARNING(WARNING) SIMDJSON_PRAGMA(GCC diagnostic ignored #WARNING)
|
||||||
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
|
#define SIMDJSON_DISABLE_DEPRECATED_WARNING SIMDJSON_DISABLE_GCC_WARNING(-Wdeprecated-declarations)
|
||||||
|
|
|
@ -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)
|
if(SIMDJSON_BUILD_STATIC)
|
||||||
|
@ -15,9 +39,8 @@ else()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_sources(simdjson PRIVATE simdjson.cpp)
|
target_link_libraries(simdjson PRIVATE simdjson-source simdjson-flags)
|
||||||
target_link_libraries(simdjson PUBLIC simdjson-headers)
|
target_link_libraries(simdjson INTERFACE simdjson-headers) # Only expose the headers, not sources
|
||||||
target_include_directories(simdjson PRIVATE .)
|
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
## We output the library at the root of the current directory where cmake is invoked
|
## 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})
|
MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR})
|
||||||
endif()
|
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
|
# Installation
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,42 +1,60 @@
|
||||||
# Helper so we don't have to repeat ourselves so much
|
# Helper so we don't have to repeat ourselves so much
|
||||||
function(add_cpp_test TEST_NAME TEST_FILE)
|
function(add_cpp_test TEST_NAME TEST_FILE)
|
||||||
|
# If a source file is passed, add an executable
|
||||||
add_executable(${TEST_NAME} ${TEST_FILE})
|
add_executable(${TEST_NAME} ${TEST_FILE})
|
||||||
add_test(${TEST_NAME} ${TEST_NAME})
|
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 $<CONFIGURATION>
|
||||||
|
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.
|
# 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.
|
if (NOT MSVC) # Can't get simdjson-source to compile on Windows for some reason.
|
||||||
add_cpp_test(numberparsingcheck numberparsingcheck.cpp quicktests)
|
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)
|
add_cpp_test(stringparsingcheck stringparsingcheck.cpp quicktests)
|
||||||
target_link_libraries(stringparsingcheck simdjson-source)
|
target_link_libraries(stringparsingcheck simdjson-include-source)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# All remaining tests link with simdjson proper
|
# All remaining tests link with simdjson proper
|
||||||
link_libraries(simdjson)
|
link_libraries(simdjson)
|
||||||
|
add_cpp_test(basictests basictests.cpp quicktests)
|
||||||
add_cpp_test(basictests basictests.cpp)
|
add_cpp_test(errortests errortests.cpp quicktests)
|
||||||
add_cpp_test(errortests errortests.cpp)
|
add_cpp_test(integer_tests integer_tests.cpp quicktests)
|
||||||
add_cpp_test(integer_tests integer_tests.cpp)
|
add_cpp_test(jsoncheck jsoncheck.cpp quicktests)
|
||||||
add_cpp_test(jsoncheck jsoncheck.cpp)
|
add_cpp_test(parse_many_test parse_many_test.cpp quicktests)
|
||||||
add_cpp_test(parse_many_test parse_many_test.cpp)
|
|
||||||
add_cpp_test(pointercheck pointercheck.cpp quicktests)
|
add_cpp_test(pointercheck pointercheck.cpp quicktests)
|
||||||
add_cpp_test(extracting_values_example extracting_values_example.cpp quicktests)
|
add_cpp_test(extracting_values_example extracting_values_example.cpp quicktests)
|
||||||
|
|
||||||
set_property(
|
# Script tests
|
||||||
TEST basictests errortests integer_tests jsoncheck parse_many_test pointercheck
|
|
||||||
APPEND PROPERTY LABELS quicktests
|
|
||||||
)
|
|
||||||
|
|
||||||
#
|
|
||||||
# json2json test
|
|
||||||
#
|
|
||||||
if (NOT MSVC) # Can't run .sh on windows
|
if (NOT MSVC) # Can't run .sh on windows
|
||||||
|
#
|
||||||
|
# json2json test
|
||||||
|
#
|
||||||
add_test(
|
add_test(
|
||||||
NAME testjson2json
|
NAME testjson2json
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/testjson2json.sh
|
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 DEPENDS minify json2json)
|
||||||
set_property(TEST testjson2json APPEND PROPERTY LABELS slowtests)
|
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()
|
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 $<CONFIGURATION>
|
|
||||||
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.
|
# 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(NOT (MSVC AND MSVC_VERSION LESS 1920))
|
||||||
if(SIMDJSON_EXCEPTIONS)
|
if(SIMDJSON_EXCEPTIONS)
|
||||||
add_compile_test(readme_examples readme_examples.cpp quicktests)
|
add_compile_test(readme_examples readme_examples.cpp quicktests)
|
||||||
set_property(
|
set_property(
|
||||||
TEST readme_examples
|
TEST readme_examples
|
||||||
APPEND PROPERTY LABELS quicktests
|
APPEND PROPERTY LABELS quicktests
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
add_compile_test(readme_examples_noexceptions readme_examples_noexceptions.cpp quicktests)
|
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*
|
# 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)
|
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_tests_properties(readme_examples_will_fail_with_exceptions_off PROPERTIES WILL_FAIL TRUE)
|
||||||
set_property(
|
set_property(
|
||||||
|
@ -112,7 +128,7 @@ endif()
|
||||||
|
|
||||||
## This causes problems
|
## This causes problems
|
||||||
# add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp)
|
# 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_test(singleheader singleheader)
|
||||||
|
|
||||||
add_subdirectory(compilation_failure_tests)
|
add_subdirectory(compilation_failure_tests)
|
||||||
|
|
|
@ -109,7 +109,7 @@ namespace treewalk_1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (SIMDJSON_CPLUSPLUS >= 201703L)
|
#ifdef SIMDJSON_CPLUSPLUS17
|
||||||
void basics_cpp17_1() {
|
void basics_cpp17_1() {
|
||||||
dom::parser parser;
|
dom::parser parser;
|
||||||
padded_string json = R"( { "foo": 1, "bar": 2 } )"_padded;
|
padded_string json = R"( { "foo": 1, "bar": 2 } )"_padded;
|
||||||
|
@ -179,7 +179,7 @@ void performance_1() {
|
||||||
cout << doc2 << endl;
|
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
|
// The web_request part of this is aspirational, so we compile as much as we can here
|
||||||
void performance_2() {
|
void performance_2() {
|
||||||
dom::parser parser(1024*1024); // Never grow past documents > 1MB
|
dom::parser parser(1024*1024); // Never grow past documents > 1MB
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace simdjson;
|
using namespace simdjson;
|
||||||
|
|
||||||
#if (SIMDJSON_CPLUSPLUS >= 201703L)
|
#ifdef SIMDJSON_CPLUSPLUS17
|
||||||
void basics_error_1() {
|
void basics_error_1() {
|
||||||
dom::parser parser;
|
dom::parser parser;
|
||||||
auto json = "1"_padded;
|
auto json = "1"_padded;
|
||||||
|
@ -76,7 +76,7 @@ void basics_error_3() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (SIMDJSON_CPLUSPLUS >= 201703L)
|
#ifdef SIMDJSON_CPLUSPLUS17
|
||||||
void basics_error_3_cpp17() {
|
void basics_error_3_cpp17() {
|
||||||
auto cars_json = R"( [
|
auto cars_json = R"( [
|
||||||
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
{ "make": "Toyota", "model": "Camry", "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
link_libraries(simdjson)
|
link_libraries(simdjson simdjson-flags simdjson-windows-headers)
|
||||||
link_libraries(simdjson-windows-headers)
|
|
||||||
|
|
||||||
add_executable(json2json json2json.cpp)
|
add_executable(json2json json2json.cpp)
|
||||||
add_executable(jsonstats jsonstats.cpp)
|
add_executable(jsonstats jsonstats.cpp)
|
||||||
|
|
Loading…
Reference in New Issue