mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
c806e955c4
* Initial work on JSON builder * moving the files back to ondemand for now. * tweak * more later * update * minor edits * dropping vs arm (missing support) * adding tests. we still specialized write_string_escaped * tweaking * fix typo * tweaking the approach * minor fix * missing store * another missing store * Attempt at fixing failing serialization tests. (#2292) * Fixing appeand_float typo (#2294) * applying a couple of fixes * updating single header * fix for pre C++17 if constexpr * Fixing unused argument problem and updating the singleheader file * various pedantic fixes * Sketch of builder * reordering. * simplify * Adding draft of static reflection based deserialization * Updating simdjson singleheader * patching the automated deserialization. * automated * Adding support for smart pointers of user defined types. * Adding specialization for smart pointers for basic types. I think it is highly likely that this can be done in a more generic way. * Referncing a later version of rapidjson that fixed the issue related with assignment attempt of a const variable for GenericStringRef class. * guarding the tests * adding documentation for string_builder * saving * rename to 'append' * saving * non-functional benchmarks (#2342) * non-functional benchmarks * Fix typo * various fixes * tweaking --------- Co-authored-by: Daniel Lemire <dlemire@lemire.me> Co-authored-by: Francisco Geiman Thiesen <franciscogthiesen@gmail.com> * tuning * various minor fixes * minor tweak * minor simplification * updating amal * adding a cast * update * fancy casting * removing dead code * Pushing latest changes. CITM benchmark is still not working. * Still not working, but now I am getting only 10 errors. * add static reflection benchmark to 'large random' benchmark and allows (#2349) deserialization (with static reflection) from objects and arrays. Co-authored-by: Daniel Lemire <dlemire@lemire.me> * Removing std::map from CitmCatalog definition, since that is not currently supported. * Added free to rust bench, segfault is still happening.. * The syntax changed: ^E became ^^E. (#2350) * The syntax changed: ^E became ^^E. * guarding --------- Co-authored-by: Daniel Lemire <dlemire@lemire.me> * Adding support for string_view_keyed_map types. * Adding concepts as a conditional include. * updating single-header * Adding concepts to ondemand deps * rust benchmark is finally working * Fixing small typo in docs. * adding docker config and instructions so that our users can test the static reflection (#2358) * adding docker config and instructions so that our users can test the static reflection * completing the instructions * pruning white spaces --------- Co-authored-by: Daniel Lemire <dlemire@lemire.me> * minor optimizations on the JSON builder branch * avoiding undef behaviour * saving * somewhat nicer builder * make it possible to run just one benchmark * adding linux perf * fixing minor issue * updating swar * Adding real world compilation benchmark (#2379) * Adding compilation benchmark for json parsing with and without reflection * Moving it to the benchmark folder, also reducing a bit the number of iterations. * Removing script from root folder. * Reducing number of iterations * Update benchmark/benchmark_reflection_usage_compilation.sh Co-authored-by: Daniel Lemire <daniel@lemire.me> * Update benchmark/benchmark_reflection_usage_compilation.sh Co-authored-by: Daniel Lemire <daniel@lemire.me> * Update benchmark/benchmark_reflection_usage_compilation.sh Co-authored-by: Daniel Lemire <daniel@lemire.me> * Making the script more customizable and also test whether the compiler being used supports reflection before actually running the benchmark --------- Co-authored-by: Daniel Lemire <daniel@lemire.me> * Using define_static_string from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3491r2.html (#2389) * Applying changes needed after latest reflection paper updates. * Working, but no template for yet. * Updating single-header to incldue the use of define_static_string. * copying over master --------- Co-authored-by: Daniel Lemire <dlemire@lemire.me> Co-authored-by: Francisco Geiman Thiesen <franciscogthiesen@gmail.com>
239 lines
8.3 KiB
CMake
239 lines
8.3 KiB
CMake
#
|
|
# Flags used by exes and by the simdjson library (project-wide flags)
|
|
#
|
|
add_library(simdjson-internal-flags INTERFACE)
|
|
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
|
# We default to ON for all targets, so that we can use the library in shared libraries.
|
|
set_target_properties(simdjson-internal-flags PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|
endif(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
|
|
|
|
option(SIMDJSON_CHECK_EOF "Check for the end of the input buffer. The setting is unnecessary since we require padding of the inputs. You should expect tests to fail with this option turned on." OFF)
|
|
if(SIMDJSON_CHECK_EOF)
|
|
add_compile_definitions(SIMDJSON_CHECK_EOF=1)
|
|
endif()
|
|
|
|
option(SIMDJSON_SANITIZE_UNDEFINED "Sanitize undefined behavior" OFF)
|
|
if(SIMDJSON_SANITIZE_UNDEFINED)
|
|
add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all)
|
|
add_link_options(-fsanitize=undefined -fno-sanitize-recover=all)
|
|
endif()
|
|
|
|
option(SIMDJSON_SANITIZE "Sanitize addresses" OFF)
|
|
if(SIMDJSON_SANITIZE)
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
message(STATUS "The address sanitizer under Apple's clang appears to be \
|
|
incompatible with the undefined-behavior sanitizer.")
|
|
message(STATUS "You may set SIMDJSON_SANITIZE_UNDEFINED to sanitize \
|
|
undefined behavior.")
|
|
add_compile_options(
|
|
-fsanitize=address -fno-omit-frame-pointer -fno-sanitize-recover=all
|
|
)
|
|
add_compile_definitions(ASAN_OPTIONS=detect_leaks=1)
|
|
link_libraries(
|
|
-fsanitize=address -fno-omit-frame-pointer -fno-sanitize-recover=all
|
|
)
|
|
else()
|
|
message(
|
|
STATUS
|
|
"Setting both the address sanitizer and the undefined sanitizer."
|
|
)
|
|
add_compile_options(
|
|
-fsanitize=address -fno-omit-frame-pointer
|
|
-fsanitize=undefined -fno-sanitize-recover=all
|
|
)
|
|
link_libraries(
|
|
-fsanitize=address -fno-omit-frame-pointer
|
|
-fsanitize=undefined -fno-sanitize-recover=all
|
|
)
|
|
endif()
|
|
|
|
# Ubuntu bug for GCC 5.0+ (safe for all versions)
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
link_libraries(-fuse-ld=gold)
|
|
endif()
|
|
endif()
|
|
|
|
option(SIMDJSON_SANITIZE_MEMORY "Sanitize memory" OFF)
|
|
|
|
if(SIMDJSON_SANITIZE_MEMORY)
|
|
message(STATUS "Setting the memory sanitizer.")
|
|
add_compile_options(
|
|
-fsanitize=memory -fno-sanitize-recover=all
|
|
)
|
|
link_libraries(
|
|
-fsanitize=memory -fno-sanitize-recover=all
|
|
)
|
|
# Ubuntu bug for GCC 5.0+ (safe for all versions)
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
link_libraries(-fuse-ld=gold)
|
|
endif()
|
|
endif()
|
|
|
|
if(SIMDJSON_SANITIZE_THREADS)
|
|
message(STATUS "Setting both the thread sanitizer \
|
|
and the undefined-behavior sanitizer.")
|
|
add_compile_options(
|
|
-fsanitize=thread -fsanitize=undefined -fno-sanitize-recover=all
|
|
)
|
|
link_libraries(
|
|
-fsanitize=thread -fsanitize=undefined -fno-sanitize-recover=all
|
|
)
|
|
|
|
# Ubuntu bug for GCC 5.0+ (safe for all versions)
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
link_libraries(-fuse-ld=gold)
|
|
endif()
|
|
endif()
|
|
|
|
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
|
|
if(NOT is_multi_config AND NOT CMAKE_BUILD_TYPE)
|
|
# Deliberately not including SIMDJSON_SANITIZE_THREADS since thread behavior
|
|
# depends on the build type.
|
|
if(SIMDJSON_SANITIZE OR SIMDJSON_SANITIZE_UNDEFINED)
|
|
message(STATUS "No build type selected and you have enabled the sanitizer, \
|
|
default to Debug. Consider setting CMAKE_BUILD_TYPE.")
|
|
message(STATUS "Setting debug optimization flag to -O1 to help sanitizer.")
|
|
set(CMAKE_CXX_FLAGS_DEBUG "-O1" CACHE STRING "" FORCE)
|
|
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
|
|
else()
|
|
message(STATUS "No build type selected, default to Release")
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
|
endif()
|
|
endif()
|
|
|
|
if(NOT MSVC)
|
|
option(SIMDJSON_USE_LIBCPP "Use the libc++ library" OFF)
|
|
endif()
|
|
|
|
if(MSVC AND BUILD_SHARED_LIBS)
|
|
# This will require special handling.
|
|
set(SIMDJSON_WINDOWS_DLL TRUE)
|
|
endif()
|
|
|
|
# We compile tools, tests, etc. with C++ 17. Override yourself if you need on a
|
|
# target.
|
|
if(SIMDJSON_STATIC_REFLECTION)
|
|
# This is temporary.
|
|
set(SIMDJSON_CXX_STANDARD 26 CACHE STRING "the C++ standard to use for simdjson")
|
|
#set(CMAKE_CXX_STANDARD ${SIMDJSON_CXX_STANDARD})
|
|
else()
|
|
set(SIMDJSON_CXX_STANDARD 17 CACHE STRING "the C++ standard to use for simdjson")
|
|
set(CMAKE_CXX_STANDARD ${SIMDJSON_CXX_STANDARD})
|
|
endif()
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
set(CMAKE_THREAD_PREFER_PTHREAD ON)
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
set(SIMDJSON_STRUCTURAL_INDEXER_STEP CACHE STRING "the SIMDJSON_STRUCTURAL_INDEXER_STEP variable")
|
|
|
|
if(SIMDJSON_STRUCTURAL_INDEXER_STEP)
|
|
message(STATUS "Setting SIMDJSON_STRUCTURAL_INDEXER_STEP to ${SIMDJSON_STRUCTURAL_INDEXER_STEP}.")
|
|
add_compile_definitions(SIMDJSON_STRUCTURAL_INDEXER_STEP=${SIMDJSON_STRUCTURAL_INDEXER_STEP})
|
|
endif()
|
|
# 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()
|
|
|
|
option(SIMDJSON_VISUAL_STUDIO_BUILD_WITH_DEBUG_INFO_FOR_PROFILING "\
|
|
Under Visual Studio, add Zi to the compile flag and DEBUG to the link file to \
|
|
add debugging information to the release build for easier profiling inside \
|
|
tools like VTune" OFF)
|
|
if(MSVC)
|
|
if(MSVC_TOOLSET_VERSION STRLESS "142")
|
|
set(SIMDJSON_LEGACY_VISUAL_STUDIO TRUE)
|
|
message (STATUS "A legacy Visual Studio version was detected. \
|
|
We recommend Visual Studio 2019 or better on a 64-bit system.")
|
|
endif()
|
|
if(MSVC_TOOLSET_VERSION STREQUAL "140")
|
|
# Visual Studio 2015 issues warnings and we tolerate it
|
|
# cmake -G "Visual Studio 14" ..
|
|
target_compile_options(simdjson-internal-flags INTERFACE /W0 /sdl)
|
|
else()
|
|
# Recent version of Visual Studio expected (2017, 2019...). Prior versions
|
|
# are unsupported.
|
|
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4714?view=vs-2019
|
|
target_compile_options(simdjson-internal-flags INTERFACE /WX /W3 /sdl /w34714)
|
|
if(MSVC_VERSION GREATER 1910)
|
|
target_compile_options(simdjson-internal-flags INTERFACE /permissive-)
|
|
endif()
|
|
endif()
|
|
if(SIMDJSON_VISUAL_STUDIO_BUILD_WITH_DEBUG_INFO_FOR_PROFILING)
|
|
add_link_options(/DEBUG)
|
|
add_compile_options(/Zi)
|
|
endif()
|
|
else()
|
|
target_compile_options(
|
|
simdjson-internal-flags INTERFACE
|
|
-Werror -Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings
|
|
-Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion
|
|
)
|
|
endif()
|
|
|
|
option(SIMDJSON_GLIBCXX_ASSERTIONS "Set _GLIBCXX_ASSERTIONS" OFF)
|
|
if (SIMDJSON_GLIBCXX_ASSERTIONS)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS")
|
|
endif()
|
|
|
|
#
|
|
# Other optional flags
|
|
#
|
|
option(SIMDJSON_BASH "Allow usage of bash within CMake" ON)
|
|
|
|
option(
|
|
SIMDJSON_VERBOSE_LOGGING
|
|
"Enable verbose logging for internal simdjson library development."
|
|
OFF
|
|
)
|
|
if(SIMDJSON_VERBOSE_LOGGING)
|
|
add_compile_definitions(SIMDJSON_VERBOSE_LOGGING=1
|
|
)
|
|
endif()
|
|
|
|
if(SIMDJSON_USE_LIBCPP)
|
|
link_libraries(-stdlib=libc++ -lc++abi)
|
|
# instead of the above line, we could have used
|
|
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++
|
|
# -lc++abi")
|
|
# The next line is needed empirically.
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
# we update CMAKE_SHARED_LINKER_FLAGS, this gets updated later as well
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lc++abi")
|
|
endif()
|
|
|
|
# prevent shared libraries from depending on Intel provided libraries
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-intel")
|
|
endif()
|
|
|
|
option(
|
|
SIMDJSON_AVX512_ALLOWED
|
|
"Enable AVX-512 instructions (only affects processors and compilers with AVX-512 support)."
|
|
ON
|
|
)
|
|
if(SIMDJSON_AVX512_ALLOWED)
|
|
add_compile_definitions(SIMDJSON_AVX512_ALLOWED=1)
|
|
else()
|
|
add_compile_definitions(SIMDJSON_AVX512_ALLOWED=0)
|
|
message(STATUS "AVX-512 instructions are not allowed.")
|
|
endif()
|
|
|
|
option(
|
|
SIMDJSON_SKIPUTF8VALIDATION
|
|
"SKIP UTF8 VALIDATION."
|
|
OFF
|
|
)
|
|
if(SIMDJSON_SKIPUTF8VALIDATION)
|
|
add_compile_definitions(SIMDJSON_UTF8VALIDATION=0)
|
|
message(STATUS "SKIP UTF8 VALIDATION")
|
|
else()
|
|
add_compile_definitions(SIMDJSON_UTF8VALIDATION=1)
|
|
endif()
|
|
|
|
include(CheckSymbolExists)
|
|
check_symbol_exists(fork unistd.h HAVE_POSIX_FORK)
|
|
check_symbol_exists(wait sys/wait.h HAVE_POSIX_WAIT)
|