2022-10-19 16:37:20 +00:00
|
|
|
find_program(makeheaders_EXECUTABLE makeheaders)
|
|
|
|
mark_as_advanced(makeheaders_EXECUTABLE)
|
2022-10-17 20:14:33 +00:00
|
|
|
|
2022-10-19 16:37:20 +00:00
|
|
|
if(makeheaders_EXECUTABLE)
|
2022-10-17 20:14:33 +00:00
|
|
|
add_executable(makeheaders IMPORTED)
|
|
|
|
set_target_properties(makeheaders PROPERTIES
|
2022-10-19 16:37:20 +00:00
|
|
|
IMPORTED_LOCATION ${makeheaders_EXECUTABLE})
|
2022-10-17 20:14:33 +00:00
|
|
|
else()
|
|
|
|
add_executable(makeheaders ${CMAKE_CURRENT_LIST_DIR}/makeheaders.c)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
unset(_MAKEHEADERS)
|
|
|
|
|
|
|
|
function(target_makeheaders target)
|
|
|
|
get_target_property(binary_dir ${target} BINARY_DIR)
|
|
|
|
get_target_property(source_dir ${target} SOURCE_DIR)
|
|
|
|
get_target_property(sources ${target} SOURCES)
|
|
|
|
foreach(source ${sources})
|
|
|
|
cmake_path(REPLACE_EXTENSION source h OUTPUT_VARIABLE header)
|
|
|
|
cmake_path(ABSOLUTE_PATH source
|
|
|
|
BASE_DIRECTORY ${source_dir}
|
|
|
|
NORMALIZE)
|
|
|
|
list(APPEND makeheader_args ${source}:${header})
|
|
|
|
cmake_path(ABSOLUTE_PATH header
|
|
|
|
BASE_DIRECTORY ${binary_dir}
|
|
|
|
NORMALIZE)
|
|
|
|
list(APPEND generated_headers ${header})
|
|
|
|
endforeach()
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${generated_headers}
|
|
|
|
COMMAND makeheaders -local -- ${makeheader_args}
|
|
|
|
DEPENDS ${sources}
|
|
|
|
COMMENT "Generating headers for target ${target}"
|
|
|
|
VERBATIM)
|
|
|
|
target_sources(${target} PRIVATE ${generated_headers})
|
|
|
|
target_include_directories(${target} PRIVATE ${binary_dir})
|
|
|
|
endfunction()
|