gdraheim / zziplib

The ZZIPlib provides read access on ZIP-archives and unpacked data. It features an additional simplified API following the standard Posix API for file access
Other
60 stars 50 forks source link

CMake project doesn't export targets #134

Closed vividos closed 1 year ago

vividos commented 2 years ago

I'm trying to include zziplib into my project using vcpkg and like to use find_package(zziplib REQUIRED) to automatically configure includes and libs. Unfortunately that fails, and according to vcpkg folks, the only missing thing is that in zzip/CMakeFiles.txt, the project doesn't export its targets. See also my issue I opened in vcpkg project: https://github.com/microsoft/vcpkg/issues/25186

From reading CMake documentation I gather that these lines should be changed:

https://github.com/gdraheim/zziplib/blob/ec0364a245d869a509481d80fc19c70cf945cee7/zzip/CMakeLists.txt#L263-L266 The lines could look like this:

install(TARGETS libzzip 
    EXPORT libzzip
    RUNTIME ...

What do you think? Could the line be added?

Osyotr commented 2 years ago

Not exactly a one line change, but still pretty straightforward:

install(TARGETS libzzip 
    EXPORT libzzipTargets # note Targets suffix
    RUNTIME ...
)

And then install config files:

install(EXPORT libzippTargets
    NAMESPACE libzipp::
    DESTINATION share/zziplib
)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/zziplibConfig.cmake.in"
[[include(CMakeFindDependencyMacro)
find_dependency(ZLIB)
file(GLOB TARGET_FILES "${CMAKE_CURRENT_LIST_DIR}/*Targets.cmake")
foreach (TARGET_FILE ${TARGET_FILES})
    include("${TARGET_FILE}")
endforeach()
]])
configure_file("${CMAKE_CURRENT_BINARY_DIR}/zziplibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/zziplibConfig.cmake" @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zziplibConfig.cmake DESTINATION share/zziplib)

This should be done for each target that needs to be exported.

vividos commented 2 years ago

Thanks Osyotr for the details!

gdraheim commented 1 year ago

Looks interesting, I did not know that cmake has its own library export format. I can not really support the solution but I hope you keep an eye on it.