[CMake] add_subdirectory and build directory
Pierre-Julien Villoud
PVilloud at movea.com
Tue Sep 15 07:31:41 EDT 2009
Actually I'm not building in two different directories since I specified the bin dir argument in the add_subdirectory which is pointing to the same directory C:\Maths.
Best Regards
Pierre-Julien
-----Message d'origine-----
De : Marcel Loose [mailto:loose at astron.nl]
Envoyé : mardi 15 septembre 2009 13:28
À : Pierre-Julien Villoud
Cc : cmake at cmake.org
Objet : RE: [CMake] add_subdirectory and build directory
Aah, I see now what the problem really is.
You're building in two different directories. So, you will end up with
two versions of libMaths. That exactly explains the output you're
seeing.
* First, in directory Maths, you're building libMaths.
* Next, in directory HelloMath, you're building both HelloMath and
libMaths, the latter due to the link dependency. The library libmMaths
is not up-to-date as you suggest; it hasn't been built yet!
* Finally, in directory Math, you're building libMaths again, but now
it's up-to-date, so nothing needs to be done.
Best regards,
Marcel Loose.
On Tue, 2009-09-15 at 10:16 +0200, Pierre-Julien Villoud wrote:
> I found my problem
>
> Here are 2 CMakeLists.txt :
>
> ===================================
> CMakeLists.txt : libMaths :
>
> #Minimum Cmake version required
> cmake_minimum_required(VERSION 2.6)
>
> add_library(Maths
> MathFuncsLib.cpp
> )
> ===================================
>
> ===================================
> CMakeLists.txt : HelloMath :
>
> #Minimum Cmake version required
> cmake_minimum_required(VERSION 2.6)
>
> include_directories(../Math)
>
> link_directories(../Math)
>
> add_executable(HelloMath
> hellomath.cpp
> )
>
> target_link_libraries(HelloMath
> Maths
> )
>
> add_subdirectory(../Math ../Math)
> ===================================
>
> My build process is the following :
> Cmake (...) && make
>
> And it's the cmake call that causes the problem :
>
> In C:\Maths :
> > Cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release && make => builds libMaths
>
> In C:\HelloMath :
> > Cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release && make => builds HelloMath AND builds libMaths (whereas it's up to date) because of the cmake call.
>
> The following works :
> In C:\HelloMath :
> > Cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release && make => builds HelloMath AND builds libMaths because of the cmake call.
>
> In C:\Maths :
> > make => does not build libMaths since it's up to date.
>
> So I must try to remove the cmake call and it will be fine !
>
> Sorry to have bothered you...
>
> Thanks !
>
> Pierre-Julien VILLOUD
>
> -----Message d'origine-----
> De : Marcel Loose [mailto:loose at astron.nl]
> Envoyé : mardi 15 septembre 2009 09:38
> À : Pierre-Julien Villoud
> Cc : cmake at cmake.org
> Objet : RE: [CMake] add_subdirectory and build directory
>
> Hi Pierre-Julien,
>
> You are right. You don't need add_dependencies() when specifying link
> dependencies using target_link_libraries(). The latter, BTW, is of
> course the preferred way to do this.
>
> Without an example of you CMakeLists.txt files, it's very hard to tell
> what, if anything, is going wrong.
>
> Regards,
> Marcel Loose.
>
> On Mon, 2009-09-14 at 16:28 +0200, Pierre-Julien Villoud wrote:
> > Sorry I did not reply to you...
> >
> > I actually use the target_link_libraries and the add_dependencies which is useless if using the target_link_libraries (I think ?)
> >
> > So I really wonder why my objects are re-built... It's still a mystery for me !
> >
> > Thanks again
> >
> > Pierre-Julien VILLOUD
> >
> > -----Message d'origine-----
> > De : Marcel Loose [mailto:loose at astron.nl]
> > Envoyé : vendredi 11 septembre 2009 18:09
> > À : Pierre-Julien Villoud
> > Cc : cmake at cmake.org
> > Objet : Re: [CMake] add_subdirectory and build directory
> >
> > Hi Pierre-Julien,
> >
> > I think I see what the problem is. You didn't specify any dependencies.
> > You mention that project A depends on B. But don't you actually mean
> > that libA depends on libB? If that's the case you should add a
> > target_link_libraries(libA libB) to the CMakeLists.txt file of project
> > A.
> >
> > Anyway, you may want to post your CMakeLists.txt files, so that people
> > can spot what you might be doing wrong. At the moment, I can only make
> > some wild guesses.
> >
> > Best regards,
> > Marcel Loose.
> >
> > On Fri, 2009-09-11 at 17:34 +0200, Pierre-Julien Villoud wrote:
> > > Hi and thanks for your answer...
> > >
> > > Here is the ouput :
> > >
> > > I'm building A : My CMakelists.txt is in C:/A
> > >
> > > -- Configuring done
> > > -- Generating done
> > > -- Build files have been written to: C:/A/Debug
> > > ==============Building A==============
> > > [ 0%] Built target CMake
> > > Scanning dependencies of target B
> > > [ 4%] Building CXX object C:/B/CMakeFiles/B.dir/B.cpp.obj
> > > Linking CXX static library C:\lib\libB.a
> > > [ 4%] Built target B
> > > Linking CXX shared module C:\bin\A.dll
> > > [100%] Built target A
> > >
> > > Then I'm building B : My CMakeLists.txt is in C:/B
> > >
> > > -- Configuring done
> > > -- Generating done
> > > -- Build files have been written to: C:/B/Debug
> > > ==============Building B==============
> > > [ 0%] Built target CMake
> > > Scanning dependencies of target B
> > > [100%] Building CXX object CMakeFiles/B.dir/B.cpp.obj
> > > Linking CXX static library C:\lib\libB.a
> > > [100%] Built target B
> > >
> > >
> > > Any clues ?
> > >
> > > @Michael : I did not look at your long and precise answer (thank you very much for it BTW) but it seems quite complicated !! How are you managing your dependencies ?
> > >
> > > Thank you for your help !
> > >
> > >
> > >
> > > -----Message d'origine-----
> > > De : Marcel Loose [mailto:loose at astron.nl]
> > > Envoyé : vendredi 11 septembre 2009 16:30
> > > À : Pierre-Julien Villoud
> > > Cc : cmake at cmake.org
> > > Objet : Re: [CMake] add_subdirectory and build directory
> > >
> > > Hi Pierre-Julien,
> > >
> > > Are you sure it's rebuilding? CMake (or 'make' actually), prints a lot
> > > of messages "Built target ..." even if no compilation was needed.
> > > However, if you also see messages like "Building ..." then it is
> > > actually rebuilding.
> > >
> > > Without an example of the output of your build, it is hard to judge
> > > what, if anything, is going wrong.
> > >
> > > Best regards,
> > > Marcel Loose.
> > >
> > > On Fri, 2009-09-11 at 15:12 +0200, Pierre-Julien Villoud wrote:
> > > > Hi everyone,
> > > >
> > > >
> > > >
> > > > After unsuccessfully looking for an answer on Google, I contact you.
> > > >
> > > > I have a question regarding the use of add_subdirectory. When a
> > > > project A is depending on a project B, I add the following in A's
> > > > CMakeLists.txt :
> > > >
> > > >
> > > >
> > > > Add_subdirectory(B Path/To/B/Build/Directory)
> > > >
> > > >
> > > >
> > > > It does build B before A. But when I build B in its build directory
> > > > and I build A after, it builds B again whereas it should not since B
> > > > is up to date.
> > > >
> > > >
> > > >
> > > > Anyone sees what's wrong ?
> > > >
> > > >
> > > >
> > > > Thanks in advance
> > > >
> > > >
> > > >
> > > > Pierre-Julien VILLOUD
> > > >
> > > >
> > > > _______________________________________________
> > > > Powered by www.kitware.com
> > > >
> > > > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> > > >
> > > > Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> > > >
> > > > Follow this link to subscribe/unsubscribe:
> > > > http://www.cmake.org/mailman/listinfo/cmake
> > >
> > > _______________________________________________
> > > Powered by www.kitware.com
> > >
> > > Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> > >
> > > Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> > >
> > > Follow this link to subscribe/unsubscribe:
> > > http://www.cmake.org/mailman/listinfo/cmake
> >
>
More information about the CMake
mailing list