<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello,</div><div><br></div><div>I'm having a hard time figuring out which solution to choose to build a library (FFmpeg) based on autotools from CMake, and I have the impression I'm going the tricky way.</div><div><br></div><div>I know how to run the FFmpeg's configure and make scripts with the right options from a bash script. I made a CMake function (based on add_custom_command()) that is able to run any bash script on both Windows and Unix OSs. Thus I could manually (from CMake) launch a FFmpeg build with the previous statements.</div><div><br></div><div>But the main disadvantage with this solution is the following one: the enabled video decoders are defined in a CMake variable (a list) that the user can define in the CMake GUI; I would like FFmpeg to be rebuilt only when this variable changes, but at the moment FFmpeg is always rebuilt.</div><div><br></div><div>FFmpeg is based on autotools (configure, make, etc). I've read a lot about add_custom_command(), add_custom_target() and ExternalProject_Add() but I still don't know what's the way to go.</div><div><br></div><div>The issues I've seen with these are:</div><div>- add_custom_command() will be always executed when I build the target that needs FFmpeg, even if FFmpeg is already built and that no setting changed</div><div>- add_custom_target() is always built too</div><div>- ExternalProject_Add() would directly execute the configure command without going through my portable bash launcher (see P.S.)</div><div><br></div><div><b>What I would like is my custom build to be dependent on some CMake variables, I don't know if it's possible.</b></div><div><br></div><div>Dependencies about some output files isn't the most important to me, because I won't be modifying the FFmpeg sources more than once every few months. And the FFmpeg sources are already in my repo so I've no need for automatic download.</div><div><br></div><div>Regards,</div><div>Lucas SOLTIC</div><div><br></div><div><br></div><div><br></div><div>P.S.: details about the portable Bash launcher for those who'd like to know:</div><div><br></div><div>The portable Bash launcher I made still requires MinGW to be installed if one wants to build from Visual Studio, but the user doesn't need to care about any command line interpreter. It's composed of 3 files: RunShellCommand.cmake, BatchBridgeToShell.bat and RunShellCommand.sh. When being run from Visual Studio, RunShellCommand() (defined in RunShellCommand.cmake) will run the bat file that will run the shell script. Otherwise RunShellCommand() will directly launch RunShellCommand.sh.</div><div><br></div><div>RunShellCommand.cmake is as follow:</div><div>function(RunShell target phase shell_command)<br><span class="Apple-tab-span" style="white-space:pre">        </span>set(cmd ${ARGV})<br><span class="Apple-tab-span" style="white-space:pre">        </span>list(REMOVE_AT cmd 0 1)<br><span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>if (MSVC)<br><span class="Apple-tab-span" style="white-space:pre">                </span>add_custom_command(TARGET ${target}<br> ${phase}<br> COMMAND BatchBridgeToShell ARGS ${MINGW_DIR} ${cmd}<br><span class="Apple-tab-span" style="white-space:pre">                                        </span> WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})<span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>else()<br><span class="Apple-tab-span" style="white-space:pre">                </span>add_custom_command(TARGET ${target}<br> ${phase}<br> COMMAND bash ARGS -c \"${cmd}\"<br><span class="Apple-tab-span" style="white-space:pre">                                        </span> WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})<span class="Apple-tab-span" style="white-space:pre">        </span><br><span class="Apple-tab-span" style="white-space:pre">        </span>endif()<br>endfunction(RunShell)<br><br></div><div><br></div><div>BatchBridgeToShell.bat is as follows:</div><div><div>PATH %1/msys/1.0/bin;%1/bin;%path%</div><div>bash -c "./RunShellCommand.sh --from-batch %*"</div></div><div><br></div><div>RunShellCommand.sh is as follows:</div><div><div>#!/bin/bash</div><div><br></div><div># Shell script to run the command given as parameter</div><div># If this script is called from a batch script, it is expected to have </div><div># two unneeded parameters</div><div><br></div><div>if [ "$1" == "--from-batch" ]</div><div> then</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>shift # drop --from-batch</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>shift # drop mingw param</div><div>fi</div><div><br></div><div># execute</div><div>$@</div></div><div><br></div><div><br></div></body></html>