|
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() |
29 | 13 |
|
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") |
92 | 24 | endif()
|
93 | 25 |
|
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") |
102 | 52 | 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) |
105 | 92 | 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_() |
106 | 100 | 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) |
0 commit comments