Skip to content

Commit 4ec5648

Browse files
authored
Merge pull request simdjson#979 from simdjson/issue977
This removes git as a dependency to our CMake
2 parents 8f2a564 + 16f12f7 commit 4ec5648

File tree

8 files changed

+152
-86
lines changed

8 files changed

+152
-86
lines changed

.drone.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,29 @@ steps:
273273
- ASAN_OPTIONS="detect_leaks=0" ctest $CTEST_FLAGS -LE "acceptance|per_implementation" # Everything we haven't run yet, run now.
274274
---
275275
kind: pipeline
276+
name: ninja-clang9
277+
platform: { os: linux, arch: amd64 }
278+
steps:
279+
- name: Build and Test
280+
image: conanio/clang9
281+
user: root
282+
environment:
283+
CC: clang-9
284+
CXX: clang++-9
285+
BUILD_FLAGS: -- -j 4
286+
CMAKE_FLAGS: -GNinja -DSIMDJSON_BUILD_STATIC=ON
287+
CTEST_FLAGS: -j4 --output-on-failure
288+
CXXFLAGS: -stdlib=libc++
289+
commands:
290+
- apt-get update -qq
291+
- apt-get install -y cmake
292+
- mkdir build
293+
- cd build
294+
- cmake $CMAKE_FLAGS ..
295+
- cmake --build . $BUILD_FLAGS
296+
- ctest $CTEST_FLAGS
297+
---
298+
kind: pipeline
276299
name: libcpp-clang9
277300
platform: { os: linux, arch: amd64 }
278301
steps:

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ include(GNUInstallDirs)
1616
include(cmake/simdjson-flags.cmake)
1717
include(cmake/simdjson-user-cmakecache.cmake)
1818

19+
20+
1921
if(SIMDJSON_JUST_LIBRARY)
20-
MESSAGE( STATUS "Building just the library, omitting all tests, tools and benchmarks." )
22+
message( STATUS "Building just the library, omitting all tests, tools and benchmarks." )
2123
endif()
2224

2325
#
@@ -39,15 +41,15 @@ add_subdirectory(include)
3941
add_subdirectory(src)
4042
add_subdirectory(windows)
4143
if(NOT(SIMDJSON_JUST_LIBRARY))
42-
add_subdirectory(tools)
44+
add_subdirectory(dependencies) ## This needs to be before tools because of cxxopts
45+
add_subdirectory(tools) ## This needs to be before tests because of cxxopts
4346
add_subdirectory(singleheader)
4447
endif()
4548

4649
#
4750
# Compile tools / tests / benchmarks
4851
#
4952
if(NOT(SIMDJSON_JUST_LIBRARY))
50-
add_subdirectory(dependencies)
5153
add_subdirectory(tests)
5254
add_subdirectory(examples)
5355
add_subdirectory(benchmark)

benchmark/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ target_compile_definitions(parse_nonumberparsing PRIVATE SIMDJSON_SKIPNUMBERPARS
1414
add_executable(parse_nostringparsing parse.cpp)
1515
target_compile_definitions(parse_nostringparsing PRIVATE SIMDJSON_SKIPSTRINGPARSING)
1616

17-
if (SIMDJSON_GOOGLE_BENCHMARKS)
17+
if (TARGET benchmark::benchmark)
1818
link_libraries(benchmark::benchmark)
1919
add_executable(bench_parse_call bench_parse_call.cpp)
2020
add_executable(bench_dom_api bench_dom_api.cpp)
2121
endif()
2222

23-
if (SIMDJSON_COMPETITION)
23+
if (TARGET competition-all)
2424
add_executable(distinctuseridcompetition distinctuseridcompetition.cpp)
2525
target_link_libraries(distinctuseridcompetition competition-core)
2626
add_executable(minifiercompetition minifiercompetition.cpp)

benchmark/checkperf.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
# Clone the repository if it's not there
99
find_package(Git QUIET)
10-
if (Git_FOUND)
10+
if (SIMDJSON_IS_UNDER_GIT AND Git_FOUND AND (GIT_VERSION_STRING VERSION_GREATER "2.1.4") AND (NOT CMAKE_GENERATOR MATCHES Ninja) ) # We use "-C" which requires a recent git
11+
message(STATUS "Git is available and it is recent. We are enabling checkperf targets.")
1112
# sync_git_repository(myrepo ...) creates two targets:
1213
# myrepo - if the repo does not exist, creates and syncs it against the origin branch
1314
# update_myrepo - will update the repo against the origin branch (and create if needed)
@@ -91,5 +92,10 @@ if (Git_FOUND)
9192
set_property(TEST checkperf APPEND PROPERTY LABELS per_implementation)
9293
set_property(TEST checkperf APPEND PROPERTY DEPENDS parse perfdiff ${SIMDJSON_USER_CMAKECACHE})
9394
set_property(TEST checkperf PROPERTY RUN_SERIAL TRUE)
94-
95-
endif (Git_FOUND)
95+
else()
96+
if (CMAKE_GENERATOR MATCHES Ninja)
97+
message(STATUS "We disable the checkperf targets under Ninja.")
98+
else()
99+
message(STATUS "Either git is unavailable or else it is too old. We are disabling checkperf targets.")
100+
endif()
101+
endif ()

cmake/simdjson-flags.cmake

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF)
1+
2+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3+
message (STATUS "The simdjson repository appears to be standalone.")
4+
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" OFF)
5+
message (STATUS "By default, we attempt to build everything.")
6+
else()
7+
message (STATUS "The simdjson repository appears to be used as a subdirectory.")
8+
option(SIMDJSON_JUST_LIBRARY "Build just the library, omit tests, tools and benchmarks" ON)
9+
message (STATUS "By default, we just build the library.")
10+
endif()
11+
12+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
13+
set(SIMDJSON_IS_UNDER_GIT ON CACHE BOOL "Whether cmake is under git control")
14+
message( STATUS "The simdjson repository appears to be under git." )
15+
else()
16+
set(SIMDJSON_IS_UNDER_GIT OFF CACHE BOOL "Whether cmake is under git control")
17+
message( STATUS "The simdjson repository does not appear to be under git." )
18+
endif()
219

