Closed vividos closed 1 year 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.
Thanks Osyotr for the details!
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.
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 inzzip/CMakeFiles.txt
, the project doesn't export its targets. See also my issue I opened in vcpkg project: https://github.com/microsoft/vcpkg/issues/25186From 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:
What do you think? Could the line be added?