do not fetch nlohmann_json if it already added in main project

This commit is contained in:
andrejlevkovitch 2023-07-14 17:03:59 +02:00
parent f4194d7e24
commit 1b3ded6276

View File

@ -80,26 +80,28 @@ endif ()
]==============================================================================================] ]==============================================================================================]
set(fetch_packages "") set(fetch_packages "")
# Fetch/Find nlohmann_json if (NOT TARGET nlohmann_json)
# TODO: Remove when bumping cmake >= 3.24 # Fetch/Find nlohmann_json
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) # TODO: Remove when bumping cmake >= 3.24
FetchContent_Declare(nlohmann_json if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
GIT_REPOSITORY https://github.com/nlohmann/json FetchContent_Declare(nlohmann_json
GIT_TAG ${JSON_FETCH_VERSION} GIT_REPOSITORY https://github.com/nlohmann/json
FIND_PACKAGE_ARGS GIT_TAG ${JSON_FETCH_VERSION}
) FIND_PACKAGE_ARGS
list(APPEND fetch_packages nlohmann_json) )
else () list(APPEND fetch_packages nlohmann_json)
# Try to get system installed version else ()
find_package(nlohmann_json QUIET) # Try to get system installed version
if (NOT nlohmann_json_FOUND) find_package(nlohmann_json QUIET)
# If failed fetch the desired version if (NOT nlohmann_json_FOUND)
FetchContent_Declare(nlohmann_json # If failed fetch the desired version
GIT_REPOSITORY https://github.com/nlohmann/json FetchContent_Declare(nlohmann_json
GIT_TAG ${JSON_FETCH_VERSION} GIT_REPOSITORY https://github.com/nlohmann/json
) GIT_TAG ${JSON_FETCH_VERSION}
list(APPEND fetch_packages nlohmann_json) )
endif () list(APPEND fetch_packages nlohmann_json)
endif ()
endif ()
endif () endif ()
# Handle configure flags # Handle configure flags