[CMake] compiling implementation first in dependancies

Filip Brcic brcha at users.sourceforge.net
Thu Jun 14 06:16:24 EDT 2007


Дана четвртак 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" ?
>
> I tried to specify direct targets, like:
> make CMakeFiles/...more stuff.../z.obj
>
> but it was not successful either.
>
> It there any way to get the behavior I want ?
>
> 	cheers,
>
> 	Philippe
>

I have just created a dummy set of {a,b,c,z}.cpp files and one z.h that was 
included in all of them (& main.cpp with main()). After building for the 
first time, I added another method to the dummy class in z.h and defined it 
in z.cpp. The output of the second build is here:

brcha at brcha ~/tmp/cmakeOrderTest/build-ordered $ make
Scanning dependencies of target cmakeOrderTest
[ 20%] Building CXX object CMakeFiles/cmakeOrderTest.dir/a.o
[ 40%] Building CXX object CMakeFiles/cmakeOrderTest.dir/b.o
[ 60%] Building CXX object CMakeFiles/cmakeOrderTest.dir/c.o
[ 80%] Building CXX object CMakeFiles/cmakeOrderTest.dir/main.o
[100%] Building CXX object CMakeFiles/cmakeOrderTest.dir/z.o
Linking CXX executable cmakeOrderTest
[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.

So, just move z.cpp to the top of your source list and it will be built first 
(if needed).

Best regards

Filip

PS: I have attached a 750 bytes archive with the "sources" I used for this 
test.

-- 
Filip Brcic <brcha at users.sourceforge.net>
WWWeb: http://purl.org/NET/brcha/home/
Jabber: brcha at kdetalk.net
Jabber: brcha at elitesecurity.org
Jabber: fbrcic at gmail.com
ICQ# 40994923
Yahoo! brcha
MSN: brcha at users.sourceforge.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmakeOrderedTest.tar.bz2
Type: application/x-tbz
Size: 750 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070614/4386e37a/cmakeOrderedTest.tar-0001.bin


More information about the CMake mailing list