We have a custom MSVC toolchain. However, we were getting an issue related to RC files. That only manifested on Ninja dirty builds.
# Here is the bug will manifest itself:
# "ninja: error: FindFirstFileExA(note: including file: d:/foobar/ms_sdk/n20246/10/include/10.0.20246.0/shared): The filename, directory name, or volume label syntax is incorrect."
An engineer at our company was able to workaround this bug by putting the following code in our custom toolchain:
# This is neccessary to ensure RC files compile with our custom toolchain
# Otherwise dirty builds will break. This code basically patches a cmake bug.
if (CMAKE_GENERATOR MATCHES "Ninja")
# Compiling RC files needs to set this. The Ninja generator calls cmcldeps.exe to extract dependencies for RC
# files. But it configurates DepType to "gcc" so cmake cannot filter show includes prefix and the dependencies
# are stored in .ninja_deps with the prefix and cause next run of ninja to fail. The DepType cannot be forced
# to "msvc" otherwise the dependency changes won't trigger recompilation of RC files.
# The workaround is to set CMAKE_CL_SHOWINCLUDES_PREFIX to the exact English string "Note: including file: ".
# function CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX may be used if any locale issue occurs.
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: " CACHE INTERNAL "AMD WORKAROUND")
# The Ninja generator relies on the following variables to determine MSVC style PDB names. But these variables
# stored in cmake are only initialized to "" when it is first time run on a project before CMake${lang}Compiler
# .cmake are generated. The next run doesn't initilazed them because CMake${lang}Compiler.cmake are there. So
# they are null and SetMsvcTargetPdbVariable() returns false so ".dbg" suffix is used for PDBs.
# The workaround is to set them to either x64 or x86 (actually "" is enough).
#
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID.html?highlight=architecture_id
set(CMAKE_CXX_ARCHITECTURE_ID "x64" CACHE INTERNAL "AMD WORKAROUND")
set(CMAKE_C_ARCHITECTURE_ID "x64" CACHE INTERNAL "AMD WORKAROUND")
endif()