From 75ad979783a56c027aa9343fe6da2672d6e40e1e Mon Sep 17 00:00:00 2001 From: Nils Tonnaett Date: Tue, 22 Oct 2024 17:54:13 -0700 Subject: [PATCH] Use find_package for fmt and gtest with FetchContent fallback --- CMakeLists.txt | 18 ++++++++++++++++-- src/CMakeLists.txt | 3 +-- src/controller/CMakeLists.txt | 3 +-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93873587..cd0c2679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,9 +93,17 @@ cu_setup_project_version_variables(${LA_AVDECC_VERSION}) # Set minimum OSX/iOS version cu_setup_apple_minimum_versions(MACOS 10.13) +include(FetchContent) + # Include fmtlib if(ENABLE_AVDECC_USE_FMTLIB) - add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/externals/3rdparty/fmtlib EXCLUDE_FROM_ALL) + FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt.git + GIT_TAG 0c9fce2ffefecfdce794e1859584e25877b7b592 # release-11.0.2 + FIND_PACKAGE_ARGS NAMES fmt + ) + FetchContent_MakeAvailable(fmt) endif() # Include json @@ -224,7 +232,13 @@ if(BUILD_AVDECC_TESTS AND NOT VS_USE_CLANG) set(BUILD_GMOCK ON CACHE BOOL "Build the googlemock subproject" FORCE) set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" FORCE) # Include gtest framework - add_subdirectory(externals/3rdparty/gtest) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0 + FIND_PACKAGE_ARGS NAMES GTest + ) + FetchContent_MakeAvailable(googletest) # Include our unit tests add_subdirectory(tests) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8f6372e9..439fe7df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -295,8 +295,7 @@ if(BUILD_AVDECC_LIB_SHARED_CXX) # Setup libfmt if(ENABLE_AVDECC_USE_FMTLIB) - target_compile_options(${PROJECT_NAME}_cxx PRIVATE -DHAVE_FMT) - target_link_libraries(${PROJECT_NAME}_cxx PRIVATE fmt-header-only) + target_compile_options(${PROJECT_NAME}_cxx PRIVATE -DHAVE_FMT -DFMT_HEADER_ONLY) endif() # Setup json diff --git a/src/controller/CMakeLists.txt b/src/controller/CMakeLists.txt index 205d1214..d5045592 100644 --- a/src/controller/CMakeLists.txt +++ b/src/controller/CMakeLists.txt @@ -100,8 +100,7 @@ if(BUILD_AVDECC_LIB_SHARED_CXX) # Setup libfmt if(ENABLE_AVDECC_USE_FMTLIB) - target_compile_options(${PROJECT_NAME}_cxx PRIVATE -DHAVE_FMT) - target_link_libraries(${PROJECT_NAME}_cxx PRIVATE fmt-header-only) + target_compile_options(${PROJECT_NAME}_cxx PRIVATE -DHAVE_FMT -DFMT_HEADER_ONLY) endif() # Setup json