[CMake] behaviour change in MakefileGenerator3

Brad King brad.king at kitware.com
Thu Jun 30 11:33:36 EDT 2005


Alexander Neundorf wrote:
> Hi, 
>  
> until recently (my last cmake was from 25th april) I used the following 
> code: 
>  
> src/firmware/app/test/CMakeLists.txt: 
>  
> ADD_CUSTOM_COMMAND(OUTPUT ecos/install/lib/target.ld 
>    COMMAND sh 
>    ARGS -c \" cd ecos\; ecosconfig tree || exit -1\; make || exit -1\; if 
> [ -e install/lib/target.ld ] \; then touch install/lib/target.ld\; fi\" 
>       DEPENDS ecos/ecos.ecc ) 
>  
> If I enter make in src/firmware/app/test/, with the new Makefile 
> generator ecos/ecos.ecc is searched relative to src/, i.e. 
> src/ecos/ecos.ecc .  With the older makefile generator it was searched 
> relative to the current directory, i.e. 
> src/firmware/app/test/ecos/ecos.ecc . 
>  
> I guess the reason are the new flat makefiles. Is this change 
> intentional ? (I can work around it by adding 
> ${CMAKE_CURRENT_SOURCE_DIR} ) 

The problem is that the current working directory of the make process is 
now different.  The new generator adds commands to set the working 
directory properly before invoking the custom command.  You can find the 
rule in TARGET.dir/target.ld.build.make where TARGET is the name of the 
target in which the custom command is used.  The cd command should be there.

I think your problem is that the new shell gets started in the wrong 
directory.  UNIX-style makes run each command (\n\t-separated) in its 
own new shell.  CMake accounts for this by adding "cd proper/dir && " 
before each line.  Somehow make is using the wrong current directory 
when it starts the "sh" command.  If you inspect the make rule you may 
be able to tell why.

-Brad


More information about the CMake mailing list