<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 28, 2019 at 1:31 PM melak47 <<a href="mailto:melak47@posteo.net">melak47@posteo.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I'm using add_custom_command with the Ninja generator on Windows to<br>
invoke mc.exe on an .mc file,<br>
to generate an .rc file, to create a resource DLL.<br>
The full example is here:<br>
<a href="https://gist.github.com/melak47/f7d83046c6d57b338d633468d078f5b1" rel="noreferrer" target="_blank">https://gist.github.com/melak47/f7d83046c6d57b338d633468d078f5b1</a><br>
<br>
The problem is, changing the .mc file and rebuilding only causes mc.exe<br>
to rerun,<br>
anything depending on the generated .rc file is not rebuilt.<br>
I think this happens because cmake generates some order-only<br>
dependencies for the generated files.<br>
<br>
Some of the relevant build statements that are generated:<br>
<br>
<br>
#<br>
=============================================================================<br>
# Object build statements for MODULE_LIBRARY target example<br>
<br>
<br>
#############################################<br>
# Order-only phony target for example<br>
<br>
build cmake_object_order_depends_target_example: phony || example.hpp<br>
example.rc example_MSG00001.bin<br>
<br>
build CMakeFiles\example.dir\example.rc.res: RC_COMPILER__example<br>
D$:\repro\build\example.rc || cmake_object_order_depends_target_example<br>
DEFINES = -Dexample_EXPORTS<br>
DEP_FILE = CMakeFiles\example.dir\example.rc.res.d<br>
FLAGS = -DWIN32 -D_DEBUG<br>
OBJECT_DIR = CMakeFiles\example.dir<br>
OBJECT_FILE_DIR = CMakeFiles\example.dir<br>
TARGET_COMPILE_PDB = CMakeFiles\example.dir\<br>
TARGET_PDB = example.pdb<br>
<br>
<br>
#<br>
=============================================================================<br>
# Link build statements for MODULE_LIBRARY target example<br>
<br>
<br>
#############################################<br>
# Link the shared module example.dll<br>
<br>
build example.dll: CXX_MODULE_LIBRARY_LINKER__example<br>
CMakeFiles\example.dir\example.rc.res<br>
LANGUAGE_COMPILE_FLAGS = /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od<br>
/RTC1 -MDd<br>
LINK_FLAGS = /machine:x64 /debug /INCREMENTAL /noentry<br>
LINK_LIBRARIES = kernel32.lib user32.lib gdi32.lib winspool.lib<br>
shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib<br>
OBJECT_DIR = CMakeFiles\example.dir<br>
POST_BUILD = cd .<br>
PRE_LINK = cd .<br>
TARGET_COMPILE_PDB = CMakeFiles\example.dir\<br>
TARGET_FILE = example.dll<br>
TARGET_IMPLIB = example.lib<br>
TARGET_PDB = example.pdb<br>
<br>
<br>
#############################################<br>
# Custom command for example.rc<br>
<br>
build example.rc example.hpp example_MSG00001.bin: CUSTOM_COMMAND<br>
..\<a href="http://example.mc" rel="noreferrer" target="_blank">example.mc</a><br>
COMMAND = cmd.exe /C "cd /D D:\repro\build && "C:\Program Files<br>
(x86)\Windows Kits\10\bin\10.0.18362.0\x64\mc.exe" -b -e hpp -h<br>
D:/repro/build -r D:/repro/build D:/repro/<a href="http://example.mc" rel="noreferrer" target="_blank">example.mc</a>"<br>
DESC = Generating example.rc, example.hpp, example_MSG00001.bin<br>
restat = 1<br>
<br>
<br>
#############################################<br>
# Assume dependencies for generated source file.<br>
<br>
build D$:\repro\build\example.rc: CUSTOM_COMMAND ||<br>
cmake_object_order_depends_target_example<br>
COMMAND = cmd.exe /c<br>
restat = 1<br>
<br>
<br>
As you can see, CMakeFiles\example.dir\example.rc.res depends on<br>
D$:\repro\build\example.rc,<br>
which depends on the actual example.rc through<br>
cmake_object_order_depends_target_example as<br>
an **order-only** dependency.<br>
If I read the ninja manual correctly, this means changes to example.rc<br>
will by design not cause depndees to be rebuilt.<br>
<br>
If instead of an empty CUSTOM_COMMAND, cmake emitted a phony like:<br>
<br>
build D$:\repro\build\example.rc: phony example.rc<br>
<br>
example.rc.res and example.dll would be properly rebuilt.<br>
(Also, a phony does not appear in the build log, unlike the empty<br>
CUSTOM_COMMAND which just shows up as 'cmd /c')<br>
<br>
Is this a bug, or is there some intent behind emitting a CUSTOM_COMMAND<br>
here?<br></blockquote></div><div><br></div><div><br></div><div>This seems like a bug to me, please add it to gitlab as a new issue here:<div><br></div><div><a href="https://gitlab.kitware.com/cmake/cmake/issues">https://gitlab.kitware.com/cmake/cmake/issues</a><br></div><div><br></div><div>Please ensure you also record what version of CMake you are using. If you can test with some different CMake versions to confirm whether it is a long-standing issue or a regression in a more recent version, that would also be very helpful. I believe there have been a few changes relating to RC handling in the last few releases, so can't rule out a regression.</div><div><br></div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>Get the hand-book for every CMake user: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div><div>Consulting services (CMake, C++, build/release processes): <a href="https://crascit.com/services" target="_blank">https://crascit.com/services</a></div></div></div></div></div></div></div></div></div></div></div></div></div>