myx/MyxCMake/lib/generators/PrivateConfigHeader.cmake
2024-04-08 22:49:13 +03:00

41 lines
1.7 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#[=======================================================================[.rst:
myx_generate_private_config_header
----------------------------------
Вспомогательная функция для автоматической генерации заголовочного
файла, содержащего информацию о проекте::
myx_generate_private_config_header(TARGET_NAME BASE_FILENAME)
Обязательные параметры: `TARGET_NAME` - имя цели, с которой связан
заголовочный файл, и `BASE_FILENAME` - имя генерируемого заголовочного файла.
#]=======================================================================]
include_guard(GLOBAL)
if(${CMAKE_VERSION} VERSION_LESS 3.17.0)
set(MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT "${CMAKE_CURRENT_LIST_DIR}")
endif()
function(myx_generate_private_config_header TARGET_NAME BASE_FILENAME)
if(${CMAKE_VERSION} VERSION_LESS 3.17.0)
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${MYX_CMAKE_LIB_GENERATORS_DIR_BACKPORT})
endif()
set(BUILD_DATE ${MYX_TODAY})
myx_project_version_int()
get_property(PROJECT_VERSION_INT GLOBAL PROPERTY PROJECT_VERSION_INT)
set(filename "${PROJECT_BINARY_DIR}/include/${BASE_FILENAME}")
configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PrivateConfig.hpp.in" ${filename})
get_target_property(target_type ${TARGET_NAME} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
target_sources(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${filename}>)
else()
set_property(TARGET ${TARGET_NAME} APPEND PROPERTY PRIVATE_HEADER_FILES ${filename})
target_sources(${TARGET_NAME} PRIVATE ${filename})
endif()
endfunction()