Files
cmake/Tests/RunCMake/FASTBuild/UnitySubdirsIsolate.cmake
Andrew Maher 3f43795df9 FASTBuild: Allow files in different subdirs to be in the same unity bucket
The FASTBuild generator puts source files from different subdirectories
into different `FastbuildObjectListNode` instances. This ensures that
files with the same name will not write to the same object file. A unity
bucket can only contain files from a single `FastbuildObjectListNode`
instance, so a side effect of this logic is that unity buckets can only
contain files in the same subdirectory. This change fixes the problem by
skipping the subdirectory check logic for files with unity enabled.

Fixes: #27457
2026-02-11 14:38:22 -05:00

24 lines
937 B
CMake

# Test that isolated files from subdirectories get proper subdirectory-based object paths,
# while non-isolated files are combined in unity buckets regardless of subdirectory.
set(CMAKE_UNITY_BUILD ON)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/subdir1)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/subdir2)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp "int main() { return 0; }\n")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/subdir1/unity_file.cpp "int unity_file() { return 1; }\n")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/subdir2/isolated_file.cpp "int isolated_file() { return 2; }\n")
add_executable(main
${CMAKE_CURRENT_BINARY_DIR}/main.cpp
${CMAKE_CURRENT_BINARY_DIR}/subdir1/unity_file.cpp
${CMAKE_CURRENT_BINARY_DIR}/subdir2/isolated_file.cpp
)
set_source_files_properties(
${CMAKE_CURRENT_BINARY_DIR}/subdir2/isolated_file.cpp
TARGET_DIRECTORY main
PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON
)