320
#
421
# Flags used by exes and by the simdjson library (project-wide flags)

dependencies/CMakeLists.txt

Lines changed: 85 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,88 @@
11
# Initializes a git submodule if it hasn't been initialized before
2-
# Does NOT attempt to update or otherwise modify git submodules that are already initialized.
3-
function(initialize_submodule DIRECTORY)
4-
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
5-
find_package(Git QUIET REQUIRED)
6-
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git does not exist. Initializing ${DIRECTORY} submodule ...")
7-
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}
8-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
9-
RESULT_VARIABLE GIT_EXIT_CODE)
10-
if(NOT GIT_EXIT_CODE EQUAL "0")
11-
message(FATAL_ERROR "${GIT_EXECUTABLE} submodule update --init dependencies/${DIRECTORY} failed with exit code ${GIT_EXIT_CODE}, please checkout submodules")
2+
3+
4+
find_package(Git QUIET) # We want the library to build even if git is missing
5+
if ((Git_FOUND) AND (SIMDJSON_IS_UNDER_GIT))
6+
message(STATUS "Git is available.")
7+
# Does NOT attempt to update or otherwise modify git submodules that are already initialized.
8+
function(initialize_submodule DIRECTORY)
9+
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git)
10+
message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}/.git does not exist. Initializing ${DIRECTORY} submodule ...")
11+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init ${CMAKE_CURRENT_SOURCE_DIR}/${DIRECTORY}
12+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
RESULT_VARIABLE GIT_EXIT_CODE)
14+
if(NOT GIT_EXIT_CODE EQUAL "0")
15+
message(FATAL_ERROR "${GIT_EXECUTABLE} submodule update --init dependencies/${DIRECTORY} failed with exit code ${GIT_EXIT_CODE}, please checkout submodules")
16+
endif()
1217
endif()
18+
endfunction(initialize_submodule)
19+
20+
if (SIMDJSON_GOOGLE_BENCHMARKS)
21+
option(BENCHMARK_ENABLE_TESTING OFF)
22+
set(BENCHMARK_ENABLE_TESTING OFF)
23+
option(BENCHMARK_ENABLE_INSTALL OFF)
24+
set(BENCHMARK_ENABLE_INSTALL OFF)
25+
initialize_submodule(benchmark)
26+
add_subdirectory(benchmark)
27+
endif()
28+
29+
if (SIMDJSON_COMPETITION)
30+
initialize_submodule(cJSON)
31+
add_library(competition-cJSON INTERFACE)
32+
target_include_directories(competition-cJSON INTERFACE cJSON)
33+
34+
initialize_submodule(fastjson)
35+
add_library(competition-fastjson INTERFACE)
36+
target_include_directories(competition-fastjson INTERFACE fastjson/src fastjson/include)
37+
38+
initialize_submodule(gason)
39+
add_library(competition-gason INTERFACE)
40+
target_include_directories(competition-gason INTERFACE gason/src)
41+
42+
initialize_submodule(jsmn)
43+
add_library(competition-jsmn INTERFACE)
44+
target_include_directories(competition-jsmn INTERFACE jsmn)
45+
46+
initialize_submodule(json)
47+
add_library(competition-json INTERFACE)
48+
target_include_directories(competition-json INTERFACE json/single_include)
49+
50+
initialize_submodule(json11)
51+
add_library(competition-json11 INTERFACE)
52+
target_include_directories(competition-json11 INTERFACE json11)
53+
54+
add_library(competition-jsoncppdist INTERFACE)
55+
target_include_directories(competition-jsoncppdist INTERFACE jsoncppdist)
56+
57+
initialize_submodule(rapidjson)
58+
add_library(competition-rapidjson INTERFACE)
59+
target_include_directories(competition-rapidjson INTERFACE rapidjson/include)
60+
61+
initialize_submodule(sajson)
62+
add_library(competition-sajson INTERFACE)
63+
target_include_directories(competition-sajson INTERFACE sajson/include)
64+
65+
initialize_submodule(ujson4c)
66+
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
67+
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
68+
69+
add_library(competition-core INTERFACE)
70+
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn)
71+
72+
add_library(competition-all INTERFACE)
73+
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
74+
endif()
75+
76+
initialize_submodule(cxxopts)
77+
message(STATUS "We acquired cxxopts and we are adding it as a library and target.")
78+
add_library(cxxopts INTERFACE)
79+
target_include_directories(cxxopts INTERFACE cxxopts/include)
80+
else()
81+
message(STATUS "Git is unavailable.")
82+
if(SIMDJSON_COMPETITION)
83+
message (STATUS "'SIMDJSON_COMPETITION' is requested, but we cannot download the remote repositories." )
84+
endif()
85+
if(SIMDJSON_GOOGLE_BENCHMARKS)
86+
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, but we cannot download the remote repositories." )
1387
endif()
14-
endfunction(initialize_submodule)
15-
16-
if (SIMDJSON_GOOGLE_BENCHMARKS)
17-
option(BENCHMARK_ENABLE_TESTING OFF)
18-
set(BENCHMARK_ENABLE_TESTING OFF)
19-
option(BENCHMARK_ENABLE_INSTALL OFF)
20-
set(BENCHMARK_ENABLE_INSTALL OFF)
21-
initialize_submodule(benchmark)
22-
add_subdirectory(benchmark)
23-
endif()
24-
25-
if (SIMDJSON_COMPETITION)
26-
initialize_submodule(cJSON)
27-
add_library(competition-cJSON INTERFACE)
28-
target_include_directories(competition-cJSON INTERFACE cJSON)
29-
30-
initialize_submodule(fastjson)
31-
add_library(competition-fastjson INTERFACE)
32-
target_include_directories(competition-fastjson INTERFACE fastjson/src fastjson/include)
33-
34-
initialize_submodule(gason)
35-
add_library(competition-gason INTERFACE)
36-
target_include_directories(competition-gason INTERFACE gason/src)
37-
38-
initialize_submodule(jsmn)
39-
add_library(competition-jsmn INTERFACE)
40-
target_include_directories(competition-jsmn INTERFACE jsmn)
41-
42-
initialize_submodule(json)
43-
add_library(competition-json INTERFACE)
44-
target_include_directories(competition-json INTERFACE json/single_include)
45-
46-
initialize_submodule(json11)
47-
add_library(competition-json11 INTERFACE)
48-
target_include_directories(competition-json11 INTERFACE json11)
49-
50-
add_library(competition-jsoncppdist INTERFACE)
51-
target_include_directories(competition-jsoncppdist INTERFACE jsoncppdist)
52-
53-
initialize_submodule(rapidjson)
54-
add_library(competition-rapidjson INTERFACE)
55-
target_include_directories(competition-rapidjson INTERFACE rapidjson/include)
56-
57-
initialize_submodule(sajson)
58-
add_library(competition-sajson INTERFACE)
59-
target_include_directories(competition-sajson INTERFACE sajson/include)
60-
61-
initialize_submodule(ujson4c)
62-
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
63-
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
64-
65-
add_library(competition-core INTERFACE)
66-
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn)
67-
68-
add_library(competition-all INTERFACE)
69-
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
70-
endif()
71-
72-
initialize_submodule(cxxopts)
73-
add_library(cxxopts INTERFACE)
74-
target_include_directories(cxxopts INTERFACE cxxopts/include)
88+
endif()

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ find_program(BASH bash)
6464

6565

6666
# Script tests
67-
if (BASH AND (NOT MSVC)) # The scripts are not robust enough to run under Windows even if bash is available
67+
if (BASH AND (NOT MSVC) AND (TARGET json2json)) # The scripts are not robust enough to run under Windows even if bash is available
6868
#
6969
# json2json test
7070
#

tools/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
link_libraries(simdjson simdjson-internal-flags simdjson-windows-headers cxxopts)
2-
3-
add_executable(json2json json2json.cpp)
4-
add_executable(jsonstats jsonstats.cpp)
5-
add_executable(minify minify.cpp)
1+
if(TARGET cxxopts) # we only build the tools if cxxopts is available
2+
message(STATUS "We have cxxopts as a dependency and we are buiding the tools (e.g., json2json).")
3+
link_libraries(simdjson simdjson-internal-flags simdjson-windows-headers cxxopts)
4+
add_executable(json2json json2json.cpp)
5+
add_executable(jsonstats jsonstats.cpp)
6+
add_executable(minify minify.cpp)
7+
else()
8+
message(STATUS "We are missing cxxopts as a dependency so the tools (e.g., json2json) are omitted.")
9+
endif()

0 commit comments

Comments
 (0)