Skip to content

Commit

Permalink
CMake: support for build tree SerialboxConfig.cmake (#184)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
havogt authored Dec 20, 2018
1 parent 64ad25d commit bc1e9ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
27 changes: 7 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -454,3 +438,6 @@ if(SERIALBOX_TESTING)
serialbox_test_end()
endif(SERIALBOX_TESTING)

include(cmake/Packaging.cmake)


19 changes: 18 additions & 1 deletion cmake/CMakeLists.txt → cmake/Packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion cmake/SerialboxConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions cmake/SerialboxConfig.sh.in

This file was deleted.

0 comments on commit bc1e9ad

Please sign in to comment.