aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2024-05-11 22:03:39 +1000
committerfuzzard <fuzzard@kodi.tv>2024-05-18 11:27:12 +1000
commit483fb6b08b1e807eef8762f32b4d1eb0d2bc7196 (patch)
tree3172c70fd6192f713cb244290ec56b28d20609f8
parent57022cbca8d81a3684a2af1420a3854b58300e10 (diff)
[cmake][modules] FindFmt cleanup and use core_target_link_libraries
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/modules/FindFmt.cmake100
-rw-r--r--cmake/modules/FindSpdlog.cmake6
3 files changed, 48 insertions, 60 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9db66c3a7d..5976132b61 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -324,7 +324,7 @@ list(APPEND install_data ${ADDON_INSTALL_DATA})
add_library(compileinfo OBJECT ${CORE_BUILD_DIR}/xbmc/CompileInfo.cpp)
set_target_properties(compileinfo PROPERTIES FOLDER "Build Utilities")
target_compile_options(compileinfo PRIVATE ${SYSTEM_DEFINES} ${ARCH_DEFINES})
-add_dependencies(compileinfo fmt::fmt)
+target_link_libraries(compileinfo PRIVATE ${APP_NAME_LC}::Fmt)
if(NOT MSVC)
target_compile_options(compileinfo PUBLIC ${CORE_COMPILE_OPTIONS})
diff --git a/cmake/modules/FindFmt.cmake b/cmake/modules/FindFmt.cmake
index 6a3f36eab8..a96e911717 100644
--- a/cmake/modules/FindFmt.cmake
+++ b/cmake/modules/FindFmt.cmake
@@ -4,9 +4,9 @@
#
# This will define the following target:
#
-# fmt::fmt - The Fmt library
+# ${APP_NAME_LC}::Fmt - The Fmt library
-if(NOT TARGET fmt::fmt)
+if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
include(cmake/scripts/common/ModuleHelpers.cmake)
@@ -58,45 +58,37 @@ if(NOT TARGET fmt::fmt)
find_path(FMT_INCLUDE_DIR NAMES fmt/format.h
HINTS ${DEPENDS_PATH}/include ${PC_FMT_INCLUDEDIR}
- ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
- NO_CACHE)
+ ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
find_library(FMT_LIBRARY_RELEASE NAMES fmt
HINTS ${DEPENDS_PATH}/lib ${PC_FMT_LIBDIR}
- ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
- NO_CACHE)
+ ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
find_library(FMT_LIBRARY_DEBUG NAMES fmtd
HINTS ${DEPENDS_PATH}/lib ${PC_FMT_LIBDIR}
- ${${CORE_PLATFORM_LC}_SEARCH_CONFIG}
- NO_CACHE)
+ ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
+ else()
+ # This is for the case where a distro provides a non standard (Debug/Release) config type
+ # eg Debian's config file is fmtConfigTargets-none.cmake
+ # convert this back to either DEBUG/RELEASE or just RELEASE
+ # we only do this because we use find_package_handle_standard_args for config time output
+ # and it isnt capable of handling TARGETS, so we have to extract the info
+ get_target_property(_FMT_CONFIGURATIONS fmt::fmt IMPORTED_CONFIGURATIONS)
+ foreach(_fmt_config IN LISTS _FMT_CONFIGURATIONS)
+ # Some non standard config (eg None on Debian)
+ # Just set to RELEASE var so select_library_configurations can continue to work its magic
+ string(TOUPPER ${_fmt_config} _fmt_config_UPPER)
+ if((NOT ${_fmt_config_UPPER} STREQUAL "RELEASE") AND
+ (NOT ${_fmt_config_UPPER} STREQUAL "DEBUG"))
+ get_target_property(FMT_LIBRARY_RELEASE fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER})
+ else()
+ get_target_property(FMT_LIBRARY_${_fmt_config_UPPER} fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER})
+ endif()
+ endforeach()
+
+ get_target_property(FMT_INCLUDE_DIR fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
endif()
endif()
- # fmt::fmt target exists and is of suitable versioning. the INTERNAL_FMT build
- # is not created.
- # We create variables based off TARGET data for use with FPHSA
- if(TARGET fmt::fmt AND NOT TARGET fmt)
- # This is for the case where a distro provides a non standard (Debug/Release) config type
- # eg Debian's config file is fmtConfigTargets-none.cmake
- # convert this back to either DEBUG/RELEASE or just RELEASE
- # we only do this because we use find_package_handle_standard_args for config time output
- # and it isnt capable of handling TARGETS, so we have to extract the info
- get_target_property(_FMT_CONFIGURATIONS fmt::fmt IMPORTED_CONFIGURATIONS)
- foreach(_fmt_config IN LISTS _FMT_CONFIGURATIONS)
- # Some non standard config (eg None on Debian)
- # Just set to RELEASE var so select_library_configurations can continue to work its magic
- string(TOUPPER ${_fmt_config} _fmt_config_UPPER)
- if((NOT ${_fmt_config_UPPER} STREQUAL "RELEASE") AND
- (NOT ${_fmt_config_UPPER} STREQUAL "DEBUG"))
- get_target_property(FMT_LIBRARY_RELEASE fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER})
- else()
- get_target_property(FMT_LIBRARY_${_fmt_config_UPPER} fmt::fmt IMPORTED_LOCATION_${_fmt_config_UPPER})
- endif()
- endforeach()
-
- get_target_property(FMT_INCLUDE_DIR fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
- endif()
-
include(SelectLibraryConfigurations)
select_library_configurations(FMT)
unset(FMT_LIBRARIES)
@@ -106,29 +98,30 @@ if(NOT TARGET fmt::fmt)
REQUIRED_VARS FMT_LIBRARY FMT_INCLUDE_DIR
VERSION_VAR FMT_VERSION)
if(Fmt_FOUND)
- if(TARGET fmt OR NOT TARGET fmt::fmt)
- if(NOT TARGET fmt::fmt)
- add_library(fmt::fmt UNKNOWN IMPORTED)
- endif()
+ # cmake target and not building internal
+ if(TARGET fmt::fmt AND NOT TARGET fmt)
+ add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS fmt::fmt)
+ else()
+ add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
if(FMT_LIBRARY_RELEASE)
- set_target_properties(fmt::fmt PROPERTIES
- IMPORTED_CONFIGURATIONS RELEASE
- IMPORTED_LOCATION_RELEASE "${FMT_LIBRARY_RELEASE}")
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
+ IMPORTED_CONFIGURATIONS RELEASE
+ IMPORTED_LOCATION_RELEASE "${FMT_LIBRARY_RELEASE}")
endif()
if(FMT_LIBRARY_DEBUG)
- set_target_properties(fmt::fmt PROPERTIES
- IMPORTED_CONFIGURATIONS DEBUG
- IMPORTED_LOCATION_DEBUG "${FMT_LIBRARY_DEBUG}")
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
+ IMPORTED_CONFIGURATIONS DEBUG
+ IMPORTED_LOCATION_DEBUG "${FMT_LIBRARY_DEBUG}")
endif()
- set_target_properties(fmt::fmt PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}")
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${FMT_INCLUDE_DIR}")
endif()
if(TARGET fmt)
- add_dependencies(fmt::fmt fmt)
+ add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} fmt)
# We are building as a requirement, so set LIB_BUILD property to allow calling
# modules to know we will be building, and they will want to rebuild as well.
- set_target_properties(fmt::fmt PROPERTIES LIB_BUILD ON)
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES LIB_BUILD ON)
endif()
# Add internal build target when a Multi Config Generator is used
@@ -146,14 +139,9 @@ if(NOT TARGET fmt::fmt)
endif()
add_dependencies(build_internal_depends fmt)
endif()
- endif()
-
- # Check whether we already have fmt::fmt target added to dep property list
- get_property(CHECK_INTERNAL_DEPS GLOBAL PROPERTY INTERNAL_DEPS_PROP)
- list(FIND CHECK_INTERNAL_DEPS "fmt::fmt" FMT_PROP_FOUND)
-
- # list(FIND) returns -1 if search item not found
- if(FMT_PROP_FOUND STREQUAL "-1")
- set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP fmt::fmt)
+ else()
+ if(Fmt_FIND_REQUIRED)
+ message(FATAL_ERROR "Fmt libraries were not found. You may want to use -DENABLE_INTERNAL_FMT=ON")
+ endif()
endif()
endif()
diff --git a/cmake/modules/FindSpdlog.cmake b/cmake/modules/FindSpdlog.cmake
index a4ff560efa..d1c76451d6 100644
--- a/cmake/modules/FindSpdlog.cmake
+++ b/cmake/modules/FindSpdlog.cmake
@@ -42,7 +42,7 @@ macro(buildSpdlog)
BUILD_DEP_TARGET()
- add_dependencies(${MODULE_LC} fmt::fmt)
+ add_dependencies(${MODULE_LC} ${APP_NAME_LC}::Fmt)
endmacro()
if(NOT TARGET spdlog::spdlog)
@@ -55,9 +55,9 @@ if(NOT TARGET spdlog::spdlog)
find_package(Fmt ${LIB_FMT_VER} MODULE REQUIRED)
endif()
- if(TARGET fmt::fmt)
+ if(TARGET ${APP_NAME_LC}::Fmt)
# Check if we want to force a build due to a dependency rebuild
- get_property(LIB_FORCE_REBUILD TARGET fmt::fmt PROPERTY LIB_BUILD)
+ get_property(LIB_FORCE_REBUILD TARGET ${APP_NAME_LC}::Fmt PROPERTY LIB_BUILD)
endif()
set(MODULE_LC spdlog)