Skip to content

Commit c805fc2

Browse files
authored
Remove git modules (simdjson#1258)
* Bump minimum CMake version * Remove unnecessary git checks * Move benchmark options where they are used * Declare helper functions for dependencies The custom solution here is tailored for fast configure times, but only works for dependencies on Github. * Import dependencies using the declared commands * Remove git submodules * Call target_link_libraries properly target_link_libraries must not be called without a requirement specifier. * Fix includes for competition Co-authored-by: friendlyanon <friendlyanon@users.noreply.github.com>
1 parent 218c274 commit c805fc2

24 files changed

+185
-200
lines changed

.gitmodules

Lines changed: 0 additions & 42 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.9) # CMP0069 NEW
1+
cmake_minimum_required(VERSION 3.13)
22

33
project(simdjson
44
DESCRIPTION "Parsing gigabytes of JSON per second"

benchmark/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ link_libraries(simdjson-windows-headers test-data)
44

55
if (TARGET benchmark::benchmark)
66
add_executable(bench_sax bench_sax.cpp)
7-
target_link_libraries(bench_sax simdjson-internal-flags simdjson-include-source benchmark::benchmark)
7+
target_link_libraries(bench_sax PRIVATE simdjson-internal-flags simdjson-include-source benchmark::benchmark)
88
endif (TARGET benchmark::benchmark)
99

1010
link_libraries(simdjson simdjson-flags)
@@ -24,19 +24,19 @@ target_compile_definitions(parse_nostringparsing PRIVATE SIMDJSON_SKIPSTRINGPARS
2424

2525
if (TARGET competition-all)
2626
add_executable(distinctuseridcompetition distinctuseridcompetition.cpp)
27-
target_link_libraries(distinctuseridcompetition competition-core)
27+
target_link_libraries(distinctuseridcompetition PRIVATE competition-core)
2828

2929
add_executable(minifiercompetition minifiercompetition.cpp)
30-
target_link_libraries(minifiercompetition competition-core)
30+
target_link_libraries(minifiercompetition PRIVATE competition-core)
3131

3232
add_executable(parseandstatcompetition parseandstatcompetition.cpp)
33-
target_link_libraries(parseandstatcompetition competition-core)
33+
target_link_libraries(parseandstatcompetition PRIVATE competition-core)
3434

3535
add_executable(parsingcompetition parsingcompetition.cpp)
36-
target_link_libraries(parsingcompetition competition-core)
36+
target_link_libraries(parsingcompetition PRIVATE competition-core)
3737

3838
add_executable(allparsingcompetition parsingcompetition.cpp)
39-
target_link_libraries(allparsingcompetition competition-all)
39+
target_link_libraries(allparsingcompetition PRIVATE competition-all)
4040
target_compile_definitions(allparsingcompetition PRIVATE ALLPARSER)
4141
endif()
4242

benchmark/checkperf.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Clone the repository if it's not there
99
find_package(Git QUIET)
10-
if (SIMDJSON_IS_UNDER_GIT AND SIMDJSON_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
10+
if (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
1111
message(STATUS "Git is available and it is recent. We are enabling checkperf targets.")
1212
# sync_git_repository(myrepo ...) creates two targets:
1313
# myrepo - if the repo does not exist, creates and syncs it against the origin branch

benchmark/parsingcompetition.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,23 @@ using json = nlohmann::json;
4040

4141
#ifdef ALLPARSER
4242

43-
#include "fastjson.cpp"
44-
#include "fastjson_dom.cpp"
45-
#include "gason.cpp"
43+
#include "fastjson/core.h"
44+
#include "fastjson/dom.h"
45+
#include "fastjson/fastjson.h"
46+
47+
#include "gason.h"
48+
49+
#include "json11.hpp"
4650

47-
#include "json11.cpp"
48-
extern "C" {
49-
#include "cJSON.c"
5051
#include "cJSON.h"
51-
#include "jsmn.c"
52+
5253
#include "jsmn.h"
54+
5355
#include "ujdecode.h"
54-
#include "ultrajsondec.c"
56+
extern "C" {
57+
#include "ultrajson.h"
5558
}
5659

57-
#include "jsoncpp.cpp"
5860
#include "json/json.h"
5961

6062
#endif

cmake/simdjson-flags.cmake

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ else()
99
message (STATUS "By default, we just build the library.")
1010
endif()
1111

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()
19-
2012
#
2113
# Flags used by exes and by the simdjson library (project-wide flags)
2214
#
@@ -50,12 +42,6 @@ else()
5042
option(SIMDJSON_BUILD_STATIC "Build a static library" OFF) # turning it on disables the production of a dynamic library
5143
option(SIMDJSON_USE_LIBCPP "Use the libc++ library" OFF)
5244
endif()
53-
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
54-
55-
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON)
56-
if(SIMDJSON_COMPETITION)
57-
message(STATUS "Using SIMDJSON_GOOGLE_BENCHMARKS")
58-
endif()
5945

6046
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake")
6147

@@ -185,8 +171,6 @@ endif(SIMDJSON_ONDEMAND_SAFETY_RAILS)
185171

186172
option(SIMDJSON_BASH "Allow usage of bash within CMake" ON)
187173

188-
option(SIMDJSON_GIT "Allow usage of git within CMake" ON)
189-
190174
option(SIMDJSON_EXCEPTIONS "Enable simdjson's exception-throwing interface" ON)
191175
if(NOT SIMDJSON_EXCEPTIONS)
192176
message(STATUS "simdjson exception interface turned off. Code that does not check error codes will not compile.")

dependencies/CMakeLists.txt

Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,107 @@
1-
# Initializes a git submodule if it hasn't been initialized before
2-
3-
4-
find_package(Git QUIET) # We want the library to build even if git is missing
5-
if ((Git_FOUND) AND SIMDJSON_GIT 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()
17-
endif()
18-
endfunction(initialize_submodule)
19-
20-
if (SIMDJSON_GOOGLE_BENCHMARKS)
21-
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, configuring..." )
22-
option(BENCHMARK_ENABLE_TESTING OFF)
23-
set(BENCHMARK_ENABLE_TESTING OFF)
24-
option(BENCHMARK_ENABLE_INSTALL OFF)
25-
set(BENCHMARK_ENABLE_INSTALL OFF)
26-
initialize_submodule(benchmark)
27-
add_subdirectory(benchmark)
28-
endif()
1+
include(import.cmake)
2+
3+
option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON)
4+
option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON)
5+
6+
if(SIMDJSON_GOOGLE_BENCHMARKS)
7+
set_off(BENCHMARK_ENABLE_TESTING)
8+
set_off(BENCHMARK_ENABLE_INSTALL)
9+
10+
import_dependency(google_benchmarks google/benchmark 8982e1e)
11+
add_dependency(google_benchmarks)
12+
endif()
2913

30-
if (SIMDJSON_COMPETITION)
31-
initialize_submodule(cJSON)
32-
add_library(competition-cJSON INTERFACE)
33-
target_include_directories(competition-cJSON INTERFACE cJSON)
34-
35-
initialize_submodule(fastjson)
36-
add_library(competition-fastjson INTERFACE)
37-
target_include_directories(competition-fastjson INTERFACE fastjson/src fastjson/include)
38-
39-
initialize_submodule(gason)
40-
add_library(competition-gason INTERFACE)
41-
target_include_directories(competition-gason INTERFACE gason/src)
42-
43-
initialize_submodule(jsmn)
44-
add_library(competition-jsmn INTERFACE)
45-
target_include_directories(competition-jsmn INTERFACE jsmn)
46-
47-
initialize_submodule(json)
48-
add_library(competition-json INTERFACE)
49-
target_include_directories(competition-json INTERFACE json/single_include)
50-
51-
initialize_submodule(json11)
52-
add_library(competition-json11 INTERFACE)
53-
target_include_directories(competition-json11 INTERFACE json11)
54-
55-
add_library(competition-jsoncppdist INTERFACE)
56-
target_include_directories(competition-jsoncppdist INTERFACE jsoncppdist)
57-
58-
initialize_submodule(rapidjson)
59-
add_library(competition-rapidjson INTERFACE)
60-
target_include_directories(competition-rapidjson INTERFACE rapidjson/include)
61-
62-
initialize_submodule(sajson)
63-
add_library(competition-sajson INTERFACE)
64-
target_include_directories(competition-sajson INTERFACE sajson/include)
65-
66-
initialize_submodule(ujson4c)
67-
add_library(competition-ujson4c ujson4c/src/ujdecode.c)
68-
target_include_directories(competition-ujson4c PUBLIC ujson4c/3rdparty ujson4c/src)
69-
70-
# Boost JSON is not compatible with some clang/libc++ configurations.
71-
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
72-
initialize_submodule(boost.json)
73-
add_library(boostjson boost.json/src/src.cpp)
74-
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
75-
target_include_directories(boostjson PUBLIC boost.json/include)
76-
endif()
77-
78-
initialize_submodule(yyjson)
79-
add_library(yyjson yyjson/src/yyjson.c)
80-
target_include_directories(yyjson PUBLIC yyjson/src)
81-
82-
add_library(competition-core INTERFACE)
83-
# Boost JSON is not compatible with some clang/libc++ configurations.
84-
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
85-
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn yyjson)
86-
else()
87-
target_link_libraries(competition-core INTERFACE competition-json competition-rapidjson competition-sajson competition-cJSON competition-jsmn boostjson yyjson)
88-
endif()
89-
90-
add_library(competition-all INTERFACE)
91-
target_link_libraries(competition-all INTERFACE competition-core competition-jsoncppdist competition-json11 competition-fastjson competition-gason competition-ujson4c)
14+
# This prevents variables declared with set() from unnecessarily escaping and
15+
# should not be called more than once
16+
function(competition_scope_)
17+
# Boost JSON is not compatible with some clang/libc++ configurations.
18+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
19+
import_dependency(boostjson CPPAlliance/json a0983f7)
20+
add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp")
21+
target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE)
22+
target_include_directories(boostjson SYSTEM PUBLIC
23+
"${boostjson_SOURCE_DIR}/include")
9224
endif()
9325

94-
initialize_submodule(cxxopts)
95-
message(STATUS "We acquired cxxopts and we are adding it as a library and target.")
96-
add_library(cxxopts INTERFACE)
97-
target_include_directories(cxxopts INTERFACE cxxopts/include)
98-
else()
99-
message(STATUS "Git is unavailable.")
100-
if(SIMDJSON_COMPETITION)
101-
message (STATUS "'SIMDJSON_COMPETITION' is requested, but we cannot download the remote repositories." )
26+
import_dependency(cjson DaveGamble/cJSON c69134d)
27+
add_library(cjson STATIC "${cjson_SOURCE_DIR}/cJSON.c")
28+
target_include_directories(cjson SYSTEM PUBLIC "${cjson_SOURCE_DIR}")
29+
30+
import_dependency(fastjson mikeando/fastjson 485f994)
31+
add_library(fastjson STATIC
32+
"${fastjson_SOURCE_DIR}/src/fastjson.cpp"
33+
"${fastjson_SOURCE_DIR}/src/fastjson2.cpp"
34+
"${fastjson_SOURCE_DIR}/src/fastjson_dom.cpp")
35+
target_include_directories(fastjson SYSTEM PUBLIC
36+
"${fastjson_SOURCE_DIR}/include")
37+
38+
import_dependency(gason vivkin/gason 7aee524)
39+
add_library(gason STATIC "${gason_SOURCE_DIR}/src/gason.cpp")
40+
target_include_directories(gason SYSTEM PUBLIC "${gason_SOURCE_DIR}/src")
41+
42+
import_dependency(jsmn zserge/jsmn 18e9fe4)
43+
add_library(jsmn STATIC "${jsmn_SOURCE_DIR}/jsmn.c")
44+
target_include_directories(jsmn SYSTEM PUBLIC "${jsmn_SOURCE_DIR}")
45+
46+
message(STATUS "Importing json (nlohmann/json@v3.9.1)")
47+
set(nlohmann_json_SOURCE_DIR "${dep_root}/json")
48+
if(NOT EXISTS "${nlohmann_json_SOURCE_DIR}")
49+
file(DOWNLOAD
50+
"https://github.com/nlohmann/json/releases/download/v3.9.1/json.hpp"
51+
"${nlohmann_json_SOURCE_DIR}/nlohmann/json.hpp")
10252
endif()
103-
if(SIMDJSON_GOOGLE_BENCHMARKS)
104-
message (STATUS "'SIMDJSON_GOOGLE_BENCHMARKS' is requested, but we cannot download the remote repositories." )
53+
add_library(nlohmann_json INTERFACE)
54+
target_include_directories(nlohmann_json SYSTEM INTERFACE "${nlohmann_json_SOURCE_DIR}")
55+
56+
import_dependency(json11 dropbox/json11 ec4e452)
57+
add_library(json11 STATIC "${json11_SOURCE_DIR}/json11.cpp")
58+
target_include_directories(json11 SYSTEM PUBLIC "${json11_SOURCE_DIR}")
59+
60+
set(jsoncpp_SOURCE_DIR "${simdjson_SOURCE_DIR}/dependencies/jsoncppdist")
61+
add_library(jsoncpp STATIC "${jsoncpp_SOURCE_DIR}/jsoncpp.cpp")
62+
target_include_directories(jsoncpp SYSTEM PUBLIC "${jsoncpp_SOURCE_DIR}")
63+
64+
import_dependency(rapidjson Tencent/rapidjson b32cd94)
65+
add_library(rapidjson INTERFACE)
66+
target_compile_definitions(rapidjson INTERFACE RAPIDJSON_HAS_STDSTRING)
67+
target_include_directories(rapidjson SYSTEM INTERFACE
68+
"${rapidjson_SOURCE_DIR}/include")
69+
70+
import_dependency(sajson chadaustin/sajson 2dcfd35)
71+
add_library(sajson INTERFACE)
72+
target_compile_definitions(sajson INTERFACE SAJSON_UNSORTED_OBJECT_KEYS)
73+
target_include_directories(sajson SYSTEM INTERFACE
74+
"${sajson_SOURCE_DIR}/include")
75+
76+
import_dependency(ujson4c esnme/ujson4c e14f3fd)
77+
add_library(ujson4c STATIC
78+
"${ujson4c_SOURCE_DIR}/src/ujdecode.c"
79+
"${ujson4c_SOURCE_DIR}/3rdparty/ultrajsondec.c")
80+
target_include_directories(ujson4c SYSTEM PUBLIC
81+
"${ujson4c_SOURCE_DIR}/src"
82+
"${ujson4c_SOURCE_DIR}/3rdparty")
83+
84+
import_dependency(yyjson ibireme/yyjson aa33ec5)
85+
add_library(yyjson STATIC "${yyjson_SOURCE_DIR}/src/yyjson.c")
86+
target_include_directories(yyjson SYSTEM PUBLIC "${yyjson_SOURCE_DIR}/src")
87+
88+
add_library(competition-core INTERFACE)
89+
target_link_libraries(competition-core INTERFACE nlohmann_json rapidjson sajson cjson jsmn yyjson)
90+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
91+
target_link_libraries(competition-core INTERFACE boostjson)
10592
endif()
93+
94+
add_library(competition-all INTERFACE)
95+
target_link_libraries(competition-all INTERFACE competition-core jsoncpp json11 fastjson gason ujson4c)
96+
endfunction()
97+
98+
if(SIMDJSON_COMPETITION)
99+
competition_scope_()
106100
endif()
101+
102+
set_off(CXXOPTS_BUILD_EXAMPLES)
103+
set_off(CXXOPTS_BUILD_TESTS)
104+
set_off(CXXOPTS_ENABLE_INSTALL)
105+
106+
import_dependency(cxxopts jarro2783/cxxopts 794c975)
107+
add_dependency(cxxopts)

dependencies/benchmark

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/boost.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/cJSON

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/cxxopts

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/fastjson

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/gason

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)