From cbc7e3c1b0e617f704674cc547b5a6eebad5b362 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 12 Dec 2018 15:26:18 +0800 Subject: [PATCH 1/2] Adds CMake library and install target --- CMakeLists.txt | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e060df..47b1a25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,21 @@ cmake_minimum_required(VERSION 3.8.2) -project(Clara) +project(Clara VERSION 1.1.5) -set(SOURCE_FILES src/main.cpp src/ClaraTests.cpp include/clara.hpp) -include_directories( include third_party ) +include(GNUInstallDirs) + +add_library(Clara INTERFACE) +add_library(Clara::Clara ALIAS Clara) +target_include_directories(Clara + INTERFACE + "$" + "$") +target_compile_features(Clara + INTERFACE cxx_trailing_return_types) + +set(SOURCE_FILES src/main.cpp src/ClaraTests.cpp) add_executable(ClaraTests ${SOURCE_FILES}) +target_include_directories(ClaraTests PRIVATE third_party) +target_link_libraries(ClaraTests PRIVATE Clara::Clara) if(USE_CPP14) set_property(TARGET ClaraTests PROPERTY CXX_STANDARD 14) @@ -37,3 +49,24 @@ endif() include(CTest) add_test(NAME RunTests COMMAND $) + +set(target_export_name "${PROJECT_NAME}Targets") +set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +set(version_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") + +# install headers +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/single_include/" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# install project config +install(TARGETS Clara EXPORT ${target_export_name}) +install(EXPORT ${target_export_name} + NAMESPACE Clara:: + DESTINATION ${config_install_dir} + FILE "${PROJECT_NAME}Config.cmake") + +# install version config +include(CMakePackageConfigHelpers) +write_basic_package_version_file(${version_config} + COMPATIBILITY SameMajorVersion) +install(FILES ${version_config} DESTINATION ${config_install_dir}) From ba9db5b0829344e41c07032a2772758995f14a66 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 3 May 2019 07:16:06 +0800 Subject: [PATCH 2/2] Remove architecture check from CMake package Reference: * https://github.com/onqtam/doctest/pull/225 * https://github.com/catchorg/Catch2/issues/1368 --- CMakeLists.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47b1a25..85dcdb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,17 @@ install(EXPORT ${target_export_name} # install version config include(CMakePackageConfigHelpers) + +# CMake automatically adds an architecture compatibility check to make sure +# 32 and 64 bit code is not accidentally mixed. For a header-only library this +# is not required. The check can be disabled by temporarily unsetting +# CMAKE_SIZEOF_VOID_P. In CMake 3.14 and later this can be achieved more cleanly +# with write_basic_package_version_file(ARCH_INDEPENDENT). +# TODO: Use this once a newer CMake can be required. +set(CLARA_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) +unset(CMAKE_SIZEOF_VOID_P) write_basic_package_version_file(${version_config} COMPATIBILITY SameMajorVersion) +set(CMAKE_SIZEOF_VOID_P ${CLARA_SIZEOF_VOID_P}) + install(FILES ${version_config} DESTINATION ${config_install_dir})