Исправление включения файлов в интерфейсную библиотеку

This commit is contained in:
Andrei Astafev 2024-03-28 10:57:43 +03:00
parent 01e095e99c
commit a4b841d852
2 changed files with 14 additions and 9 deletions

View File

@ -31,26 +31,31 @@ function(myx_generate_git_info_header TARGET_NAME BASE_FILENAME)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(__filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
file(APPEND ${__filename} "")
set(filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
file(APPEND ${filename} "")
set(__prefix "")
set(prefix "")
if(ARG_PREFIX)
string(APPEND ARG_PREFIX "_")
string(REPLACE "-" "_" __prefix ${ARG_PREFIX})
string(REPLACE "-" "_" prefix ${ARG_PREFIX})
endif()
# cmake-format: off
if(NOT TARGET ${TARGET_NAME}-git-info-header)
add_custom_target(${TARGET_NAME}-git-info-header ALL
${CMAKE_COMMAND} -DGIT_INFO_FILE=${__filename} -DPREFIX=${__prefix}
${CMAKE_COMMAND} -DGIT_INFO_FILE=${filename} -DPREFIX=${prefix}
-P ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/GitInfo.cmake
BYPRODUCTS ${__filename}
BYPRODUCTS ${filename}
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR})
endif()
# cmake-format: on
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${__filename})
target_sources(${TARGET_NAME} PRIVATE ${__filename})
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
get_target_property(target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${filename}>)
else()
target_sources(${TARGET_NAME} PRIVATE ${filename})
endif()
add_dependencies(${TARGET_NAME} ${TARGET_NAME}-git-info-header)
endfunction()

View File

@ -33,7 +33,7 @@ function(myx_generate_private_config_header TARGET_NAME BASE_FILENAME)
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
get_target_property(target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE ${filename})
target_sources(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${filename}>)
else()
target_sources(${TARGET_NAME} PRIVATE ${filename})
endif()