| 1 |
# Copyright (C) 2025 The Qt Company Ltd. |
| 2 |
# SPDX-License-Identifier: BSD-3-Clause |
| 3 |
|
| 4 |
include_guard() |
| 5 |
|
| 6 |
# Check whether ${file_path} is generated during the build phase. |
| 7 |
# We do this by creating a custom command that creates a copy of the file. |
| 8 |
# If the file_path is not known to the build system, ninja will complain. |
| 9 |
# If the file_path is known to the build system but not created, the copy command fails. |
| 10 |
function(check_file_is_built file_path) |
| 11 |
set(out_file "${file_path}.copy") |
| 12 |
add_custom_command( |
| 13 |
OUTPUT "${out_file}" |
| 14 |
DEPENDS "${file_path}" |
| 15 |
COMMAND "${CMAKE_COMMAND}" -E copy "${file_path}" "${out_file}" |
| 16 |
VERBATIM |
| 17 |
) |
| 18 |
|
| 19 |
get_filename_component(target "${file_path}" NAME) |
| 20 |
string(REGEX REPLACE "[ .-]" "_" target "${target}") |
| 21 |
string(PREPEND target "copy_") |
| 22 |
while(TARGET "${target}") |
| 23 |
string(APPEND target "_") |
| 24 |
endwhile() |
| 25 |
add_custom_target("${target}" ALL |
| 26 |
DEPENDS "${out_file}" |
| 27 |
) |
| 28 |
endfunction() |