From 91b07ba07598ea64d5bd5a19aab825690cf0aba7 Mon Sep 17 00:00:00 2001 From: friendlyanon <1736896+friendlyanon@users.noreply.github.com> Date: Mon, 14 Dec 2020 01:07:29 +0100 Subject: [PATCH] Allow build without download (#1334) * Add option for downloading dependencies * Format the boost json import code Co-authored-by: friendlyanon --- dependencies/CMakeLists.txt | 46 ++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt index 51ab3a31..4ef9bfbb 100644 --- a/dependencies/CMakeLists.txt +++ b/dependencies/CMakeLists.txt @@ -1,7 +1,14 @@ +include(CMakeDependentOption) include(import.cmake) -option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON) -option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON) +option(SIMDJSON_ALLOW_DOWNLOADS + "Allow dependencies to be downloaded during configure time" + ON) + +cmake_dependent_option(SIMDJSON_COMPETITION "Compile competitive benchmarks" ON + SIMDJSON_ALLOW_DOWNLOADS OFF) +cmake_dependent_option(SIMDJSON_GOOGLE_BENCHMARKS "compile the Google Benchmark benchmarks" ON + SIMDJSON_ALLOW_DOWNLOADS OFF) if(SIMDJSON_GOOGLE_BENCHMARKS) set_off(BENCHMARK_ENABLE_TESTING) @@ -16,13 +23,21 @@ endif() function(competition_scope_) # boost json in standalone mode requires C++17 string_view include(CheckCXXSourceCompiles) - check_cxx_source_compiles("#include \n#if __cpp_lib_string_view < 201606\n#error no string view support\n#endif\nint main(){}" USE_BOOST_JSON) + check_cxx_source_compiles([[ +#include + +#if __cpp_lib_string_view < 201606 +# error no string view support +#endif + +int main() {} +]] USE_BOOST_JSON) if(USE_BOOST_JSON) - import_dependency(boostjson boostorg/json ee8d72d8502b409b5561200299cad30ccdb91415) - add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp") - target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE) - target_include_directories(boostjson SYSTEM PUBLIC - "${boostjson_SOURCE_DIR}/include") + import_dependency(boostjson boostorg/json ee8d72d) + add_library(boostjson STATIC "${boostjson_SOURCE_DIR}/src/src.cpp") + target_compile_definitions(boostjson PUBLIC BOOST_JSON_STANDALONE) + target_include_directories(boostjson SYSTEM PUBLIC + "${boostjson_SOURCE_DIR}/include") endif() import_dependency(cjson DaveGamble/cJSON c69134d) @@ -102,9 +117,14 @@ if(SIMDJSON_COMPETITION) competition_scope_() endif() -set_off(CXXOPTS_BUILD_EXAMPLES) -set_off(CXXOPTS_BUILD_TESTS) -set_off(CXXOPTS_ENABLE_INSTALL) +cmake_dependent_option(SIMDJSON_CXXOPTS "Download cxxopts (necessary for tools)" ON + SIMDJSON_ALLOW_DOWNLOADS OFF) -import_dependency(cxxopts jarro2783/cxxopts 794c975) -add_dependency(cxxopts) +if(SIMDJSON_CXXOPTS) + set_off(CXXOPTS_BUILD_EXAMPLES) + set_off(CXXOPTS_BUILD_TESTS) + set_off(CXXOPTS_ENABLE_INSTALL) + + import_dependency(cxxopts jarro2783/cxxopts 794c975) + add_dependency(cxxopts) +endif()