Skip to content

Commit 6d14afd

Browse files
authored
Make threads optional in the cmake build (simdjson#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
1 parent 6e5178e commit 6d14afd

6 files changed

Lines changed: 45 additions & 12 deletions

File tree

.appveyor.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ platform:
1212
environment:
1313
matrix:
1414
- SIMDJSON_BUILD_STATIC: "OFF"
15+
THREADS: "ON"
16+
- SIMDJSON_BUILD_STATIC: "OFF"
17+
THREADS: "OFF"
1518
- SIMDJSON_BUILD_STATIC: "ON"
19+
THREADS: "ON"
20+
# - SIMDJSON_BUILD_STATIC: "ON"
21+
# THREADS: "OFF"
1622

1723
build_script:
1824
- mkdir build
1925
- cd build
20-
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 ..
26+
- ps: cmake -DSIMDJSON_BUILD_STATIC="$env:SIMDJSON_BUILD_STATIC" -DSIMDJSON_ENABLE_THREADS="$env:THREADS" -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64 ..
2127
- cmake --build .
2228
- ctest --verbose --output-on-failure
29+

.circleci/config.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ commands:
3737

3838
jobs:
3939

40+
gcc-avx-unthreaded:
41+
description: Build, run tests and check performance on GCC 7 and AVX 2 *without* threads
42+
executor: gcc7
43+
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
44+
steps: [ cmake_test ]
45+
gcc-avx-threaded:
46+
description: Build, run tests and check performance on GCC 7 and AVX 2 with threads
47+
executor: gcc7
48+
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=ON }
49+
steps: [ cmake_test ]
50+
51+
clang-avx-unthreaded:
52+
description: Build, run tests and check performance on Clang 6 and AVX 2 *without* threads
53+
executor: clang6
54+
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=OFF }
55+
steps: [ init_clang6, cmake_test ]
56+
clang-avx-threaded:
57+
description: Build, run tests and check performance on Clang 6 and AVX 2 with threads
58+
executor: clang6
59+
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_ENABLE_THREADS=ON }
60+
steps: [ init_clang6, cmake_test ]
61+
4062
gcc-avx:
4163
description: Build, run tests and check performance on GCC 7 and AVX 2
4264
executor: gcc7
@@ -99,22 +121,22 @@ jobs:
99121
steps: [ init_clang6, cmake_test ]
100122

101123
clang-sse:
102-
description: Build, run tests and check performance on GCC 7 and SSE 4.2
124+
description: Build, run tests and check performance on Clang 6 and SSE 4.2
103125
executor: clang6
104126
environment: { ARCHFLAGS: -march=nehalem }
105127
steps: [ init_clang6, make_test ]
106128
clang-sse-dynamic:
107-
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake dynamic build
129+
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake dynamic build
108130
executor: clang6
109131
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF }
110132
steps: [ init_clang6, cmake_test ]
111133
clang-sse-static:
112-
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake static build
134+
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake static build
113135
executor: clang6
114136
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=ON }
115137
steps: [ init_clang6, cmake_test ]
116138
clang-sse-sanitize:
117-
description: Build, run tests and check performance on GCC 7 and SSE 4.2 with a cmake sanitize build
139+
description: Build, run tests and check performance on Clang 6 and SSE 4.2 with a cmake sanitize build
118140
executor: clang6
119141
environment: { CMAKE_TEST_FLAGS: -DSIMDJSON_BUILD_STATIC=OFF -DSIMDJSON_SANITIZE=ON }
120142
steps: [ init_clang6, cmake_test ]
@@ -139,6 +161,10 @@ workflows:
139161
- clang-sse-dynamic
140162
- clang-sse-static
141163
- clang-sse-sanitize
164+
- gcc-avx-threaded
165+
- gcc-avx-unthreaded
166+
- clang-avx-threaded
167+
- clang-avx-unthreaded
142168

143169
# TODO add windows: https://circleci.com/docs/2.0/configuration-reference/#windows
144170

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
3838

3939
find_package(CTargets)
4040
find_package(Options)
41-
find_package(Threads REQUIRED)
4241

43-
if(CMAKE_USE_PTHREADS_INIT)
44-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
45-
endif()
42+
option(SIMDJSON_ENABLE_THREADS "enable threaded operation" ON)
4643

4744
install(DIRECTORY include/${SIMDJSON_LIB_NAME} DESTINATION include)
4845
set (TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jsonchecker/")

benchmark/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ add_cpp_benchmark(parse)
88
add_cpp_benchmark(statisticalmodel)
99
add_cpp_benchmark(parse_stream)
1010

11-
target_link_libraries(parse_stream Threads::Threads)
12-
1311
add_executable(perfdiff perfdiff.cpp)

src/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ if(MSVC AND (SIMDJSON_LIB_TYPE STREQUAL "SHARED"))
100100
set_target_properties(${SIMDJSON_LIB_NAME}
101101
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS 1)
102102
endif()
103+
104+
if(SIMDJSON_ENABLE_THREADS)
105+
find_package(Threads REQUIRED)
106+
target_link_libraries( ${SIMDJSON_LIB_NAME} Threads::Threads)
107+
endif()
108+

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_cpp_test(jsonstream_test)
1010
add_cpp_test(pointercheck)
1111
add_cpp_test(integer_tests)
1212

13-
target_link_libraries(jsonstream_test Threads::Threads)
1413
## This causes problems
1514
# add_executable(singleheader ./singleheadertest.cpp ${PROJECT_SOURCE_DIR}/singleheader/simdjson.cpp)
1615
# target_compile_definitions(singleheader PRIVATE JSON_TEST_PATH="${PROJECT_SOURCE_DIR}/jsonexamples/twitter.json")

0 commit comments

Comments
 (0)