diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 193d167d8..31ca054a0 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -105,18 +105,10 @@ else() message(FATAL_ERROR "Could not find ${CLP_LIBS_STRING} libraries for Boost") endif() -# Find and setup fmt -# NOTE: -# - We only try to link to the static library -# - spdlog uses fmt, so their versions need to be kept in-sync -find_package(fmt 8.0.1 REQUIRED) -if(fmt_FOUND) - message(STATUS "Found fmt ${fmt_VERSION}") -else() - message(FATAL_ERROR "Could not find static libraries for fmt") -endif() +# Find and setup spdlog and fmt transitive dependency -# Find and setup spdlog +# Specify the minimum required spdlog version (can be overridden by the user) +set (spdlog_MIN_VERSION "1.9.0" CACHE STRING "Minimum required version of spdlog") if(CLP_USE_STATIC_LIBS) # NOTE: On some Linux distributions (e.g. Ubuntu), the spdlog package only contains a dynamic # library. If the `find_package(spdlog)` call below fails, re-run @@ -124,18 +116,61 @@ if(CLP_USE_STATIC_LIBS) # source. set(spdlog_USE_STATIC_LIBS ON) endif() -find_package(spdlog 1.9.2 REQUIRED) +find_package(spdlog ${spdlog_MIN_VERSION} REQUIRED) if(spdlog_FOUND) message(STATUS "Found spdlog ${spdlog_VERSION}") else() + message("You may want to re-run `components/core/tools/scripts/lib_install//install-packages-from-source.sh`") if (CLP_USE_STATIC_LIBS) - message(FATAL_ERROR "Could not find static libraries for spdlog. You may want to re-run - `components/core/tools/scripts/lib_install//install-packages-from-source.sh`") + message(FATAL_ERROR "Could not find static libraries for spdlog.") else() message(FATAL_ERROR "Could not find libraries for spdlog.") endif() endif() +# Determine the lower bound version compatibility of fmt w.r.t to spdlog +if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0") + set(FMT_MIN_VERSION "11.0.0") +elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12.0") + set(FMT_MIN_VERSION "10.0.0") +elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11.0") + set(FMT_MIN_VERSION "9.0.0") +elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.9.0") + set(FMT_MIN_VERSION "8.0.0") +else() + message(FATAL_ERROR "Unsupported spdlog version (${spdlog_VERSION}). Minimum supported version is 1.9.0.") +endif() + +# Find fmt with the compatible version +# NOTE: +# - We only try to link to the static library +find_package(fmt ${FMT_MIN_VERSION} REQUIRED) +if(fmt_FOUND) + # Determine the upper bound version compatibility of fmt w.r.t to spdlog + if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0") + # Empty block, no upper version limit + elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12.0") + if (fmt_VERSION VERSION_GREATER_EQUAL "11.0.0") + message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 10.0.0 <= version < 11.0.0") + endif() + elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11.0") + if (fmt_VERSION VERSION_GREATER_EQUAL "10.0.0") + message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 9.0.0 <= version < 10.0.0") + endif() + elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.9.0") + if (fmt_VERSION VERSION_GREATER_EQUAL "9.0.0") + message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 8.0.0 <= version < 9.0.0") + endif() + endif() + message(STATUS "Found fmt ${fmt_VERSION}") +else() + message(FATAL_ERROR "Could not find static libraries for fmt") +endif() + +# Print the selected versions for debugging +message(STATUS "Using spdlog version ${spdlog_VERSION}") +message(STATUS "Using fmt version ${fmt_VERSION}") + # Find and setup libarchive if(CLP_USE_STATIC_LIBS) set(LibArchive_USE_STATIC_LIBS ON)