From 764442f0f489453199a86bf08656d8a01aca52a1 Mon Sep 17 00:00:00 2001 From: BryanFlynt <72622421+BryanFlynt@users.noreply.github.com> Date: Sat, 5 Nov 2022 15:45:17 -0600 Subject: [PATCH 1/2] Update CMakeLists.txt Added ARGPARSE_INSTALL This allows a separate project using argparse through CMake FetchContent_Declare(...) to install the project without having to also install argparse. --- CMakeLists.txt | 117 +++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb359d5f..6f12e13f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ project(argparse LANGUAGES CXX ) +option(ARGPARSE_INSTALL OFF) option(ARGPARSE_BUILD_TESTS OFF) option(ARGPARSE_LONG_VERSION_ARG_ONLY OFF) @@ -36,63 +37,65 @@ if(ARGPARSE_BUILD_TESTS) add_subdirectory(test) endif() -install(TARGETS argparse EXPORT argparseConfig) -install(EXPORT argparseConfig - NAMESPACE argparse:: - DESTINATION ${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}) -install(FILES ${CMAKE_CURRENT_LIST_DIR}/include/argparse/argparse.hpp - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/argparse) - - -set(CONFIG_FILE_NAME_WITHOUT_EXT "${PROJECT_NAME}Config") -set(CMAKE_CONFIG_FILE_BASENAME "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_NAME_WITHOUT_EXT}") -set(CMAKE_CONFIG_VERSION_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}-version.cmake") -set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}.cmake") - -if(${CMAKE_VERSION} VERSION_GREATER "3.14") - set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") -endif() - -write_basic_package_version_file("${CMAKE_CONFIG_VERSION_FILE_NAME}" - COMPATIBILITY ExactVersion - ${OPTIONAL_ARCH_INDEPENDENT} -) - -export(EXPORT argparseConfig - NAMESPACE argparse::) - -install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}" - DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}") - -set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging") - -set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") -set(CPACK_PACKAGE_VENDOR "argparse (C++) developers") -set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") -set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") -set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") -set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") -set(CPACK_PACKAGE_MAINTAINER "Pranav Srinivas Kumar") -set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}") -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") -set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") - -set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev") -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev") -set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf") - -set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel") -set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}") - -set(CPACK_DEB_COMPONENT_INSTALL ON) -set(CPACK_RPM_COMPONENT_INSTALL ON) -set(CPACK_NSIS_COMPONENT_INSTALL ON) -set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") - -set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc") -configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) -install(FILES "${PKG_CONFIG_FILE_NAME}" +if(ARGPARSE_INSTALL) + install(TARGETS argparse EXPORT argparseConfig) + install(EXPORT argparseConfig + NAMESPACE argparse:: + DESTINATION ${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}) + install(FILES ${CMAKE_CURRENT_LIST_DIR}/include/argparse/argparse.hpp + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/argparse) + + + set(CONFIG_FILE_NAME_WITHOUT_EXT "${PROJECT_NAME}Config") + set(CMAKE_CONFIG_FILE_BASENAME "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_NAME_WITHOUT_EXT}") + set(CMAKE_CONFIG_VERSION_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}-version.cmake") + set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CONFIG_FILE_BASENAME}.cmake") + + if(${CMAKE_VERSION} VERSION_GREATER "3.14") + set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT") + endif() + + write_basic_package_version_file("${CMAKE_CONFIG_VERSION_FILE_NAME}" + COMPATIBILITY ExactVersion + ${OPTIONAL_ARCH_INDEPENDENT} + ) + + export(EXPORT argparseConfig + NAMESPACE argparse::) + + install(FILES "${CMAKE_CONFIG_VERSION_FILE_NAME}" + DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/${PROJECT_NAME}") + + set(PackagingTemplatesDir "${CMAKE_CURRENT_SOURCE_DIR}/packaging") + + set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + set(CPACK_PACKAGE_VENDOR "argparse (C++) developers") + set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") + set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") + set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") + set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}") + set(CPACK_PACKAGE_MAINTAINER "Pranav Srinivas Kumar") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + + set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev") + set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev") + set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf") + + set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel") + set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}") + + set(CPACK_DEB_COMPONENT_INSTALL ON) + set(CPACK_RPM_COMPONENT_INSTALL ON) + set(CPACK_NSIS_COMPONENT_INSTALL ON) + set(CPACK_DEBIAN_COMPRESSION_TYPE "xz") + + set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc") + configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY) + install(FILES "${PKG_CONFIG_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig" -) + ) +endif() include(CPack) From d201a3e1df3bfef2bc9fbc7458350e9b61e871e6 Mon Sep 17 00:00:00 2001 From: BryanFlynt <72622421+BryanFlynt@users.noreply.github.com> Date: Sat, 5 Nov 2022 15:47:39 -0600 Subject: [PATCH 2/2] Update CMakeLists.txt Default ON for ARGPARSE_INSTALL --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f12e13f..ddc87c57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ project(argparse LANGUAGES CXX ) -option(ARGPARSE_INSTALL OFF) +option(ARGPARSE_INSTALL ON) option(ARGPARSE_BUILD_TESTS OFF) option(ARGPARSE_LONG_VERSION_ARG_ONLY OFF)