From 54b7291c341b6fd3369a2243d80de35b1df28773 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Sun, 5 Apr 2020 16:43:37 -0700 Subject: [PATCH] Reference simdjson by name, don't specify include files individually --- .circleci/config.yml | 2 +- CMakeLists.txt | 20 ++++--- benchmark/CMakeLists.txt | 7 +-- fuzz/CMakeLists.txt | 2 +- include/CMakeLists.txt | 27 +-------- src/CMakeLists.txt | 120 ++++++++------------------------------- tests/CMakeLists.txt | 4 +- 7 files changed, 43 insertions(+), 139 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2eed29a37..332f0a297 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,7 +59,7 @@ commands: - run: make all - run: make test - cmake_test: # this version builds, install, test and then verifyi from the installation + cmake_test: # this version builds, install, test and then verify from the installation steps: - run: apt-get update -qq - run: apt-get install -y cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e25a3da3..9318bda25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,6 @@ set(CMAKE_MACOSX_RPATH OFF) set(CMAKE_THREAD_PREFER_PTHREAD ON) set(THREADS_PREFER_PTHREAD_FLAG ON) -set(SIMDJSON_LIB_NAME simdjson) set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 3) set(PROJECT_VERSION_PATCH 1) @@ -50,22 +49,27 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake") find_package(CTargets) find_package(Options) -# We used to have install(DIRECTORY include/${SIMDJSON_LIB_NAME} DESTINATION include) -# alone. -# However, this fails because we also need the root level simdjson.h file. -install(DIRECTORY include/${SIMDJSON_LIB_NAME} DESTINATION include) -install(FILES include/${SIMDJSON_LIB_NAME}.h DESTINATION include) +# +# 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 +# set (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/") set (BENCHMARK_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonexamples/") add_definitions(-DSIMDJSON_TEST_DATA_DIR="${TEST_DATA_DIR}") add_definitions(-DSIMDJSON_BENCHMARK_DATA_DIR="${TEST_DATA_DIR}") enable_testing() -include(include/CMakeLists.txt) -add_subdirectory(src) + add_subdirectory(tools) add_subdirectory(tests) add_subdirectory(benchmark) + if (SIMDJSON_GOOGLE_BENCHMARKS) if(NOT EXISTS dependencies/benchmark/CMakeLists.txt) # message(STATUS "Unable to find dependencies/benchmark/CMakeLists.txt") diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 3e4f95f9a..ce56248b0 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,9 +1,4 @@ -target_include_directories(${SIMDJSON_LIB_NAME} - INTERFACE - $ - $ -) - +include_directories( . linux ) add_cpp_benchmark(parse) add_cpp_benchmark(statisticalmodel) add_cpp_benchmark(parse_stream) diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index d30c38a4c..1a31d3b38 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_LIB_NAME}) + target_link_libraries(${name} PRIVATE simdjson) if (SIMDJSON_FUZZ_LDFLAGS) target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS}) endif () diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 657a7052e..7e06d9821 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,25 +1,2 @@ -set(SIMDJSON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) -set(SIMDJSON_INCLUDE - ${SIMDJSON_INCLUDE_DIR}/simdjson.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/common_defs.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/compiler_check.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/document_stream.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/document.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/error.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/implementation.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document_stream.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/document.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/error.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/padded_string.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/inline/parsedjson_iterator.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/internal/jsonformatutils.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonioutil.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/jsonparser.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/nonstd/string_view.hpp - ${SIMDJSON_INCLUDE_DIR}/simdjson/padded_string.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/parsedjson.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/parsedjson_iterator.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/portability.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/simdjson_version.h - ${SIMDJSON_INCLUDE_DIR}/simdjson/simdjson.h -) \ No newline at end of file +install(DIRECTORY simdjson DESTINATION include FILES_MATCHING PATTERN *.h) +install(FILES simdjson.h DESTINATION include) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 239091a04..aef071ea6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,114 +1,47 @@ -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() - include(GNUInstallDirs) -# we default on a shared library. if(SIMDJSON_BUILD_STATIC) - set(SIMDJSON_LIB_TYPE STATIC) MESSAGE( STATUS "Building a static library." ) + add_library(simdjson STATIC "") else() - MESSAGE( STATUS "Building a dynamic library (default)." ) - set(SIMDJSON_LIB_TYPE SHARED) + MESSAGE( STATUS "Building a dynamic library." ) + add_library(simdjson SHARED "") endif() -MESSAGE( STATUS "SIMDJSON_LIB_TYPE: " ${SIMDJSON_LIB_TYPE}) +target_sources(simdjson PRIVATE simdjson.cpp) +target_include_directories(simdjson PUBLIC $) +target_include_directories(simdjson PRIVATE .) -# Bring in include files -include(../include/CMakeLists.txt) +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() -set(SIMDJSON_SRC_DIR $) +if(SIMDJSON_ENABLE_THREADS) + find_package(Threads REQUIRED) + target_link_libraries(simdjson PRIVATE Threads::Threads) +endif() -set(SIMDJSON_SRC - simdjson.cpp -) +# Installation -# Load headers and sources -set(SIMDJSON_SRC_HEADERS - error.cpp - implementation.cpp - isadetection.h - simdprune_tables.h - stage1_find_marks.cpp - stage2_build_tape.cpp - arm64/bitmanipulation.h - arm64/bitmask.h - arm64/implementation.h - arm64/intrinsics.h - arm64/numberparsing.h - arm64/simd.h - arm64/stage1_find_marks.h - arm64/stage2_build_tape.h - arm64/stringparsing.h - fallback/implementation.h - fallback/stage1_find_marks.h - fallback/stage2_build_tape.h - generic/atomparsing.h - generic/json_scanner.h - generic/json_string_scanner.h - generic/json_structural_indexer.h - generic/numberparsing.h - generic/stage2_build_tape.h - generic/stage2_streaming_build_tape.h - generic/stringparsing.h - generic/utf8_fastvalidate_algorithm.h - generic/utf8_lookup_algorithm.h - generic/utf8_lookup2_algorithm.h - generic/utf8_range_algorithm.h - generic/utf8_zwegner_algorithm.h - haswell/bitmanipulation.h - haswell/bitmask.h - haswell/implementation.h - haswell/intrinsics.h - haswell/numberparsing.h - haswell/simd.h - haswell/stage1_find_marks.h - haswell/stage2_build_tape.h - haswell/stringparsing.h - document_parser_callbacks.h - westmere/bitmanipulation.h - westmere/bitmask.h - westmere/implementation.h - westmere/intrinsics.h - westmere/numberparsing.h - westmere/simd.h - westmere/stage1_find_marks.h - westmere/stage2_build_tape.h - westmere/stringparsing.h -) -set_source_files_properties(${SIMDJSON_SRC_HEADERS} PROPERTIES HEADER_FILE_ONLY TRUE) - -add_library(${SIMDJSON_LIB_NAME} ${SIMDJSON_LIB_TYPE} ${SIMDJSON_SRC} ${SIMDJSON_INCLUDE} ${SIMDJSON_SRC_HEADERS}) - -target_include_directories(${SIMDJSON_LIB_NAME} - PUBLIC - $ - $ - $ -) - -install(TARGETS ${SIMDJSON_LIB_NAME} - EXPORT ${SIMDJSON_LIB_NAME}-config +install(TARGETS simdjson + EXPORT simdjson-config ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) -install(EXPORT ${SIMDJSON_LIB_NAME}-config - FILE ${SIMDJSON_LIB_NAME}-config.cmake - NAMESPACE ${SIMDJSON_LIB_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SIMDJSON_LIB_NAME} +install(EXPORT simdjson-config + FILE simdjson-config.cmake + 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_LIB_NAME} PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} - VERSION ${SIMDJSON_LIB_VERSION} - SOVERSION ${SIMDJSON_LIB_SOVERSION}) +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() @@ -121,12 +54,7 @@ if(MSVC AND (SIMDJSON_LIB_TYPE STREQUAL "SHARED")) 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_LIB_NAME} + set_target_properties(simdjson PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1) endif() -if(SIMDJSON_ENABLE_THREADS) - find_package(Threads REQUIRED) - target_link_libraries( ${SIMDJSON_LIB_NAME} Threads::Threads) -endif() - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fa2c524eb..b5352ed89 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ if(MSVC) - target_include_directories(${SIMDJSON_LIB_NAME} + target_include_directories(simdjson INTERFACE $ ) endif() @@ -24,7 +24,7 @@ target_compile_definitions(errortests PRIVATE JSON_TEST_PATH="${PROJECT_SOURCE_D ## This causes problems # add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp) -# target_link_libraries(singleheader ${SIMDJSON_LIB_NAME}) +# target_link_libraries(singleheader simdjson) # add_test(singleheader singleheader) if(MSVC)