aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzard <fuzzard@kodi.tv>2024-06-24 12:04:44 +1000
committerfuzzard <fuzzard@kodi.tv>2024-06-26 16:38:34 +1000
commita7b858b1c4ca0e4563924f06835ee6a0ee93cf95 (patch)
tree82d69d2455df17839e8495843774b74e8d55eb3a
parentc0161da767fad02f87be5746e377769fb0d0ebac (diff)
[cmake][modules] FindExiv2 cleanup and fix old exiv2 target name use
exiv2 config files prior to 0.28 use an non-namespaced target, so we check for it as an optional
-rw-r--r--cmake/modules/FindExiv2.cmake101
1 files changed, 67 insertions, 34 deletions
diff --git a/cmake/modules/FindExiv2.cmake b/cmake/modules/FindExiv2.cmake
index 5e6c9e0fca..bb42f04c25 100644
--- a/cmake/modules/FindExiv2.cmake
+++ b/cmake/modules/FindExiv2.cmake
@@ -10,8 +10,6 @@
if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
macro(buildexiv2)
-
- find_package(Patch MODULE REQUIRED)
find_package(Iconv REQUIRED)
# Note: Please drop once a release based on master is made. First 2 are already upstream.
@@ -21,6 +19,17 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
generate_patchcommand("${patches}")
+ if(WIN32 OR WINDOWS_STORE)
+ # Exiv2 cant be built using /RTC1, so we alter and disable the auto addition of flags
+ # using WIN_DISABLE_PROJECT_FLAGS
+ string(REPLACE "/RTC1" "" EXIV2_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} )
+
+ set(EXTRA_ARGS "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}$<$<CONFIG:Debug>: ${EXIV2_CXX_FLAGS_DEBUG}>$<$<CONFIG:Release>: ${CMAKE_CXX_FLAGS_RELEASE}>"
+ "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}$<$<CONFIG:Debug>: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}>$<$<CONFIG:Release>: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}>")
+
+ set(WIN_DISABLE_PROJECT_FLAGS ON)
+ endif()
+
set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
-DEXIV2_ENABLE_WEBREADY=OFF
-DEXIV2_ENABLE_XMP=OFF
@@ -33,7 +42,8 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
-DEXIV2_ENABLE_BROTLI=OFF
-DEXIV2_ENABLE_INIH=OFF
-DEXIV2_ENABLE_FILESYSTEM_ACCESS=OFF
- -DEXIV2_BUILD_EXIV2_COMMAND=OFF)
+ -DEXIV2_BUILD_EXIV2_COMMAND=OFF
+ ${EXTRA_ARGS})
if(NOT CMAKE_CXX_COMPILER_LAUNCHER STREQUAL "")
list(APPEND CMAKE_ARGS -DBUILD_WITH_CCACHE=ON)
@@ -58,7 +68,36 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
buildexiv2()
else()
- if(NOT TARGET Exiv2::exiv2lib)
+ if(TARGET Exiv2::exiv2lib OR TARGET exiv2lib)
+ # We create variables based off TARGET data for use with FPHSA
+ # exiv2 < 0.28 uses a non namespaced target, but also has an alias. Prioritise
+ # namespaced target, and fallback to old target for < 0.28
+ if(TARGET Exiv2::exiv2lib)
+ set(_exiv_target_name Exiv2::exiv2lib)
+ else()
+ set(_exiv_target_name exiv2lib)
+ endif()
+
+ # This is for the case where a distro provides a non standard (Debug/Release) config type
+ # eg Debian's config file is exiv2Config-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(_EXIV2_CONFIGURATIONS ${_exiv_target_name} IMPORTED_CONFIGURATIONS)
+ foreach(_exiv2_config IN LISTS _EXIV2_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 ${_exiv2_config} _exiv2_config_UPPER)
+ if((NOT ${_exiv2_config_UPPER} STREQUAL "RELEASE") AND
+ (NOT ${_exiv2_config_UPPER} STREQUAL "DEBUG"))
+ get_target_property(EXIV2_LIBRARY_RELEASE ${_exiv_target_name} IMPORTED_LOCATION_${_exiv2_config_UPPER})
+ else()
+ get_target_property(EXIV2_LIBRARY_${_exiv2_config_UPPER} ${_exiv_target_name} IMPORTED_LOCATION_${_exiv2_config_UPPER})
+ endif()
+ endforeach()
+
+ get_target_property(EXIV2_INCLUDE_DIR ${_exiv_target_name} INTERFACE_INCLUDE_DIRECTORIES)
+ else()
find_package(PkgConfig)
# Fallback to pkg-config and individual lib/include file search
if(PKG_CONFIG_FOUND)
@@ -67,35 +106,12 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
endif()
find_path(EXIV2_INCLUDE_DIR NAMES exiv2/exiv2.hpp
- HINTS ${PC_EXIV2_INCLUDEDIR} NO_CACHE)
- find_library(EXIV2_LIBRARY NAMES exiv2
- HINTS ${PC_EXIV2_LIBDIR} NO_CACHE)
+ HINTS ${PC_EXIV2_INCLUDEDIR})
+ find_library(EXIV2_LIBRARY_RELEASE NAMES exiv2
+ HINTS ${PC_EXIV2_LIBDIR})
endif()
endif()
- # We create variables based off TARGET data for use with FPHSA
- if(TARGET Exiv2::exiv2lib AND NOT TARGET exiv2)
- # This is for the case where a distro provides a non standard (Debug/Release) config type
- # eg Debian's config file is exiv2Config-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 Exiv2::exiv2lib IMPORTED_CONFIGURATIONS)
- foreach(_exiv2_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 ${_exiv2_config} _exiv2_config_UPPER)
- if((NOT ${_exiv2_config_UPPER} STREQUAL "RELEASE") AND
- (NOT ${_exiv2_config_UPPER} STREQUAL "DEBUG"))
- get_target_property(EXIV2_LIBRARY_RELEASE Exiv2::exiv2lib IMPORTED_LOCATION_${_exiv2_config_UPPER})
- else()
- get_target_property(EXIV2_LIBRARY_${_exiv2_config_UPPER} Exiv2::exiv2lib IMPORTED_LOCATION_${_exiv2_config_UPPER})
- endif()
- endforeach()
-
- get_target_property(EXIV2_INCLUDE_DIR Exiv2::exiv2lib INTERFACE_INCLUDE_DIRECTORIES)
- endif()
-
include(SelectLibraryConfigurations)
select_library_configurations(EXIV2)
unset(EXIV2_LIBRARIES)
@@ -106,14 +122,31 @@ if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
VERSION_VAR EXIV2_VER)
if(EXIV2_FOUND)
- if(TARGET Exiv2::exiv2lib AND NOT TARGET exiv2)
- # Exiv2 config found. Use it
- add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS Exiv2::exiv2lib)
+ if((TARGET Exiv2::exiv2lib OR TARGET exiv2lib) AND NOT TARGET exiv2)
+ # Exiv alias exiv2lib in their latest cmake config. We test for the alias
+ # to workout what we need to point OUR alias at.
+ get_target_property(_EXIV2_ALIASTARGET exiv2lib ALIASED_TARGET)
+ if(_EXIV2_ALIASTARGET)
+ set(_exiv_target_name ${_EXIV2_ALIASTARGET})
+ endif()
+ add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS ${_exiv_target_name})
else()
add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
- IMPORTED_LOCATION "${EXIV2_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${EXIV2_INCLUDE_DIR}")
+
+ if(EXIV2_LIBRARY_RELEASE)
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
+ IMPORTED_CONFIGURATIONS RELEASE
+ IMPORTED_LOCATION_RELEASE "${EXIV2_LIBRARY_RELEASE}")
+ endif()
+ if(EXIV2_LIBRARY_DEBUG)
+ set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${EXIV2_LIBRARY_DEBUG}")
+ set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ endif()
+
if(CORE_SYSTEM_NAME STREQUAL "freebsd")
set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES procstat)