aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2022-06-28 13:29:38 +1000
committerfuzzard <fuzzard@kodi.tv>2022-09-28 14:17:10 +1000
commit580285f6bf6766cb7a1370d87625f4486d906d0d (patch)
tree0ec2e1f8ef4af588915f933320014982dfcaa5c2 /cmake
parent98bd7aea2103717fc48b4a96bd47f3ae9f52a001 (diff)
[cmake] allow handling of more corner cases of existing lib versions of spdlog/fmt
If a dependency lib is rebuilt, allow a way to notify the calling parent that the dependency is being built. This then allows the parent to rebuild to make sure all the correct versions of a lib are inline. Eg Spdlog exists and was built against FMT 7.0.1 (we cant know what version). We no longer have FMT lib, so it is rebuilt (ver 8.0.1). Allow spdlog to recognise that its dependency is being force built, and therefore it should rebuild to make sure the same lib/api is used throughout.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/modules/FindFmt.cmake44
-rw-r--r--cmake/modules/FindSpdlog.cmake13
2 files changed, 46 insertions, 11 deletions
diff --git a/cmake/modules/FindFmt.cmake b/cmake/modules/FindFmt.cmake
index 32af4a21a1..abecba501f 100644
--- a/cmake/modules/FindFmt.cmake
+++ b/cmake/modules/FindFmt.cmake
@@ -12,11 +12,20 @@
#
# fmt::fmt - The Fmt library
+define_property(TARGET PROPERTY LIB_BUILD
+ BRIEF_DOCS "This target will be compiling the library"
+ FULL_DOCS "This target will be compiling the library")
+
+set(FORCE_BUILD OFF)
+
# If target exists, no need to rerun find
# Allows a module that may be a dependency for multiple libraries to just be executed
# once to populate all required variables/targets
-if(NOT TARGET fmt::fmt)
- if(ENABLE_INTERNAL_FMT)
+if((NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) AND NOT TARGET fmt)
+
+ # Build if ENABLE_INTERNAL_FMT, or if required version in find_package call is greater
+ # than already found FMT_VERSION from a previous find_package call
+ if(ENABLE_INTERNAL_FMT OR (Fmt_FIND_REQUIRED AND FMT_VERSION VERSION_LESS Fmt_FIND_VERSION))
include(cmake/scripts/common/ModuleHelpers.cmake)
@@ -27,7 +36,16 @@ if(NOT TARGET fmt::fmt)
# Check for existing FMT. If version >= FMT-VERSION file version, dont build
find_package(FMT CONFIG QUIET)
- if(FMT_VERSION VERSION_LESS ${${MODULE}_VER})
+ if(Fmt_FIND_VERSION)
+ if(FMT_VERSION VERSION_LESS ${Fmt_FIND_VERSION})
+ set(FORCE_BUILD ON)
+ endif()
+ endif()
+
+ if(${FORCE_BUILD} OR FMT_VERSION VERSION_LESS ${${MODULE}_VER})
+
+ # Set FORCE_BUILD to enable fmt::fmt property that build will occur
+ set(FORCE_BUILD ON)
if(APPLE)
set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
@@ -88,8 +106,16 @@ if(NOT TARGET fmt::fmt)
set(FMT_LIBRARIES ${FMT_LIBRARY})
set(FMT_INCLUDE_DIRS ${FMT_INCLUDE_DIR})
+ # Reorder this to allow handling of FMT_FORCE_BUILD and not duplicate in property
if(NOT TARGET fmt::fmt)
- add_library(fmt::fmt UNKNOWN IMPORTED)
+ set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt)
+ endif()
+
+ if(NOT TARGET fmt::fmt OR FORCE_BUILD)
+ if(NOT TARGET fmt::fmt)
+ add_library(fmt::fmt UNKNOWN IMPORTED)
+ endif()
+
if(FMT_LIBRARY_RELEASE)
set_target_properties(fmt::fmt PROPERTIES
IMPORTED_CONFIGURATIONS RELEASE
@@ -102,11 +128,19 @@ if(NOT TARGET fmt::fmt)
endif()
set_target_properties(fmt::fmt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}")
+
+ # If a force build is done, let any calling packages know they may want to rebuild
+ if(FORCE_BUILD)
+ set_target_properties(fmt::fmt PROPERTIES LIB_BUILD ON)
+ endif()
endif()
if(TARGET fmt)
add_dependencies(fmt::fmt fmt)
endif()
- set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt)
+ else()
+ if(FMT_FIND_REQUIRED)
+ message(FATAL_ERROR "Fmt lib not found. Maybe use -DENABLE_INTERNAL_FMT=ON")
+ endif()
endif()
mark_as_advanced(FMT_INCLUDE_DIR FMT_LIBRARY)
diff --git a/cmake/modules/FindSpdlog.cmake b/cmake/modules/FindSpdlog.cmake
index fca6437388..23c8617db0 100644
--- a/cmake/modules/FindSpdlog.cmake
+++ b/cmake/modules/FindSpdlog.cmake
@@ -14,21 +14,22 @@
# Spdlog::Spdlog - The Spdlog library
if(ENABLE_INTERNAL_SPDLOG)
+ include(cmake/scripts/common/ModuleHelpers.cmake)
- # Check for dependencies
- find_package(Fmt MODULE QUIET)
+ # Check for dependencies - Must be done before SETUP_BUILD_VARS
+ get_libversion_data("fmt" "target")
+ find_package(Fmt ${LIB_FMT_VER} MODULE REQUIRED)
- include(cmake/scripts/common/ModuleHelpers.cmake)
+ # Check if we want to force a build due to a dependency rebuild
+ get_property(LIB_FORCE_REBUILD TARGET fmt::fmt PROPERTY LIB_BUILD)
set(MODULE_LC spdlog)
-
SETUP_BUILD_VARS()
# Check for existing SPDLOG. If version >= SPDLOG-VERSION file version, dont build
find_package(SPDLOG CONFIG QUIET)
- if(SPDLOG_VERSION VERSION_LESS ${${MODULE}_VER})
-
+ if(SPDLOG_VERSION VERSION_LESS ${${MODULE}_VER} OR LIB_FORCE_REBUILD)
if(APPLE)
set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
endif()