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 cmake package config #709

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
33 changes: 30 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ if(BUILD_STATIC_LIBS)
set_target_properties(fido2 PROPERTIES OUTPUT_NAME fido2_static)
endif()
target_link_libraries(fido2 ${TARGET_LIBRARIES})
install(TARGETS fido2 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS fido2
EXPORT libfido2Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

# dynamic library
Expand All @@ -143,9 +146,11 @@ if(BUILD_SHARED_LIBS)
VERSION ${FIDO_VERSION} SOVERSION ${FIDO_MAJOR})
target_link_libraries(fido2_shared ${TARGET_LIBRARIES})
install(TARGETS fido2_shared
EXPORT libfido2Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()

install(FILES fido.h DESTINATION include)
Expand All @@ -156,3 +161,25 @@ if(NOT MSVC)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfido2.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()

include(CMakePackageConfigHelpers)
export(PACKAGE libfido2)
configure_package_config_file(
libfido2Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/libfido2Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libfido2
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/libfido2ConfigVersion.cmake
VERSION ${FIDO_VERSION}
COMPATIBILITY SameMajorVersion
)
install(EXPORT libfido2Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libfido2)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libfido2Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/libfido2ConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/libfido2
)
10 changes: 10 additions & 0 deletions src/libfido2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(FIDO_VERSION @FIDO_VERSION@)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it canonical to set a variable like this? I was under the impression that this was already handled by write_basic_package_version_file() (albeit under a slightly different variable name).

Copy link
Author

Choose a reason for hiding this comment

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

yes, write_basic_package_version_file provides it under a different name, so I did define this. can change it though.


@PACKAGE_INIT@

set_and_check(FIDO_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(FIDO_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
Comment on lines +5 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these necessary given the exported targets (maybe needs INCLUDES DESTINATION)?

Copy link
Author

Choose a reason for hiding this comment

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

hmm, indeed. https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html seems to be what should be set for the target


check_required_components(libfido2)

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