From bc1e9ad93e8bc8181636ce003acfb790babf7f23 Mon Sep 17 00:00:00 2001 From: Hannes Vogt Date: Thu, 20 Dec 2018 17:10:18 +0100 Subject: [PATCH] CMake: support for build tree SerialboxConfig.cmake (#184) Serialbox will register itself to the CMake registry which allows that it is automatically discovered with libraries in the build tree and includes from the src tree. This allows IDEs to resolve inter-project symbol lookup. --- CMakeLists.txt | 27 ++++++----------------- cmake/{CMakeLists.txt => Packaging.cmake} | 19 +++++++++++++++- cmake/SerialboxConfig.cmake.in | 2 +- cmake/SerialboxConfig.sh.in | 11 --------- 4 files changed, 26 insertions(+), 33 deletions(-) rename cmake/{CMakeLists.txt => Packaging.cmake} (66%) delete mode 100644 cmake/SerialboxConfig.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 42ee73e2..97e67f44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -389,34 +389,18 @@ configure_file(${SERIALBOX_CXX_CONFIG_FILE_IN} ${SERIALBOX_CXX_CONFIG_FILE}) install(FILES ${SERIALBOX_CXX_CONFIG_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/serialbox/core) -# building for development -option(SERIALBOX_DEVELOPMENT "If enabled, headers will be installed as symlinks to the src directory, to allow IDEs to jump between files" OFF) - # Install serialbox headers -if(NOT SERIALBOX_DEVELOPMENT) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox DESTINATION include - FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox DESTINATION include + FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") - if(SERIALBOX_ENABLE_C) +if(SERIALBOX_ENABLE_C) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox-c DESTINATION include - FILES_MATCHING PATTERN "*.h") - endif() -else() - # install symlinks for each header from the install location to the src location - file(GLOB_RECURSE header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/*.h" "src/*.hpp") - foreach(file ${header_files}) - get_filename_component(directory ${file} DIRECTORY) - install(DIRECTORY DESTINATION include/${directory}) # create folder - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/src/${file} ${CMAKE_INSTALL_PREFIX}/include/${file})") - endforeach() + FILES_MATCHING PATTERN "*.h") endif() ## Build Serialbox add_subdirectory(src) -## Install FindSerialbox.cmake -add_subdirectory(cmake) - ## Build unittests if(SERIALBOX_TESTING) enable_testing() @@ -454,3 +438,6 @@ if(SERIALBOX_TESTING) serialbox_test_end() endif(SERIALBOX_TESTING) +include(cmake/Packaging.cmake) + + diff --git a/cmake/CMakeLists.txt b/cmake/Packaging.cmake similarity index 66% rename from cmake/CMakeLists.txt rename to cmake/Packaging.cmake index bcf03605..cca7b1c2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/Packaging.cmake @@ -7,7 +7,8 @@ ## ##===------------------------------------------------------------------------------------------===## -cmake_minimum_required(VERSION 3.12) +# this registers the build-tree with a global CMake-registry +export(PACKAGE Serialbox) include(CMakePackageConfigHelpers) @@ -38,3 +39,19 @@ write_basic_package_version_file( ) install(FILES "${PROJECT_BINARY_DIR}/cmake/SerialboxConfigVersion.cmake" DESTINATION cmake) +## For build tree +export(TARGETS SerialboxStatic SerialboxObjects SerialboxFilesytemTarget + FILE ${PROJECT_BINARY_DIR}/SerialboxTargets.cmake + NAMESPACE Serialbox:: +) + +configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/SerialboxConfig.cmake.in + ${PROJECT_BINARY_DIR}/SerialboxConfig.cmake + INSTALL_DESTINATION ${PROJECT_BINARY_DIR} + PATH_VARS CMAKE_INSTALL_DIR +) +write_basic_package_version_file( + ${PROJECT_BINARY_DIR}/SerialboxConfigVersion.cmake + VERSION ${Serialbox_VERSION_STRING} + COMPATIBILITY AnyNewerVersion +) diff --git a/cmake/SerialboxConfig.cmake.in b/cmake/SerialboxConfig.cmake.in index 9c10cfce..32ed6d5e 100644 --- a/cmake/SerialboxConfig.cmake.in +++ b/cmake/SerialboxConfig.cmake.in @@ -45,7 +45,7 @@ set(SERIALBOX_REQUIRED_BOOST_COMPONENTS "@REQUIRED_BOOST_COMPONENTS@") #====--------------------------------------------------------------------------------------------=== # Import library targets -include("@PACKAGE_CMAKE_INSTALL_DIR@/SerialboxTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/SerialboxTargets.cmake") set(SERIALBOX_HAS_SHARED_LIBRARY FALSE) if(TARGET Serialbox::SerialboxShared) diff --git a/cmake/SerialboxConfig.sh.in b/cmake/SerialboxConfig.sh.in deleted file mode 100644 index 870bd722..00000000 --- a/cmake/SerialboxConfig.sh.in +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -### Serialbox CONFIGURATION -################################# -# -# -# Generated by CMake - -export SERIALBOX_FORTRAN_LIBRARIES="@SERIALBOX_FORTRAN_LIBRARIES_AS_STRING@" -export SERIALBOX_CXX_LIBRARIES="@SERIALBOX_CXX_LIBRARIES_AS_STRING@" -export SERIALBOX_C_LIBRARIES="@SERIALBOX_C_LIBRARIES_AS_STRING@" -