[CMake] Building an external library based on autotools

Lucas Soltic lucas.soltic at orange.fr
Thu Mar 21 15:43:31 EDT 2013


Hello,

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.

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.

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.

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.

The issues I've seen with these are:
- 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
- add_custom_target() is always built too
- ExternalProject_Add() would directly execute the configure command without going through my portable bash launcher (see P.S.)

What I would like is my custom build to be dependent on some CMake variables, I don't know if it's possible.

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.

Regards,
Lucas SOLTIC



P.S.: details about the portable Bash launcher for those who'd like to know:

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.

RunShellCommand.cmake is as follow:
function(RunShell target phase shell_command)
	set(cmd ${ARGV})
	list(REMOVE_AT cmd 0 1)
	
	if (MSVC)
		add_custom_command(TARGET ${target}
                     ${phase}
                     COMMAND BatchBridgeToShell ARGS ${MINGW_DIR} ${cmd}
					 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})	
	else()
		add_custom_command(TARGET ${target}
                     ${phase}
                     COMMAND bash ARGS -c \"${cmd}\"
					 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})	
	endif()
endfunction(RunShell)


BatchBridgeToShell.bat is as follows:
PATH %1/msys/1.0/bin;%1/bin;%path%
bash -c "./RunShellCommand.sh --from-batch %*"

RunShellCommand.sh is as follows:
#!/bin/bash

# Shell script to run the command given as parameter
# If this script is called from a batch script, it is expected to have 
# two unneeded parameters

if [ "$1" == "--from-batch" ]
  then
	shift # drop --from-batch
	shift # drop mingw param
fi

# execute
$@


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130321/100edfad/attachment.htm>


More information about the CMake mailing list