Skip to content

Commit

Permalink
add FindPNG Module compatbile CMake Config File
Browse files Browse the repository at this point in the history
  • Loading branch information
bebuch committed Mar 1, 2024
1 parent f1848a3 commit 908dcf9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,30 @@ if(NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL)
FILE libpng${PNGLIB_ABI_VERSION}.cmake)
endif()

# Create a CMake Config File that can be used via find_package(PNG CONFIG)
if(NOT SKIP_INSTALL_CONFIG_FILE AND NOT SKIP_INSTALL_ALL)
install(TARGETS ${PNG_LIBRARY_TARGETS}
EXPORT PNGTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})

include(CMakePackageConfigHelpers)
write_basic_package_version_file(PNGConfigVersion.cmake
VERSION ${PNGLIB_VERSION}
COMPATIBILITY SameMinorVersion)

install(EXPORT PNGTargets
FILE PNGTargets.cmake
NAMESPACE PNG::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PNG)

install(FILES PNGConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/PNGConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/PNG)
endif()

# TODO: Create MSVC import lib for MinGW-compiled shared lib.
# pexports libpng.dll > libpng.def
# lib /def:libpng.def /machine:x86
15 changes: 15 additions & 0 deletions PNGConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include(CMakeFindDependencyMacro)

find_dependency(ZLIB REQUIRED)

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

if(NOT TARGET PNG::PNG)
if(TARGET PNG::png_shared)
add_library(PNG::PNG INTERFACE IMPORTED)
target_link_libraries(PNG::PNG INTERFACE PNG::png_shared)
elseif(TARGET PNG::png_static)
add_library(PNG::PNG INTERFACE IMPORTED)
target_link_libraries(PNG::PNG INTERFACE PNG::png_static)
endif()
endif()

0 comments on commit 908dcf9

Please sign in to comment.