CMake/Tests/RunCMake/UnityBuild/unitybuild_c_absolute_path-check.cmake
James Moore 84996a65aa Unity: Add option to use relative paths for unity files
Add a target property that will be read on unity file generation to
attempt to use a relative path to the source file from the CMake Source
Directory or the generated unity file. Additionally add the CMake
Source Directory and the CMake Binary directory to the include path of
the generated unity files.

Closes: #26352
2024-10-15 09:44:18 -07:00

18 lines
817 B
CMake

set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c")
if(NOT EXISTS "${unitybuild_c}")
set(RunCMake_TEST_FAILED "Generated unity source file ${unitybuild_c} does not exist.")
return()
endif()
string(JOIN ".*" EXPECTED_UNITY_FILE_CONTENT
[[#include "([A-Za-z]:)?/[^"]*/Tests/RunCMake/UnityBuild/unitybuild_c_absolute_path-build/s1\.c"]]
[[#include "([A-Za-z]:)?/[^"]*/Tests/RunCMake/UnityBuild/unitybuild_c_absolute_path-build/s2\.c"]]
[[#include "([A-Za-z]:)?/[^"]*/Tests/RunCMake/UnityBuild/unitybuild_c_absolute_path-build/s3\.c"]]
)
file(STRINGS ${unitybuild_c} unitybuild_c_strings)
if(NOT unitybuild_c_strings MATCHES "${EXPECTED_UNITY_FILE_CONTENT}")
set(RunCMake_TEST_FAILED "Generated unity file ${unitybuild_c} doesn't contain absolute paths")
return()
endif()