4 # Finds the exiv2 library
6 # This will define the following imported targets::
8 # ${APP_NAME_LC}::Exiv2 - The EXIV2 library
10 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
13 find_package(Iconv REQUIRED)
15 # Patch pending review upstream (https://github.com/Exiv2/exiv2/pull/3004)
16 set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/0001-WIN-lib-postfix.patch")
18 generate_patchcommand("${patches}")
20 if(WIN32 OR WINDOWS_STORE)
21 set(EXIV2_DEBUG_POSTFIX d)
23 # Exiv2 cant be built using /RTC1, so we alter and disable the auto addition of flags
24 # using WIN_DISABLE_PROJECT_FLAGS
25 string(REPLACE "/RTC1" "" EXIV2_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} )
27 set(EXTRA_ARGS "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}$<$<CONFIG:Debug>: ${EXIV2_CXX_FLAGS_DEBUG}>$<$<CONFIG:Release>: ${CMAKE_CXX_FLAGS_RELEASE}>"
28 "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}$<$<CONFIG:Debug>: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}>$<$<CONFIG:Release>: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}>")
30 set(WIN_DISABLE_PROJECT_FLAGS ON)
33 set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
34 -DEXIV2_ENABLE_WEBREADY=OFF
35 -DEXIV2_ENABLE_XMP=OFF
36 -DEXIV2_ENABLE_CURL=OFF
37 -DEXIV2_ENABLE_NLS=OFF
38 -DEXIV2_BUILD_SAMPLES=OFF
39 -DEXIV2_BUILD_UNIT_TESTS=OFF
40 -DEXIV2_ENABLE_VIDEO=OFF
41 -DEXIV2_ENABLE_BMFF=OFF
42 -DEXIV2_ENABLE_BROTLI=OFF
43 -DEXIV2_ENABLE_INIH=OFF
44 -DEXIV2_ENABLE_FILESYSTEM_ACCESS=OFF
45 -DEXIV2_BUILD_EXIV2_COMMAND=OFF
48 if(NOT CMAKE_CXX_COMPILER_LAUNCHER STREQUAL "")
49 list(APPEND CMAKE_ARGS -DBUILD_WITH_CCACHE=ON)
55 include(cmake/scripts/common/ModuleHelpers.cmake)
61 find_package(exiv2 CONFIG QUIET
62 HINTS ${DEPENDS_PATH}/lib/cmake
63 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
65 # Check for existing EXIV2. If version >= EXIV2-VERSION file version, dont build
66 if((exiv2_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_EXIV2) OR
67 ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_EXIV2))
71 if(TARGET Exiv2::exiv2lib OR TARGET exiv2lib)
72 # We create variables based off TARGET data for use with FPHSA
73 # exiv2 < 0.28 uses a non namespaced target, but also has an alias. Prioritise
74 # namespaced target, and fallback to old target for < 0.28
75 if(TARGET Exiv2::exiv2lib)
76 set(_exiv_target_name Exiv2::exiv2lib)
78 set(_exiv_target_name exiv2lib)
81 # This is for the case where a distro provides a non standard (Debug/Release) config type
82 # eg Debian's config file is exiv2Config-none.cmake
83 # convert this back to either DEBUG/RELEASE or just RELEASE
84 # we only do this because we use find_package_handle_standard_args for config time output
85 # and it isnt capable of handling TARGETS, so we have to extract the info
86 get_target_property(_EXIV2_CONFIGURATIONS ${_exiv_target_name} IMPORTED_CONFIGURATIONS)
87 foreach(_exiv2_config IN LISTS _EXIV2_CONFIGURATIONS)
88 # Some non standard config (eg None on Debian)
89 # Just set to RELEASE var so select_library_configurations can continue to work its magic
90 string(TOUPPER ${_exiv2_config} _exiv2_config_UPPER)
91 if((NOT ${_exiv2_config_UPPER} STREQUAL "RELEASE") AND
92 (NOT ${_exiv2_config_UPPER} STREQUAL "DEBUG"))
93 get_target_property(EXIV2_LIBRARY_RELEASE ${_exiv_target_name} IMPORTED_LOCATION_${_exiv2_config_UPPER})
95 get_target_property(EXIV2_LIBRARY_${_exiv2_config_UPPER} ${_exiv_target_name} IMPORTED_LOCATION_${_exiv2_config_UPPER})
99 get_target_property(EXIV2_INCLUDE_DIR ${_exiv_target_name} INTERFACE_INCLUDE_DIRECTORIES)
101 find_package(PkgConfig)
102 # Fallback to pkg-config and individual lib/include file search
104 pkg_check_modules(PC_EXIV2 exiv2 QUIET)
105 set(EXIV2_VER ${PC_EXIV2_VERSION})
108 find_path(EXIV2_INCLUDE_DIR NAMES exiv2/exiv2.hpp
109 HINTS ${PC_EXIV2_INCLUDEDIR})
110 find_library(EXIV2_LIBRARY_RELEASE NAMES exiv2
111 HINTS ${PC_EXIV2_LIBDIR})
115 include(SelectLibraryConfigurations)
116 select_library_configurations(EXIV2)
117 unset(EXIV2_LIBRARIES)
119 include(FindPackageHandleStandardArgs)
120 find_package_handle_standard_args(Exiv2
121 REQUIRED_VARS EXIV2_LIBRARY EXIV2_INCLUDE_DIR
122 VERSION_VAR EXIV2_VER)
125 if((TARGET Exiv2::exiv2lib OR TARGET exiv2lib) AND NOT TARGET exiv2)
126 # Exiv alias exiv2lib in their latest cmake config. We test for the alias
127 # to workout what we need to point OUR alias at.
128 get_target_property(_EXIV2_ALIASTARGET exiv2lib ALIASED_TARGET)
129 if(_EXIV2_ALIASTARGET)
130 set(_exiv_target_name ${_EXIV2_ALIASTARGET})
132 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS ${_exiv_target_name})
134 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
135 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
136 INTERFACE_INCLUDE_DIRECTORIES "${EXIV2_INCLUDE_DIR}")
138 if(EXIV2_LIBRARY_RELEASE)
139 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
140 IMPORTED_CONFIGURATIONS RELEASE
141 IMPORTED_LOCATION_RELEASE "${EXIV2_LIBRARY_RELEASE}")
143 if(EXIV2_LIBRARY_DEBUG)
144 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
145 IMPORTED_LOCATION_DEBUG "${EXIV2_LIBRARY_DEBUG}")
146 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
147 IMPORTED_CONFIGURATIONS DEBUG)
150 if(CORE_SYSTEM_NAME STREQUAL "freebsd")
151 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
152 INTERFACE_LINK_LIBRARIES procstat)
153 elseif(CORE_SYSTEM_NAME MATCHES "windows")
154 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
155 INTERFACE_LINK_LIBRARIES psapi)
160 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} exiv2)
163 # Add internal build target when a Multi Config Generator is used
164 # We cant add a dependency based off a generator expression for targeted build types,
165 # https://gitlab.kitware.com/cmake/cmake/-/issues/19467
166 # therefore if the find heuristics only find the library, we add the internal build
167 # target to the project to allow user to manually trigger for any build type they need
168 # in case only a specific build type is actually available (eg Release found, Debug Required)
169 # This is mainly targeted for windows who required different runtime libs for different
170 # types, and they arent compatible
171 if(_multiconfig_generator)
174 set_target_properties(exiv2 PROPERTIES EXCLUDE_FROM_ALL TRUE)
176 add_dependencies(build_internal_depends exiv2)
179 if(Exiv2_FIND_REQUIRED)
180 message(FATAL_ERROR "Could NOT find or build Exiv2 library. You may want to try -DENABLE_INTERNAL_EXIV2=ON")