Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cmake config file export #2703

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)

find_package(exiv2 REQUIRED CONFIG NAMES exiv2) # search ${CMAKE_INSTALL_PREFIX}/lib/cmake/exiv2/
add_executable(exifprint ../samples/exifprint.cpp) # Create exifprint target
target_link_libraries(exifprint PRIVATE exiv2lib) # link exiv2lib
target_link_libraries(exifprint PRIVATE Exiv2::exiv2lib) # link exiv2lib
EOF
$ cmake . # generate the makefile
$ cmake --build . # build the code
Expand Down
12 changes: 12 additions & 0 deletions cmake/exiv2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@PACKAGE_INIT@

cmake_minimum_required(VERSION 3.5)
include(CMakeFindDependencyMacro)

if(@EXIV2_ENABLE_PNG@) # if(EXIV2_ENABLE_PNG)
find_dependency(ZLIB REQUIRED)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/exiv2Export.cmake")

check_required_components(exiv2)
23 changes: 17 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ add_library( exiv2lib
${PUBLIC_HEADERS}
$<TARGET_OBJECTS:exiv2lib_int>
)
add_library(Exiv2::exiv2lib ALIAS exiv2lib)

generate_export_header(exiv2lib
EXPORT_MACRO_NAME EXIV2API
Expand Down Expand Up @@ -283,10 +284,13 @@ set(requires_private_for_pc_file "${requires_private_string}" PARENT_SCOPE)

write_basic_package_version_file(exiv2ConfigVersion.cmake COMPATIBILITY ExactVersion)

install(TARGETS exiv2lib EXPORT exiv2Config
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
install(TARGETS exiv2lib EXPORT exiv2Export)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CMake 3.14 and above, you don't need to supply the RUNTIME, LIBRARY, and ARCHIVE directories. This relies on the defaults, which conveniently were the same as before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As CMake was reduced to 3.5, is this still relevant?

Copy link
Contributor Author

@Ryanf55 Ryanf55 Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! This cmake version required to build exiv2 is 3.16.3 which is when this line of code runs. This version is unchanged in this PR.

The version required to consume exiv2 is now 3.5. Previously, no such minimum version was specified, it was undefined.

They are independent.


include(CMakePackageConfigHelpers)
configure_package_config_file(
../cmake/exiv2Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/exiv2Config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/exiv2"
)

install(FILES
Expand All @@ -295,7 +299,14 @@ install(FILES
${CMAKE_BINARY_DIR}/exiv2lib_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/exiv2)

install(EXPORT exiv2Config DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/exiv2")
install(EXPORT exiv2Export
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/exiv2"
NAMESPACE Exiv2::
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/exiv2ConfigVersion.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/exiv2")
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/exiv2ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/exiv2Config.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/exiv2")

Loading