Make threads optional in the cmake build (#376)

Only the simdjson library should optionally depend on threads,
the executables that link to simdjson will get the dependency
indirectly.

* add option for controlling threads (default is on)
* add CI testing with threading on/off for msvc, gcc and clang
* fix an unrelated copy paste comment error in the cirlce ci build conf
This commit is contained in:
Paul Dreik 2019-11-22 21:51:46 +01:00 committed by GitHub
parent 6e5178efc4
commit 6d14afd80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 12 deletions

View File

@ -12,11 +12,18 @@ platform:
environment:
matrix:
- SIMDJSON_BUILD_STATIC: "OFF"
THREADS: "ON"
- SIMDJSON_BUILD_STATIC: "OFF"
THREADS: "OFF"
- SIMDJSON_BUILD_STATIC: "ON"
THREADS: "ON"
# - SIMDJSON_BUILD_STATIC: "ON"
# THREADS: "OFF"
build_script:
- mkdir build
- cd build
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 ..
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DSIMDJSON_ENABLE_THREADS="$env:THREADS" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 ..
- cmake --build .
- ctest --verbose --output-on-failure

View File

@ -37,6 +37,28 @@ commands:
jobs:
gcc-avx-unthreaded:
description: Build, run tests and check performance on GCC 7 and AVX 2 *without* threads
executor: gcc7
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
steps: [ cmake_test ]
gcc-avx-threaded:
description: Build, run tests and check performance on GCC 7 and AVX 2 with threads
executor: gcc7
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=ON }
steps: [ cmake_test ]
clang-avx-unthreaded:
description: Build, run tests and check performance on Clang 6 and AVX 2 *without* threads
executor: clang6
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
steps: [ init_clang6, cmake_test ]
clang-avx-threaded:
description: Build, run tests and check performance on Clang 6 and AVX 2 with threads
executor: clang6
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=ON }
steps: [ init_clang6, cmake_test ]
gcc-avx:
description: Build, run tests and check performance on GCC 7 and AVX 2
executor: gcc7
@ -99,22 +121,22 @@ jobs:
steps: [ init_clang6, cmake_test ]
clang-sse:
description: Build, run tests and check performance on GCC 7 and SSE 4.2
description: Build, run tests and check performance on Clang 6 and SSE 4.2
executor: clang6
environment: { ARCHFLAGS: -march=nehalem }
steps: [ init_clang6, make_test ]
clang-sse-dynamic:
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake dynamic build
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake dynamic build
executor: clang6
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF }
steps: [ init_clang6, cmake_test ]
clang-sse-static:
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake static build
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake static build
executor: clang6
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=ON }
steps: [ init_clang6, cmake_test ]
clang-sse-sanitize:
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake sanitize build
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake sanitize build
executor: clang6
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_SANITIZE=ON }
steps: [ init_clang6, cmake_test ]
@ -139,6 +161,10 @@ workflows:
- clang-sse-dynamic
- clang-sse-static
- clang-sse-sanitize
- gcc-avx-threaded
- gcc-avx-unthreaded
- clang-avx-threaded
- clang-avx-unthreaded
# TODO add windows: https://circleci.com/docs/2.0/configuration-reference/#windows

View File

@ -38,11 +38,8 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
find_package(CTargets)
find_package(Options)
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
option(SIMDJSON_ENABLE_THREADS "enable threaded operation" ON)
install(DIRECTORY include/${SIMDJSON_LIB_NAME} DESTINATION include)
set (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")

View File

@ -8,6 +8,4 @@ add_cpp_benchmark(parse)
add_cpp_benchmark(statisticalmodel)
add_cpp_benchmark(parse_stream)
target_link_libraries(parse_stream Threads::Threads)
add_executable(perfdiff perfdiff.cpp)

View File

@ -100,3 +100,9 @@ if(MSVC AND (SIMDJSON_LIB_TYPE STREQUAL "SHARED"))
set_target_properties(${SIMDJSON_LIB_NAME}
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
endif()
if(SIMDJSON_ENABLE_THREADS)
find_package(Threads REQUIRED)
target_link_libraries( ${SIMDJSON_LIB_NAME} Threads::Threads)
endif()

View File

@ -10,7 +10,6 @@ add_cpp_test(jsonstream_test)
add_cpp_test(pointercheck)
add_cpp_test(integer_tests)
target_link_libraries(jsonstream_test Threads::Threads)
## This causes problems
# add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp)
# target_compile_definitions(singleheader PRIVATE JSON_TEST_PATH="${PROJECT_SOURCE_DIR}/jsonexamples/twitter.json")