Custom command/target results in MSB8065 warnings in Visual Studio 2022 & 2026

I am aware of Custom command results in MSB8065 warnings in Visual Studio 2019. That is a different issue. In that case the custom command OUTPUT is not a real file. In this case it is a real file, actually a directory. Setting the SYMBOLIC property does not help.

With the following very simple CMake project that has a single custom target to create a directory I am getting the subject warning.

cmake_minimum_required(VERSION 3.25)
include(CMakePrintHelpers)

project(TestDirCreation
    VERSION 1.0
    DESCRIPTION "Simple test of creating a directory"
)

set(BUILDTIME_RESOURCES_DIR resources)
add_custom_command(
    OUTPUT ${BUILDTIME_RESOURCES_DIR}
    COMMAND ${CMAKE_COMMAND} -E make_directory "${BUILDTIME_RESOURCES_DIR}"
    COMMENT "Make resources directory"
    VERBATIM
)
add_custom_target(
    buildtime_resources_dir
    DEPENDS ${BUILDTIME_RESOURCES_DIR}
)

When running the build with this

cmake --build build --config Release --target buildtime_resources_dir

the projects created by both the VS2022 and VS2026 generators give the warning

C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): w
arning MSB8065: Custom build for item "C:\Users\mark\Projects\khronos\github\test_create_dir\build\CMakeFiles\50efc16c9
d132abaa8a164aece7e2f3a\resources.rule" succeeded, but specified output "c:\users\mark\projects\khronos\github\test_cre
ate_dir\build\resources" has not been created. This may cause incremental build to work incorrectly. [C:\Users\mark\Pro
jects\khronos\github\test_create_dir\build\buildtime_resources_dir.vcxproj]

But the output file resources (actually a directory) is created.

There is no problem when using the Ninja generator.

This is with CMake 4.4. It was happening with earlier versions too.

Any idea what the problem is and how to fix it?

The problem is a directory is not an output, the files contained within the directory are the outputs. add_custom_command documents OUTPUT as:

This defines a command to generate specified OUTPUT file(s).

Using a directory works accidentally on some generators and doesn’t on others. It’s not within the contract of the command itself.

Thank you for the clarification.

I have two independent targets (executables) sharing a resources directory. Many of the resource files are common to both targets, many are not. I have custom targets and custom commands to install those files. I made the buildtime_resources_dir target a dependency of those because I was trying to avoid a race in creating the directory when running a parallel build.

If I remove the buildtime_resources_dir target, will the file installation targets create the directory and will they work without races in a parallel build?