Skip to content

Commit bc1e9ad

Browse files
authored
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.
1 parent 64ad25d commit bc1e9ad

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

CMakeLists.txt

+7-20
Original file line numberDiff line numberDiff line change
@@ -389,34 +389,18 @@ configure_file(${SERIALBOX_CXX_CONFIG_FILE_IN} ${SERIALBOX_CXX_CONFIG_FILE})
389389
install(FILES ${SERIALBOX_CXX_CONFIG_FILE}
390390
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/serialbox/core)
391391

392-
# building for development
393-
option(SERIALBOX_DEVELOPMENT "If enabled, headers will be installed as symlinks to the src directory, to allow IDEs to jump between files" OFF)
394-
395392
# Install serialbox headers
396-
if(NOT SERIALBOX_DEVELOPMENT)
397-
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox DESTINATION include
398-
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
393+
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox DESTINATION include
394+
FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
399395

400-
if(SERIALBOX_ENABLE_C)
396+
if(SERIALBOX_ENABLE_C)
401397
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/serialbox-c DESTINATION include
402-
FILES_MATCHING PATTERN "*.h")
403-
endif()
404-
else()
405-
# install symlinks for each header from the install location to the src location
406-
file(GLOB_RECURSE header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/*.h" "src/*.hpp")
407-
foreach(file ${header_files})
408-
get_filename_component(directory ${file} DIRECTORY)
409-
install(DIRECTORY DESTINATION include/${directory}) # create folder
410-
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/src/${file} ${CMAKE_INSTALL_PREFIX}/include/${file})")
411-
endforeach()
398+
FILES_MATCHING PATTERN "*.h")
412399
endif()
413400

414401
## Build Serialbox
415402
add_subdirectory(src)
416403

417-
## Install FindSerialbox.cmake
418-
add_subdirectory(cmake)
419-
420404
## Build unittests
421405
if(SERIALBOX_TESTING)
422406
enable_testing()
@@ -454,3 +438,6 @@ if(SERIALBOX_TESTING)
454438
serialbox_test_end()
455439
endif(SERIALBOX_TESTING)
456440

441+
include(cmake/Packaging.cmake)
442+
443+

cmake/CMakeLists.txt renamed to cmake/Packaging.cmake

+18-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
##
88
##===------------------------------------------------------------------------------------------===##
99

10-
cmake_minimum_required(VERSION 3.12)
10+
# this registers the build-tree with a global CMake-registry
11+
export(PACKAGE Serialbox)
1112

1213
include(CMakePackageConfigHelpers)
1314

@@ -38,3 +39,19 @@ write_basic_package_version_file(
3839
)
3940
install(FILES "${PROJECT_BINARY_DIR}/cmake/SerialboxConfigVersion.cmake" DESTINATION cmake)
4041

42+
## For build tree
43+
export(TARGETS SerialboxStatic SerialboxObjects SerialboxFilesytemTarget
44+
FILE ${PROJECT_BINARY_DIR}/SerialboxTargets.cmake
45+
NAMESPACE Serialbox::
46+
)
47+
48+
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/SerialboxConfig.cmake.in
49+
${PROJECT_BINARY_DIR}/SerialboxConfig.cmake
50+
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
51+
PATH_VARS CMAKE_INSTALL_DIR
52+
)
53+
write_basic_package_version_file(
54+
${PROJECT_BINARY_DIR}/SerialboxConfigVersion.cmake
55+
VERSION ${Serialbox_VERSION_STRING}
56+
COMPATIBILITY AnyNewerVersion
57+
)

cmake/SerialboxConfig.cmake.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ set(SERIALBOX_REQUIRED_BOOST_COMPONENTS "@REQUIRED_BOOST_COMPONENTS@")
4545
#====--------------------------------------------------------------------------------------------===
4646

4747
# Import library targets
48-
include("@PACKAGE_CMAKE_INSTALL_DIR@/SerialboxTargets.cmake")
48+
include("${CMAKE_CURRENT_LIST_DIR}/SerialboxTargets.cmake")
4949

5050
set(SERIALBOX_HAS_SHARED_LIBRARY FALSE)
5151
if(TARGET Serialbox::SerialboxShared)

cmake/SerialboxConfig.sh.in

-11
This file was deleted.

0 commit comments

Comments
 (0)