[CMake] compiling implementation first in dependancies

Philippe Fremy phil at freehackers.org
Fri Jun 15 03:58:25 EDT 2007


Filip Brcic wrote:
> Дана четвртак 14 јун 2007, Philippe Fremy је написао(ла):
>> 	Hi,
>>
>> In my project, I have very often a pattern like this:
>> a.cpp:
>> #include "z.h"
>>
>> b.cpp:
>> #include "z.h"
>>
>> c.cpp:
>> #include "z.h"
>>
>>
>> z.cpp:
>> #include "z.h"
>>
>>
>> If I change z.h and z.cpp to add a new method, I usually don't get z.h
>> to work out of the box, but only realize it when compiling z.cpp .
>> What's annoying is that cmake will first compile a.cpp , b.cpp , c.cpp
>> and then only z.cpp .
>>
>> It there any way to tell CMake "compile the cpp file whose name match
>> the header file first" ?
>>
> [100%] Built target cmakeOrderTest
> 
> Well, I decided to play a bit and changed the order of files in the 
> CMakeLists.txt. The first set was {a.cpp b.cpp ... z.cpp} and after I moved 
> z.cpp to the beginning of the list, I got the following output (after 
> repeating the whole procedure again, of course):
> 
> brcha at brcha ~/tmp/cmakeOrderTest/build-disordered $ make
> Scanning dependencies of target cmakeOrderTest
> [ 20%] Building CXX object CMakeFiles/cmakeOrderTest.dir/z.o
> [ 40%] Building CXX object CMakeFiles/cmakeOrderTest.dir/a.o
> [ 60%] Building CXX object CMakeFiles/cmakeOrderTest.dir/b.o
> [ 80%] Building CXX object CMakeFiles/cmakeOrderTest.dir/c.o
> [100%] Building CXX object CMakeFiles/cmakeOrderTest.dir/main.o
> Linking CXX executable cmakeOrderTest
> [100%] Built target cmakeOrderTest
> 
> I guess that is what you wanted to achieve.

That's true, but I need a more generic solution. I have about 30 files
in my current project and depending on which one I am working on, I need
a different order. Changing the CMakelist order is not a viable long
term solution.

Choosing the target the way Alexander pointed out is the right solution.


	thanks nevertheless
	Philippe



More information about the CMake mailing list