From 0dbebd008c04d266dc41c4bec8280a0744fd5130 Mon Sep 17 00:00:00 2001 From: Francis Laniel Date: Wed, 13 Apr 2022 18:01:11 +0100 Subject: [PATCH] cmake: Check USE_BUNDLED_DEPS before getting nlohmann-json. Upstream: https://github.com/draios/sysdig/pull/1869 Signed-off-by: Francis Laniel --- cmake/modules/nlohmann-json.cmake | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/cmake/modules/nlohmann-json.cmake b/cmake/modules/nlohmann-json.cmake index bb1279d7..feb0f071 100644 --- a/cmake/modules/nlohmann-json.cmake +++ b/cmake/modules/nlohmann-json.cmake @@ -16,13 +16,22 @@ # limitations under the License. # -set(NJSON_SRC "${PROJECT_BINARY_DIR}/njson-prefix/src/njson") -message(STATUS "Using bundled nlohmann-json in '${NJSON_SRC}'") -set(NJSON_INCLUDE_DIR "${NJSON_SRC}/single_include") -ExternalProject_Add( - njson - URL "https://github.com/nlohmann/json/archive/v3.3.0.tar.gz" - URL_HASH "SHA256=2fd1d207b4669a7843296c41d3b6ac5b23d00dec48dba507ba051d14564aa801" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "") +if(NOT USE_BUNDLED_DEPS) + find_path(NJSON_INCLUDE_DIR NAMES nlohmann/json.hpp) + if(NJSON_INCLUDE_DIR) + message(STATUS "Found njson: include: ${NJSON_INCLUDE_DIR}") + else() + message(FATAL_ERROR "Couldn't find system njson") + endif() +else() + set(NJSON_SRC "${PROJECT_BINARY_DIR}/njson-prefix/src/njson") + message(STATUS "Using bundled nlohmann-json in '${NJSON_SRC}'") + set(NJSON_INCLUDE_DIR "${NJSON_SRC}/single_include") + ExternalProject_Add( + njson + URL "https://github.com/nlohmann/json/archive/v3.3.0.tar.gz" + URL_HASH "SHA256=2fd1d207b4669a7843296c41d3b6ac5b23d00dec48dba507ba051d14564aa801" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") +endif() -- 2.25.1