2019-05-10 09:17:13 +08:00
|
|
|
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
|
2020-04-08 03:40:25 +08:00
|
|
|
include(GNUInstallDirs)
|
2020-01-20 23:18:58 +08:00
|
|
|
|
2020-04-07 02:58:26 +08:00
|
|
|
message(STATUS "cmake version ${CMAKE_VERSION}")
|
2020-01-20 23:18:58 +08:00
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
2020-02-15 07:20:17 +08:00
|
|
|
message(STATUS "No build type selected, default to Release")
|
|
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
2019-05-10 09:17:13 +08:00
|
|
|
endif()
|
|
|
|
|
2020-04-01 05:47:25 +08:00
|
|
|
project(simdjson
|
|
|
|
DESCRIPTION "Parsing gigabytes of JSON per second"
|
2020-04-07 08:18:37 +08:00
|
|
|
LANGUAGES CXX C
|
2020-01-20 23:18:58 +08:00
|
|
|
)
|
|
|
|
|
2019-03-05 04:40:52 +08:00
|
|
|
set(PROJECT_VERSION_MAJOR 0)
|
2020-04-01 05:47:25 +08:00
|
|
|
set(PROJECT_VERSION_MINOR 3)
|
2020-04-03 07:24:43 +08:00
|
|
|
set(PROJECT_VERSION_PATCH 1)
|
|
|
|
set(SIMDJSON_LIB_VERSION "0.3.1" CACHE STRING "simdjson library version")
|
2020-04-01 21:53:45 +08:00
|
|
|
set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion")
|
2018-12-29 02:04:38 +08:00
|
|
|
|
2020-04-09 09:13:01 +08:00
|
|
|
if(MSVC)
|
2020-02-15 07:20:17 +08:00
|
|
|
option(SIMDJSON_BUILD_STATIC "Build a static library" ON) # turning it on disables the production of a dynamic library
|
2020-04-11 07:37:00 +08:00
|
|
|
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" OFF)
|
|
|
|
else()
|
2020-04-09 09:13:01 +08:00
|
|
|
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)
|
2018-12-31 10:00:19 +08:00
|
|
|
endif()
|
2020-03-14 01:38:23 +08:00
|
|
|
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF)
|
2018-12-29 02:04:38 +08:00
|
|
|
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
|
|
|
|
|
2020-04-10 08:31:35 +08:00
|
|
|
# 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()
|
|
|
|
|
2020-04-11 07:37:00 +08:00
|
|
|
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/15415#note_633938:
|
|
|
|
function(export_private_library NAME)
|
|
|
|
install(TARGETS ${NAME}
|
|
|
|
EXPORT ${NAME}-config
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
|
|
)
|
|
|
|
install(EXPORT ${NAME}-config
|
|
|
|
FILE ${NAME}-config.cmake
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simdjson-private
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
export_private_library(simdjson-flags)
|
|
|
|
|
2020-04-06 07:43:37 +08:00
|
|
|
#
|
|
|
|
# Create the top level simdjson library (must be done at this level to use both src/ and include/
|
|
|
|
# directories)
|
|
|
|
#
|
|
|
|
add_subdirectory(include)
|
|
|
|
add_subdirectory(src)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Compile tools / tests / benchmarks
|
|
|
|
#
|
2020-04-08 03:40:25 +08:00
|
|
|
enable_testing()
|
|
|
|
|
2020-04-07 08:18:37 +08:00
|
|
|
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/")
|
2020-04-06 23:24:54 +08:00
|
|
|
|
2020-04-10 08:31:35 +08:00
|
|
|
add_subdirectory(windows)
|
2020-04-07 07:04:37 +08:00
|
|
|
add_subdirectory(dependencies)
|
2018-12-29 02:04:38 +08:00
|
|
|
add_subdirectory(tests)
|
2020-04-10 01:20:44 +08:00
|
|
|
add_subdirectory(examples)
|
2020-04-10 08:31:35 +08:00
|
|
|
add_subdirectory(tools)
|
2018-12-29 02:04:38 +08:00
|
|
|
add_subdirectory(benchmark)
|
2019-02-26 03:33:01 +08:00
|
|
|
|
2019-10-29 02:46:57 +08:00
|
|
|
# for fuzzing, read the comments in the fuzz/CMakeLists.txt file
|
2019-11-08 23:32:43 +08:00
|
|
|
option(ENABLE_FUZZING "enable building the fuzzers" ON)
|
2019-10-29 02:46:57 +08:00
|
|
|
if(ENABLE_FUZZING)
|
2020-02-15 07:20:17 +08:00
|
|
|
add_subdirectory(fuzz)
|
2019-10-29 02:46:57 +08:00
|
|
|
endif()
|
|
|
|
|
2020-04-10 08:31:35 +08:00
|
|
|
#
|
|
|
|
# CPack
|
|
|
|
#
|
2019-02-26 03:33:01 +08:00
|
|
|
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
|
|
|
|
set(CPACK_PACKAGE_CONTACT "lemire@gmail.com")
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Parsing gigabytes of JSON per second")
|
|
|
|
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
|
|
|
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
|
|
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
|
|
|
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
|
|
|
|
|
|
|
set(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
|
|
|
|
|
|
|
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
|
|
|
|
|
|
|
|
include(CPack)
|