From 0be4d4c4b53a814f20e162418de5070e14c792bd Mon Sep 17 00:00:00 2001 From: andrejlevkovitch Date: Fri, 22 Sep 2023 16:12:57 +0200 Subject: [PATCH] do not fetch nlohmann_json if it already added in main project (#287) --- CMakeLists.txt | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b81049..02a2dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,26 +80,28 @@ endif () ]==============================================================================================] set(fetch_packages "") -# Fetch/Find nlohmann_json -# TODO: Remove when bumping cmake >= 3.24 -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) - FetchContent_Declare(nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG ${JSON_FETCH_VERSION} - FIND_PACKAGE_ARGS - ) - list(APPEND fetch_packages nlohmann_json) -else () - # Try to get system installed version - find_package(nlohmann_json QUIET) - if (NOT nlohmann_json_FOUND) - # If failed fetch the desired version - FetchContent_Declare(nlohmann_json - GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG ${JSON_FETCH_VERSION} - ) - list(APPEND fetch_packages nlohmann_json) - endif () +if (NOT TARGET nlohmann_json) + # Fetch/Find nlohmann_json + # TODO: Remove when bumping cmake >= 3.24 + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) + FetchContent_Declare(nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG ${JSON_FETCH_VERSION} + FIND_PACKAGE_ARGS + ) + list(APPEND fetch_packages nlohmann_json) + else () + # Try to get system installed version + find_package(nlohmann_json QUIET) + if (NOT nlohmann_json_FOUND) + # If failed fetch the desired version + FetchContent_Declare(nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG ${JSON_FETCH_VERSION} + ) + list(APPEND fetch_packages nlohmann_json) + endif () + endif () endif () # Handle configure flags