From c82e54edac576820fe2a99cd00203554ee2833ac Mon Sep 17 00:00:00 2001 From: Dan Dees Date: Wed, 11 May 2022 07:19:47 +0700 Subject: [PATCH] add cmake package From your cmake project ----------------------- find_package(verdigris CONFIG REQUIRED) target_link_libraries(${libname} PUBLIC ... verdigris::verdigris ) Todo ---- - build and run tests and benchmarks Build result ------------ [0/1] Install the project... -- Install configuration: "Release" -- Up-to-date: INSTALLDIR/share/verdigris/cmake/verdigrisTargets.cmake -- Up-to-date: INSTALLDIR/share/verdigris/cmake/verdigrisConfig.cmake -- Up-to-date: INSTALLDIR/share/verdigris/cmake/verdigrisConfigVersion.cmake -- Installing: INSTALLDIR/include/verdigris/wobjectcpp.h -- Installing: INSTALLDIR/include/verdigris/wobjectdefs.h -- Installing: INSTALLDIR/include/verdigris/wobjectimpl.h --- CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++ cmake/verdigrisConfig.cmake.in | 4 +++ 2 files changed, 63 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/verdigrisConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c64188f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 3.12) +# https://dominikberner.ch/cmake-interface-lib/ + +project( + "verdigris" + VERSION 1.2.0 + HOMEPAGE_URL "https://github.com/woboq/verdigris") + +set(libname "verdigris") + +add_library(${libname} INTERFACE) +# add alias so the project can be uses with add_subdirectory +add_library(${libname}::${libname} ALIAS ${libname}) + +include(GNUInstallDirs) + +target_include_directories( + ${libname} + INTERFACE $ + $) + +target_compile_features(${libname} INTERFACE cxx_std_11) + +install(TARGETS ${libname} + EXPORT ${libname}_Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${libname}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${libname}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${libname}Config.cmake" + INSTALL_DESTINATION + ${CMAKE_INSTALL_DATAROOTDIR}/${libname}/cmake) + +install(EXPORT ${libname}_Targets + FILE ${libname}Targets.cmake + NAMESPACE ${libname}:: + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${libname}/cmake) + +install(FILES "${PROJECT_BINARY_DIR}/${libname}Config.cmake" + "${PROJECT_BINARY_DIR}/${libname}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${libname}/cmake) + +install(FILES + ${PROJECT_SOURCE_DIR}/src/wobjectcpp.h + ${PROJECT_SOURCE_DIR}/src/wobjectdefs.h + ${PROJECT_SOURCE_DIR}/src/wobjectimpl.h + DESTINATION include/verdigris) + +set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE.LGPLv3") + +include(CPack) diff --git a/cmake/verdigrisConfig.cmake.in b/cmake/verdigrisConfig.cmake.in new file mode 100644 index 0000000..9c15f36 --- /dev/null +++ b/cmake/verdigrisConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@")