From 86044eec560a2e6dccc37812bb07737774013220 Mon Sep 17 00:00:00 2001 From: Koen van de Sande Date: Thu, 5 Feb 2026 14:59:50 +0100 Subject: [PATCH] Make installable with make install --- CMakeLists.txt | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5473904e..1710821a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,8 +56,61 @@ add_library (cryptolens ${CRYPTOLENS_LIBRARY_TYPE} ${SRC}) target_link_libraries (cryptolens ${LIBS}) target_include_directories (cryptolens PRIVATE "${cryptolens_SOURCE_DIR}/include/cryptolens") target_include_directories (cryptolens PRIVATE "${cryptolens_SOURCE_DIR}/third_party/ArduinoJson7") -target_include_directories (cryptolens PUBLIC "${cryptolens_SOURCE_DIR}/include") +target_include_directories (cryptolens PUBLIC + $ + $ +) if (${CRYPTOLENS_BUILD_TESTS}) add_subdirectory (tests) endif () + +# Installation +include(GNUInstallDirs) + +install(TARGETS cryptolens + EXPORT cryptolensTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +install(DIRECTORY ${cryptolens_SOURCE_DIR}/include/cryptolens + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(EXPORT cryptolensTargets + FILE cryptolensTargets.cmake + NAMESPACE cryptolens:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cryptolens +) + +# Generate and install package config files +include(CMakePackageConfigHelpers) + +# Create a basic config file +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfig.cmake.in +"@PACKAGE_INIT@ + +include(\"\${CMAKE_CURRENT_LIST_DIR}/cryptolensTargets.cmake\") + +check_required_components(cryptolens) +") + +configure_package_config_file( + ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cryptolens +) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfigVersion.cmake + VERSION 1.3.0 + COMPATIBILITY SameMajorVersion +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/cryptolensConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cryptolens +)