From b5e5b18844b94044cbb0a2487b01d03fc1c91f38 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 8 Aug 2023 12:39:15 +0200 Subject: [PATCH] Improve integration when doing it as sub-project --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88b68a5..be7c83a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,8 @@ if (${PROJECT_NAME}_BUILD_COMPONENT_Binarize) endif () endif() +set(namespace "${PROJECT_NAME}::") + if (${PROJECT_NAME}_BUILD_COMPONENT_Convert) set(Boost_VERSION 1.78) find_package(Boost ${Boost_VERSION} REQUIRED) @@ -51,6 +53,9 @@ if (${PROJECT_NAME}_BUILD_COMPONENT_Convert) endif () endif () +# For includes to be the same when integrating as sub-project and when using fing_package +file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} SYMBOLIC) + # Create an export header include(GenerateExportHeader) @@ -72,6 +77,8 @@ target_include_directories(${_libname}_core $ ) +add_library(${namespace}${_libname}_core ALIAS ${_libname}_core) + if (${PROJECT_NAME}_BUILD_COMPONENT_Binarize) # Binarize component add_library(${_libname}_binarize @@ -82,6 +89,8 @@ if (${PROJECT_NAME}_BUILD_COMPONENT_Binarize) # Add more source files here if needed ) + add_library(${namespace}${_libname}_binarize ALIAS ${_libname}_binarize) + generate_export_header(${_libname}_binarize EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/binarize/export.h ) @@ -108,6 +117,8 @@ if (${PROJECT_NAME}_BUILD_COMPONENT_Convert) # Add more source files here if needed ) + add_library(${namespace}${_libname}_convert ALIAS ${_libname}_convert) + generate_export_header(${_libname}_convert EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/convert/export.h ) @@ -154,7 +165,6 @@ set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") set(version_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(project_config "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") -set(namespace "${PROJECT_NAME}::") list(GET _selected_components -1 _highest_comp) foreach(_comp ${_selected_components})