From 6dde823d4cb884638c323d5cd5d7efc33bbf16dd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 May 2022 17:17:48 +0200 Subject: [PATCH] improve dependency handling (same as fsfw) --- CMakeLists.txt | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77509188..2fbcf0fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,7 @@ set(SIMPLE_OBSW_NAME eive-simple) set(UNITTEST_NAME eive-unittest) set(LIB_FSFW_NAME fsfw) set(LIB_EIVE_MISSION eive-mission) -set(LIB_ETL_NAME etl) +set(LIB_ETL_TARGET etl::etl) set(LIB_CSP_NAME libcsp) set(LIB_LWGPS_NAME lwgps) set(LIB_ARCSEC wire) @@ -325,13 +325,21 @@ add_subdirectory(${UNITTEST_PATH}) # This should have already been downloaded by the FSFW # Still include it to be safe -include(FetchContent) -FetchContent_Declare( - etl - GIT_REPOSITORY https://github.com/ETLCPP/etl - GIT_TAG ${FSFW_ETL_LIB_VERSION} -) -FetchContent_MakeAvailable(etl) +find_package(etl ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET) +# Not installed, so use FetchContent to download and provide etl +if(NOT etl_FOUND) + message(STATUS + "No ETL installation was found with find_package. Installing and providing " + "etl with FindPackage" + ) + include(FetchContent) + FetchContent_Declare( + etl + GIT_REPOSITORY https://github.com/ETLCPP/etl + GIT_TAG ${FSFW_ETL_LIB_VERSION} + ) + list(APPEND FSFW_FETCH_CONTENT_TARGETS etl) +endif() # Use same Catch2 version as framework if (NOT(TGT_BSP MATCHES "arm/te0720-1cfa") AND NOT(TGT_BSP MATCHES "arm/q7s")) @@ -348,8 +356,21 @@ if (NOT(TGT_BSP MATCHES "arm/te0720-1cfa") AND NOT(TGT_BSP MATCHES "arm/q7s")) GIT_TAG ${FSFW_CATCH2_LIB_VERSION} ) - FetchContent_MakeAvailable(Catch2) - #fixes regression -preview4, to be confirmed in later releases + list(APPEND FSFW_FETCH_CONTENT_TARGETS Catch2) + endif() +endif() + +# The documentation for FetchContent recommends declaring all the dependencies +# before making them available. We make all declared dependency available here +# after their declaration +if(FSFW_FETCH_CONTENT_TARGETS) + FetchContent_MakeAvailable(${FSFW_FETCH_CONTENT_TARGETS}) + if(TARGET etl) + add_library(${LIB_ETL_TARGET} ALIAS etl) + endif() + if(TARGET Catch2) + # Fixes regression -preview4, to be confirmed in later releases + # Related GitHub issue: https://github.com/catchorg/Catch2/issues/2417 set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "") set_target_properties(Catch2 PROPERTIES EXCLUDE_FROM_ALL "true") set_target_properties(Catch2WithMain PROPERTIES EXCLUDE_FROM_ALL "true") @@ -398,7 +419,7 @@ endif() if(EIVE_ADD_ETL_LIB) target_link_libraries(${LIB_EIVE_MISSION} PUBLIC - etl + ${LIB_ETL_TARGET} ) endif()