From 03dc1c8a3c11ad1a418dd0d8f50e91f11b411dc9 Mon Sep 17 00:00:00 2001 From: Cazadorro Date: Mon, 13 Mar 2023 14:56:42 -0500 Subject: [PATCH] Added check for gsl::gsl-lite to avoid find_package if targets already added by add_subdirectory(...) and did the same for fmt::fmt and ranges-v3, with out these changes, impossible to use library if dependencies are also subdirectories --- src/core-fmt/CMakeLists.txt | 4 +++- src/core/CMakeLists.txt | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core-fmt/CMakeLists.txt b/src/core-fmt/CMakeLists.txt index d88d23f4..96c6dded 100644 --- a/src/core-fmt/CMakeLists.txt +++ b/src/core-fmt/CMakeLists.txt @@ -29,6 +29,8 @@ add_units_module(core-fmt DEPENDENCIES mp-units::core HEADERS include/units/form target_compile_definitions(mp-units-core-fmt INTERFACE ${projectPrefix}USE_LIBFMT=$) if(${projectPrefix}USE_LIBFMT) - find_package(fmt CONFIG REQUIRED) + if(NOT TARGET fmt::fmt) + find_package(fmt CONFIG REQUIRED) + endif() target_link_libraries(mp-units-core-fmt INTERFACE fmt::fmt) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 56f462af..04576b2b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -27,7 +27,9 @@ set(${projectPrefix}DOWNCAST_MODE ON CACHE STRING "Select downcasting mode") set_property(CACHE ${projectPrefix}DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF) # find dependencies -find_package(gsl-lite CONFIG REQUIRED) +if(NOT TARGET gsl::gsl-lite) + find_package(gsl-lite CONFIG REQUIRED) +endif() # check if libc++ is being used include(CheckLibcxxInUse) @@ -71,7 +73,9 @@ target_include_directories( if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(${projectPrefix}LIBCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14") - find_package(range-v3 CONFIG REQUIRED) + if(NOT TARGET range-v3::range-v3) + find_package(range-v3 CONFIG REQUIRED) + endif() target_link_libraries(mp-units-core INTERFACE range-v3::range-v3) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")