From 58d19063476854c52d483ec4cd62d2ec62707e1f Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Fri, 10 Apr 2026 17:31:08 -0600 Subject: [PATCH 1/4] Standardize package found logic for tpls --- src/logging/CMakeLists.txt | 4 +++- src/parser/CMakeLists.txt | 4 +++- src/testing-support/CMakeLists.txt | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/logging/CMakeLists.txt b/src/logging/CMakeLists.txt index 9211a94b..35279011 100644 --- a/src/logging/CMakeLists.txt +++ b/src/logging/CMakeLists.txt @@ -12,9 +12,11 @@ if (NOT EKAT_SKIP_FIND_SPDLOG) else() message (STATUS "Looking for spdlog ... NOT FOUND") endif() +else () + set (spdlog_FOUND FALSE) endif() -if (NOT TARGET spdlog) +if (NOT spdlog_FOUND) include(EkatBuildSpdlog) set (EKAT_BUILDS_SPDLOG ON CACHE BOOL "Whether Ekat builds spdlog" FORCE) else() diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index bda0e0cf..f6ac6ca3 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -27,9 +27,11 @@ if (NOT EKAT_SKIP_FIND_YAML_CPP) else() message (STATUS "Looking for yaml-cpp ... NOT FOUND") endif() +else () + set (yaml-cpp_FOUND FALSE) endif() -if (NOT TARGET yaml-cpp) +if (NOT yaml-cpp_FOUND) include(EkatBuildYamlCpp) set (EKAT_BUILDS_YAMLCPP ON CACHE BOOL "Whether Ekat builds yaml-cpp" FORCE) else() diff --git a/src/testing-support/CMakeLists.txt b/src/testing-support/CMakeLists.txt index cab9589d..834bb98a 100644 --- a/src/testing-support/CMakeLists.txt +++ b/src/testing-support/CMakeLists.txt @@ -13,9 +13,11 @@ if (NOT EKAT_SKIP_FIND_CATCH2) else() message (STATUS "Looking for Catch2 ... NOT FOUND") endif() +else () + set (Catch2_FOUND FALSE) endif() -if (NOT TARGET Catch2::Catch2) +if (NOT Catch2_FOUND) set (EKAT_BUILDS_CATCH2 ON CACHE BOOL "Whether Ekat builds Catch2" FORCE) include (EkatBuildCatch2) else() From 3dde4093c4f090c6f4ea9861d1f9638adac081d1 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Fri, 10 Apr 2026 17:40:37 -0600 Subject: [PATCH 2/4] Ensure yaml-cpp scoped target exists for downstream customers --- cmake/EkatConfig.cmake.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/EkatConfig.cmake.in b/cmake/EkatConfig.cmake.in index 62c00aff..79b353aa 100644 --- a/cmake/EkatConfig.cmake.in +++ b/cmake/EkatConfig.cmake.in @@ -32,6 +32,11 @@ if (@EKAT_ENABLE_YAML_PARSER@) else() find_dependency(yaml-cpp REQUIRED QUIET HINTS @yaml-cpp_DIR@) endif() + + # Ensure the namespaced target exists for downstream consumers even if we created it on the fly + if (TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp) + add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp) + endif() endif() if (@EKAT_ENABLE_LOGGING@) From 4430bbcc21683833ab12d12aee244d45213480c0 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Fri, 10 Apr 2026 17:52:55 -0600 Subject: [PATCH 3/4] Ensure spdlog/Catch2 scoped target exists, like we do for yaml-cpp --- cmake/EkatConfig.cmake.in | 9 +++++++++ src/logging/CMakeLists.txt | 7 +++++++ src/testing-support/CMakeLists.txt | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/cmake/EkatConfig.cmake.in b/cmake/EkatConfig.cmake.in index 79b353aa..375a003c 100644 --- a/cmake/EkatConfig.cmake.in +++ b/cmake/EkatConfig.cmake.in @@ -47,6 +47,11 @@ if (@EKAT_ENABLE_LOGGING@) else() find_dependency(spdlog REQUIRED QUIET HINTS @spdlog_DIR@) endif() + + # Ensure the namespaced target exists for downstream consumers even if we created it on the fly + if (TARGET spdlog AND NOT TARGET spdlog::spdlog) + add_library(spdlog::spdlog ALIAS spdlog) + endif() endif() # Boost stacktrace library @@ -61,6 +66,10 @@ if (@EKAT_BUILDS_CATCH2@) else() find_dependency (Catch2 REQUIRED QUIET HINTS @Catch2_DIR@) endif() +# Ensure the namespaced target exists for downstream consumers even if we created it on the fly +if (TARGET Catch2 AND NOT TARGET Catch2::Catch2) + add_library(Catch2::Catch2 ALIAS Catch2) +endif() include (${CMAKE_CURRENT_LIST_DIR}/EkatTargets.cmake) diff --git a/src/logging/CMakeLists.txt b/src/logging/CMakeLists.txt index 35279011..4dd36a27 100644 --- a/src/logging/CMakeLists.txt +++ b/src/logging/CMakeLists.txt @@ -9,6 +9,13 @@ if (NOT EKAT_SKIP_FIND_SPDLOG) if (spdlog_FOUND) message (STATUS "Looking for spdlog ... FOUND") message (STATUS " spdlog_DIR: ${spdlog_DIR}") + # It is possible that the installation provides the spdlog target, but not the spdlog::spdlog target. If so, define the alias target + if (NOT TARGET spdlog::spdlog) + if (NOT TARGET spdlog) + message (FATAL_ERROR "Neither spdlog nor spdlog::spdlog targets were found") + endif() + add_library (spdlog::spdlog ALIAS spdlog) + endif() else() message (STATUS "Looking for spdlog ... NOT FOUND") endif() diff --git a/src/testing-support/CMakeLists.txt b/src/testing-support/CMakeLists.txt index 834bb98a..7cdf1bd4 100644 --- a/src/testing-support/CMakeLists.txt +++ b/src/testing-support/CMakeLists.txt @@ -10,6 +10,13 @@ if (NOT EKAT_SKIP_FIND_CATCH2) if (Catch2_FOUND) message (STATUS "Looking for Catch2 ... FOUND") message (STATUS " Catch2_DIR: ${Catch2_DIR}") + # It is possible that the installation provides the Catch2 target, but not the Catch2::Catch2 target. If so, define the alias target + if (NOT TARGET Catch2::Catch2) + if (NOT TARGET Catch2) + message (FATAL_ERROR "Neither Catch2 nor Catch2::Catch2 targets were found") + endif() + add_library (Catch2::Catch2 ALIAS Catch2) + endif() else() message (STATUS "Looking for Catch2 ... NOT FOUND") endif() From 9b088bbec8709dd125e81057f5a1d755c5cb2463 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Fri, 10 Apr 2026 18:09:58 -0600 Subject: [PATCH 4/4] Make TPLs handling extra-extra-safe --- cmake/EkatConfig.cmake.in | 34 ++++++++++++++++++------------ src/logging/CMakeLists.txt | 20 +++++++++++++----- src/parser/CMakeLists.txt | 25 ++++++++++++++-------- src/testing-support/CMakeLists.txt | 27 +++++++++++++----------- 4 files changed, 66 insertions(+), 40 deletions(-) diff --git a/cmake/EkatConfig.cmake.in b/cmake/EkatConfig.cmake.in index 375a003c..63cec160 100644 --- a/cmake/EkatConfig.cmake.in +++ b/cmake/EkatConfig.cmake.in @@ -26,11 +26,13 @@ endif() # yaml-cpp if (@EKAT_ENABLE_YAML_PARSER@) - if (@EKAT_BUILDS_YAMLCPP@) - # We're installing yaml-cpp alongside ekat - find_dependency(yaml-cpp REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) - else() - find_dependency(yaml-cpp REQUIRED QUIET HINTS @yaml-cpp_DIR@) + if (NOT TARGET yaml-cpp::yaml-cpp AND NOT TARGET yaml-cpp) + if (@EKAT_BUILDS_YAMLCPP@) + # We're installing yaml-cpp alongside ekat + find_dependency(yaml-cpp REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) + else() + find_dependency(yaml-cpp REQUIRED QUIET HINTS @yaml-cpp_DIR@) + endif() endif() # Ensure the namespaced target exists for downstream consumers even if we created it on the fly @@ -41,11 +43,13 @@ endif() if (@EKAT_ENABLE_LOGGING@) # spdlog - if (@EKAT_BUILDS_SPDLOG@) - # We're installing yaml-cpp alongside ekat - find_dependency(spdlog REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) - else() - find_dependency(spdlog REQUIRED QUIET HINTS @spdlog_DIR@) + if (NOT TARGET spdlog::spdlog AND NOT TARGET spdlog) + if (@EKAT_BUILDS_SPDLOG@) + # We're installing spdlog alongside ekat + find_dependency(spdlog REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) + else() + find_dependency(spdlog REQUIRED QUIET HINTS @spdlog_DIR@) + endif() endif() # Ensure the namespaced target exists for downstream consumers even if we created it on the fly @@ -61,10 +65,12 @@ if (@EKAT_ENABLE_BOOST_STACKTRACE@) endif() # Catch2 testing system -if (@EKAT_BUILDS_CATCH2@) - find_dependency (Catch2 REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) -else() - find_dependency (Catch2 REQUIRED QUIET HINTS @Catch2_DIR@) +if (NOT TARGET Catch2::Catch2 AND NOT TARGET Catch2) + if (@EKAT_BUILDS_CATCH2@) + find_dependency (Catch2 REQUIRED QUIET HINTS @CMAKE_INSTALL_PREFIX@) + else() + find_dependency (Catch2 REQUIRED QUIET HINTS @Catch2_DIR@) + endif() endif() # Ensure the namespaced target exists for downstream consumers even if we created it on the fly if (TARGET Catch2 AND NOT TARGET Catch2::Catch2) diff --git a/src/logging/CMakeLists.txt b/src/logging/CMakeLists.txt index 4dd36a27..d2a594d0 100644 --- a/src/logging/CMakeLists.txt +++ b/src/logging/CMakeLists.txt @@ -1,9 +1,13 @@ -include(GNUInstallDirs) - # spdlog is a REQUIRED dep of this package +set (spdlog_FOUND FALSE) +if (TARGET spdlog::spdlog OR TARGET spdlog) + set(spdlog_FOUND TRUE) + message(STATUS "EKAT: Using spdlog provided by parent project") +endif() + option (EKAT_SKIP_FIND_SPDLOG "Skip find_package for spdlog, and fetch via FetchContent" OFF) -if (NOT EKAT_SKIP_FIND_SPDLOG) +if (NOT spdlog_FOUND AND NOT EKAT_SKIP_FIND_SPDLOG) message (STATUS "Looking for spdlog ...") find_package(spdlog QUIET NO_DEFAULT_PATH) if (spdlog_FOUND) @@ -19,8 +23,14 @@ if (NOT EKAT_SKIP_FIND_SPDLOG) else() message (STATUS "Looking for spdlog ... NOT FOUND") endif() -else () - set (spdlog_FOUND FALSE) +endif() + +# If we found spdlog (via find_package or as an existing tgt) +# ensure it provides the scoped target +if (spdlog_FOUND) + if (TARGET spdlog AND NOT TARGET spdlog::spdlog) + add_library(spdlog::spdlog ALIAS spdlog) + endif() endif() if (NOT spdlog_FOUND) diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt index f6ac6ca3..857e45bf 100644 --- a/src/parser/CMakeLists.txt +++ b/src/parser/CMakeLists.txt @@ -1,8 +1,14 @@ # yaml-cpp is a REQUIRED dep of this package +set (yaml-cpp_FOUND FALSE) +if (TARGET yaml-cpp::yaml-cpp OR TARGET yaml-cpp) + set(yaml-cpp_FOUND TRUE) + message(STATUS "EKAT: Using yaml-cpp provided by parent project") +endif() + option (EKAT_SKIP_FIND_YAML_CPP "Skip find_package for yaml-cpp, and fetch via FetchContent" OFF) -if (NOT EKAT_SKIP_FIND_YAML_CPP) +if (NOT yaml-cpp_FOUND AND NOT EKAT_SKIP_FIND_YAML_CPP) # I am having issues getting the env var YAML_CPP_ROOT being picked up # by cmake. I suspect this has to do with the presence of the hyphen # CMake *should* convert '-' to '_' when forming the cmake/env var name, @@ -17,18 +23,19 @@ if (NOT EKAT_SKIP_FIND_YAML_CPP) if (yaml-cpp_FOUND) message (STATUS "Looking for yaml-cpp ... FOUND") message (STATUS " yaml-cpp_DIR: ${yaml-cpp_DIR}") - # It is possible that the installation provides the yaml-cpp target, but not the yaml-cpp::yaml-cpp target. If so, define the alias target - if (NOT TARGET yaml-cpp::yaml-cpp) - if (NOT TARGET yaml-cpp) - message (FATAL_ERROR "Neither yaml-cpp nor yaml-cpp::yaml-cpp targets were found") - endif() - add_library (yaml-cpp::yaml-cpp ALIAS yaml-cpp) + if (NOT TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp) endif() else() message (STATUS "Looking for yaml-cpp ... NOT FOUND") endif() -else () - set (yaml-cpp_FOUND FALSE) +endif() + +# If we found yaml-cpp (via find_package or as an existing tgt) +# ensure it provides the scoped target +if (yaml-cpp_FOUND) + if (TARGET yaml-cpp AND NOT TARGET yaml-cpp::yaml-cpp) + add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp) + endif() endif() if (NOT yaml-cpp_FOUND) diff --git a/src/testing-support/CMakeLists.txt b/src/testing-support/CMakeLists.txt index 7cdf1bd4..d09cd246 100644 --- a/src/testing-support/CMakeLists.txt +++ b/src/testing-support/CMakeLists.txt @@ -1,27 +1,30 @@ -include(GNUInstallDirs) - ### CATCH MAIN ### +set (Catch2_FOUND FALSE) +if (TARGET Catch2::Catch2 OR TARGET Catch2) + set(Catch2_FOUND TRUE) + message(STATUS "EKAT: Using Catch2 provided by parent project") +endif() + # Catch2 is a REQUIRED dep of this package option (EKAT_SKIP_FIND_CATCH2 "Skip find_package for Catch2, and fetch via FetchContent" OFF) -if (NOT EKAT_SKIP_FIND_CATCH2) +if (NOT Catch2_FOUND AND NOT EKAT_SKIP_FIND_CATCH2) message (STATUS "Looking for Catch2 ...") find_package(Catch2 QUIET NO_DEFAULT_PATH) if (Catch2_FOUND) message (STATUS "Looking for Catch2 ... FOUND") message (STATUS " Catch2_DIR: ${Catch2_DIR}") - # It is possible that the installation provides the Catch2 target, but not the Catch2::Catch2 target. If so, define the alias target - if (NOT TARGET Catch2::Catch2) - if (NOT TARGET Catch2) - message (FATAL_ERROR "Neither Catch2 nor Catch2::Catch2 targets were found") - endif() - add_library (Catch2::Catch2 ALIAS Catch2) - endif() else() message (STATUS "Looking for Catch2 ... NOT FOUND") endif() -else () - set (Catch2_FOUND FALSE) +endif() + +# If we found Catch2 (via find_package or as an existing tgt) +# ensure it provides the scoped target +if (Catch2_FOUND) + if (TARGET Catch2 AND NOT TARGET Catch2::Catch2) + add_library(Catch2::Catch2 ALIAS Catch2) + endif() endif() if (NOT Catch2_FOUND)