<div dir="ltr">I&#39;m having a problem with something pretty basic, so I&#39;m wondering what I&#39;m doing wrong.<div><br></div><div style>In my build process, I want to use PyInstaller to generate an EXE. Due to the way the source code is laid out, the scripts for this PyInstaller setup are split among several directories. In addition, I need some special binary files to be packaged as well (some of which are generated as other targets). So, my solution was to copy all the scripts from the source directories and all of the built binary files into ${CMAKE_CURRENT_BINARY_DIR}. I would then run PyInstaller from that directory, and then I wouldn&#39;t have to worry about PYTHON_PATH issues or trying to find binaries.</div>
<div style><br></div><div style>This works the first time you try to build the PyInstaller output. If a source Python script changes and I rebuild ALL, then the only task that occurs is that source script it copied to the ${CMAKE_CURRENT_BINARY_DIR}. The PyInstaller package is not rebuilt. If I build ALL again immediately afterwards (without changing any files), then the PyInstaller package is rebuilt (no files are copied).</div>
<div style><br></div><div style>I&#39;ve reduced this down to a sample script:</div><div style><br></div><div style><div>cmake_minimum_required (VERSION 2.8.10)</div><div> </div><div>project (MyProj)</div><div> </div><div>
add_custom_command(</div><div>    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource.txt</div><div>    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/source.txt ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource.txt</div>
<div>    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source.txt)</div><div>list(APPEND _MY_DEPS ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource.txt)</div><div>   </div><div>add_custom_command(</div><div>    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource2.txt</div>
<div>    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/source2.txt ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource2.txt</div><div>    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source2.txt)</div><div>list(APPEND _MY_DEPS ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource2.txt)</div>
<div>   </div><div>add_custom_command(</div><div>    OUTPUT built.txt</div><div>    COMMAND ${CMAKE_COMMAND} -E touch built.txt</div><div>    DEPENDS ${_MY_DEPS})</div><div>   </div><div>add_custom_target(SomeTarget ALL DEPENDS built.txt)</div>
<div><br></div><div style>In this example, &quot;source.txt&quot; and &quot;source2.txt&quot; in the source directory represent two Python scripts that PyInstaller needs. Those are copied to ${CMAKE_CURRENT_BINARY_DIR}/somedir/dsource.txt and dsource2.txt. Once those two files are copied, the PyInstaller proces can run (represented here by touching &quot;built.txt&quot;).</div>
<div style><br></div><div style>The first time i build ALL on this project, then the two files are copied and built.txt is touched. If I change source.txt and build ALL, then only &quot;somedir/dsource.txt&quot; is recopied (built.txt is not touched). If I immediately build again without changing a file,t then &quot;built.txt&quot; is touched.</div>
<div style><br></div><div style>I understand what&#39;s going on. &quot;built.txt&quot; depends on &quot;somedir/dsource.txt&quot; and &quot;somedir/dsource2.txt&quot;. When i change &quot;source.txt&quot; all the dependencies are scanned. &quot;built.txt&quot; notices that &quot;somedir/dsource.txt&quot; hasn&#39;t changed, so it doesnt rebuild. Simultaneously, &quot;somedir/dsource.txt&quot; notices that &quot;source.txt&quot; has changed so it builds (copies). Then if i tell it to build again, now &quot;built.txt&quot; notices that &quot;somedir/dsource.txt&quot; has changed and it builds (touches).<br>
</div><div style><br></div><div style>Clearly this is not what I want. What am I doing wrong, or how can I fix up this script to achieve the results I&#39;m looking for?</div><div style><br></div><div style>Thanks!</div></div>
</div>