Only apply compile flags to simdjson

This commit is contained in:
John Keiser 2020-04-07 12:40:25 -07:00
parent 7317fe1440
commit 6835dd73bc
4 changed files with 99 additions and 52 deletions

View File

@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
include(GNUInstallDirs)
message(STATUS "cmake version ${CMAKE_VERSION}")
if (NOT CMAKE_BUILD_TYPE)
@ -32,24 +33,15 @@ set(SIMDJSON_LIB_VERSION "0.3.1" CACHE STRING "simdjson library version")
set(SIMDJSON_LIB_SOVERSION "1" CACHE STRING "simdjson library soversion")
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
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)
if(NOT MSVC)
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
else()
option(SIMDJSON_BUILD_STATIC "Build a static library" ON) # turning it on disables the production of a dynamic library
endif()
option(SIMDJSON_SANITIZE "Sanitize addresses" OFF)
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" OFF)
option(SIMDJSON_ENABLE_THREADS "enable threaded operation" ON)
option(SIMDJSON_NO_EXCEPTIONS "Disable simdjson's exception-throwing interface" OFF)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
find_package(Options)
#
# Create the top level simdjson library (must be done at this level to use both src/ and include/
# directories)
@ -61,12 +53,12 @@ add_subdirectory(src)
#
# Compile tools / tests / benchmarks
#
enable_testing()
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/")
enable_testing()
add_subdirectory(dependencies)
add_subdirectory(tools)
add_subdirectory(tests)
@ -79,6 +71,11 @@ 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()
set(CPACK_PACKAGE_VENDOR "Daniel Lemire")
set(CPACK_PACKAGE_CONTACT "lemire@gmail.com")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Parsing gigabytes of JSON per second")

View File

@ -167,7 +167,8 @@ For the video inclined, <br />
Funding
-------
The work is supported by the Natural Sciences and Engineering Research Council of Canada under grant number RGPIN-2017-03910.
The work is supported by the Natural Sciences and Engineering Research Council of Canada under grant
number RGPIN-2017-03910.
[license]: LICENSE
[license img]: https://img.shields.io/badge/License-Apache%202-blue.svg

View File

@ -1,2 +1,71 @@
#
# simdjson headers and flags required to compile them
#
add_library(simdjson-headers INTERFACE)
# Include directory
target_include_directories(simdjson-headers INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<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)
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
INCLUDES DESTINATION include)
install(EXPORT simdjson-headers-config
FILE simdjson-headers-config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simdjson)
install(DIRECTORY simdjson DESTINATION include FILES_MATCHING PATTERN *.h)
install(FILES simdjson.h DESTINATION include)

View File

@ -1,4 +1,6 @@
include(GNUInstallDirs)
#
# simdjson as a library
#
if(SIMDJSON_BUILD_STATIC)
MESSAGE( STATUS "Building a static library." )
@ -6,34 +8,34 @@ if(SIMDJSON_BUILD_STATIC)
else()
MESSAGE( STATUS "Building a dynamic library." )
add_library(simdjson SHARED "")
target_compile_definitions(simdjson INTERFACE SIMDJSON_USING_LIBRARY=1)
if(MSVC)
MESSAGE( STATUS "Building a Windows DLL using Visual Studio, exporting all symbols automatically." )
set_target_properties(simdjson PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()
endif()
target_sources(simdjson PRIVATE simdjson.cpp)
target_link_libraries(simdjson PUBLIC simdjson-headers)
target_include_directories(simdjson PRIVATE .)
target_include_directories(simdjson PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
if(SIMDJSON_NO_EXCEPTIONS)
message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.")
target_compile_definitions(simdjson PUBLIC SIMDJSON_EXCEPTIONS=0)
if(NOT MSVC)
## We output the library at the root of the current directory where cmake is invoked
## This is handy but Visual Studio will happily ignore us
set_target_properties(simdjson PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR})
endif()
if(${CMAKE_C_COMPILER_ID} MATCHES "Intel") # icc / icpc
# prevent shared libraries from depending on Intel provided libraries
target_link_options(simdjson PUBLIC "-static-intel")
endif()
if(SIMDJSON_ENABLE_THREADS)
find_package(Threads REQUIRED)
target_link_libraries(simdjson PRIVATE Threads::Threads)
endif()
# For targets that want to include the source directly
#
# 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 .)
target_include_directories(simdjson-source INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
#
# Installation
#
install(TARGETS simdjson
EXPORT simdjson-config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
@ -46,25 +48,3 @@ install(EXPORT simdjson-config
NAMESPACE simdjson::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/simdjson
)
if(NOT MSVC)
## We output the library at the root of the current directory where cmake is invoked
## This is handy but Visual Studio will happily ignore us
set_target_properties(simdjson PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
MESSAGE( STATUS "Library output directory (does not apply to Visual Studio): " ${CMAKE_BINARY_DIR})
endif()
if(NOT SIMDJSON_BUILD_STATIC)
target_compile_definitions(simdjson INTERFACE SIMDJSON_USING_LIBRARY=1)
endif()
if(MSVC AND (NOT SIMDJSON_BUILD_STATIC))
if (CMAKE_VERSION VERSION_LESS 3.4)
MESSAGE( STATUS "To build a Windows DLL using Visual Studio, you may need cmake 3.4 or better." )
endif()
MESSAGE( STATUS "Building a Windows DLL using Visual Studio, exporting all symbols automatically." )
set_target_properties(simdjson
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()