[CMake] BUILD_COMMAND having a hard time getting usable command lines

Michael Hertling mhertling at online.de
Sun Nov 27 11:30:51 EST 2011


On 11/26/2011 07:14 PM, J Decker wrote:
> Earlier I wondered if there was a way to stop recusive invocation of a
> build command in a cmake script - I found something like a solution;
> when I run the command, set an environment variable and don't run the
> command if that environment variable is set... But...
> 
> If I specify 'TARGET' in BUILD_COMMAND, then it gets extra quotes
> around it, which make it impossible to pass to execute_process.  Also
> why doesn't cmake-gui run certain commands?
> 
> ------example - probably incomplete -----------
> 
> PROJECT( whatever )
>   build_command( GENERATOR_BUILD_COMMAND CONFIGURATION
> ${CMAKE_BUILD_TYPE} PROJECT_NAME ${PROJECT_NAME} TARGET all )
>   message( "build command:${GENERATOR_BUILD_COMMAND}" )
> 
> --------- output  -------
> 
> build command:e:/tools/unix/mingw/bin/mingw32-make.exe -i "all"
> mingw32-make.exe: *** No rule to make target `"all"'.  Stop.

What happens if you omit the TARGET clause in BUILD_COMMAND()?
Target "all" should be the default when nothing is specified.

> ---end output, begin explanation--------
> 
> In order to get BUILD_COMMAND output to work at all I have to
> 
>     STRING( REPLACE "\ " ";" GENERATOR_BUILD_COMMAND
> ${GENERATOR_BUILD_COMMAND} )

AFAIK, that's exactly the job of SEPARATE_ARGUMENTS().

> which replaces the spaces in the command with semicolons, so it looks
> like seperate commands for
> 
>       EXECUTE_PROCESS(COMMAND ${GENERATOR_BUILD_COMMAND}
> WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
> 
>  and in cmake-gui the output looks something like
> 
> ---
> build command:e:/tools/unix/mingw/bin/mingw32-make.exe -i "all"
> Executing command... (output just before Execute_process)
> Configuring done
> ---
>   but the command is never actually executed?  I go out to a command
> line and type cmake . and the build goes.

I can confirm this, but if I understand correctly, you are trying
to build the project while it still undergoes its configuration, in
particular before the generation step has finished. If so, wouldn't
you expect quite strange behaviors? Could you provide a small and
self-contained example which demonstrates what you intend to do?

Regards,

Michael


More information about the CMake mailing list