add_subdirectory and build directory

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

add_subdirectory and build directory

Pierre-Julien VILLOUD-3

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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Michael Wild

On 11. Sep, 2009, at 15:12, 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
>

That's NOT what add_subdirectory is made for. It is intended for  
adding a sub-directory in the source tree. So, if your directory  
structure looks like this (i.e. B is a sub-project of A)

A/CMakeLists.txt
A/B/CMakeLists.txt

things are simple:

A/CMakeLists.txt:
------>8------
# ....
add_subdirectory(B)

include_directories(B/include)

add_executable(a)
target_link_libraries(a b)
------<8------

However, if the two projects are unrelated (apart from A depending on  
B), you should use the find_package mechanism which is much more  
complex. I.e, in project B you create the files BConfig.cmake (or b-
config.cmake), BUse.cmake, BBuildSettings.cmake and  
BLibraryDepends.cmake:

B/BConfig.cmake.in:
------->8------
# Tell the user project where to find our headers and libraries
set(B_INCLUDE_DIRS "@CONFIG_HEADER_PATH@")
set(B_LIBRARY_DIRS "@CONFIG_LIBRARY_PATH@")

# Our build settings and library dependencies
set(B_BUILD_SETTINGS_FILE
   "@CONFIG_LIBRARY_PATH@/BBuildSettings.cmake"
   )
include("@CONFIG_LIBRARY_PATH@/BLibraryDepends.cmake")

# Defines
set( B_DEFINITIONS "@CONFIG_DEFINITIONS@" )

# USE file
set(B_USE_FILE "@CONFIG_USE_FILE_PATH@/BUse.cmake")
------<8------

B/BUse.cmake:
------->8------
# import B build settings
include(CMakeImportBuildSettings)
cmake_import_build_settings(${B_BUILD_SETTINGS_FILE})

# set up header search path
include_directories(${B_INCLUDE_DIRS})

# set up library search path
link_directories(${BM_LIBRARY_DIRS})

# defines
add_definitions(${B_DEFINITIONS})
------<8------

In the B/CMakeLists.txt file you do the following (just a snippet,  
showing the relevant stuff):

B/CMakeLists.txt:
------>8------
# ....

# say, you build two libraries, called b1 and b2
# with sources b1src1.c through b1src3.c and
# b2src1.c through b2src3.c, respectively.
add_library(b1 b1src1.c b1src2.c b1src3.c)
set_target_properties(b1 PROPERTIES
   PUBLIC_HEADER "b1hdr1.h;b1hdr2.h;b1hdr3.h"
   )

add_library(b2 b2src1.c b2src2.c b2src3.c)
set_target_properties(b2 PROPERTIES
   PUBLIC_HEADER "b2hdr1.h;b2hdr2.h;b2hdr3.h"
   )

# ....

# install the two libraries
install(TARGETS b1 b2
   LIBRARY DESTINATION lib COMPONENT shlibs
   RUNTIME DESTINATION bin COMPONENT shlibs
   ARCHIVE DESTINATION lib COMPONENT dev
   PUBLIC_HEADER DESTINATION include COMPONENT dev
   )

# ....

# AT THE VERY END OF THE FILE...

# Export library dependencies
#############################
export( TARGETS b1 b2
   NAMESPACE B_
   FILE ${CMAKE_BINARY_DIR}/BLibraryDepends.cmake
)

# Export the build settings
###########################
include(CMakeExportBuildSettings)
cmake_export_build_settings(${CMAKE_BINARY_DIR}/BBuildSettings.cmake)

# create BConfig.cmake for the build tree
#########################################
# SET TO THE PREPROCESSOR FLAGS REQUIRED TO USE PROJECT B
set(CONFIG_DEFINITIONS)
# SET TO WHATEVER INCLUDE PATH IS REQUIRED TO USE B'S BINARY TREE
set(CONFIG_HEADER_PATH ${CMAKE_SOURCE_DIR}/include )
# SET TO WHATEVER LIBRARY PATH IS REQUIRED TO USE B'S BINARY TREE
# (ACTUALLY, DUE TO CMAKE-MAGIC THIS CAN BE EMPTY)
set(CONFIG_LIBRARY_PATH)
set(CONFIG_USE_FILE_PATH ${CMAKE_SOURCE_DIR})
configure_file(
   ${CMAKE_SOURCE_DIR}/BConfig.cmake.in
   ${CMAKE_BINARY_DIR}/BConfig.cmake
   @ONLY
   )

# create BConfig.cmake for the install tree
###########################################
set(CONFIG_HEADER_PATH "${CMAKE_INSTALL_PREFIX}/include")
set(CONFIG_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CONFIG_USE_FILE_PATH "${CMAKE_INSTALL_PREFIX}/share/cmake/B" )
configure_file(
   ${CMAKE_SOURCE_DIR}/BConfig.cmake.in
   ${CMAKE_BINARY_DIR}/InstallFiles/BConfig.cmake
   @ONLY
   )

# install the CMake config files
################################
install( FILES
   BUse.cmake
   "${CMAKE_BINARY_DIR}/InstallFiles/BConfig.cmake"
   "${CMAKE_BINARY_DIR}/BBuildSettings.cmake"
   DESTINATION share/cmake/B
   COMPONENT dev
   )

# install the BLibraryDepends.cmake file
########################################
install( EXPORT BLibraryDepends
   DESTINATION share/cmake/B
   NAMESPACE B_
   COMPONENT dev
   )
------<8------


And then, in your A/CMakeLists.txt you do the following to use B:

A/CMakeLists.txt:
------>8------

find_package(B REQUIRED)
include(${B_USE_FILE})

add_executable(a asrc1.c asrc2.c asrc3.c)
target_link_libraries(a B_b1 B_b2)

------<8------

In order for CMake to find the BConfig.cmake, it searches some known  
system directories (refer to the documentation of find_package). If  
CMake can't find the file (which is very likely if you want to use B's  
build tree), you have to set the cache variable B_DIR to the binary  
directory of B.


I hope this explains how things work. If not, there's always the CMake  
book...

Michael
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Marcel Loose
In reply to this post by Pierre-Julien VILLOUD-3
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Bill Hoffman
In reply to this post by Michael Wild

>
> That's NOT what add_subdirectory is made for. It is intended for adding
> a sub-directory in the source tree. So, if your directory structure
> looks like this (i.e. B is a sub-project of A)
>
> A/CMakeLists.txt
> A/B/CMakeLists.txt
>
> things are simple:
>
> A/CMakeLists.txt:

Actually add_subdirectory does support the notion of out-of-source
source.   So, a source directory in does not have to be a direct
sub-directory on disk.

-Bill
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Pierre-Julien VILLOUD-3
In reply to this post by Marcel Loose
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:[hidden email]]
Envoyé : vendredi 11 septembre 2009 16:30
À : Pierre-Julien Villoud
Cc : [hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Marcel Loose
In reply to this post by Pierre-Julien VILLOUD-3
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:[hidden email]]
> Envoyé : vendredi 11 septembre 2009 16:30
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Michael Wild
In reply to this post by Bill Hoffman

On 11. Sep, 2009, at 16:45, Bill Hoffman wrote:

>
>> That's NOT what add_subdirectory is made for. It is intended for  
>> adding a sub-directory in the source tree. So, if your directory  
>> structure looks like this (i.e. B is a sub-project of A)
>> A/CMakeLists.txt
>> A/B/CMakeLists.txt
>> things are simple:
>> A/CMakeLists.txt:
>
> Actually add_subdirectory does support the notion of out-of-source  
> source.   So, a source directory in does not have to be a direct sub-
> directory on disk.
>
> -Bill
True, but then you wouldn't point it at a binary directory. AFAIK, if  
you point project A at an out-of-source source, say project B, that  
project B will be built completely within the binary tree of A.

Michael

_______________________________________________
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

PGP.sig (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

David Cole
On Sat, Sep 12, 2009 at 2:45 AM, Michael Wild <[hidden email]> wrote

True, but then you wouldn't point it at a binary directory. AFAIK, if you point project A at an out-of-source source, say project B, that project B will be built completely within the binary tree of A.


The second argument to add_subdirectory allows you to put the binary tree of "project B's build tree within project A" anywhere you want...

Of course, it should not be the same as a build tree of "standalone project B".... Because that's a different build.

Perhaps that's where the confusion is in this case?

Pierre-Julien, is that what you are expecting? When you use add_subdirectory, you should typically leave off the 2nd argument unless you just want to organize things differently than CMake does by default. But if you do use it, make sure that the directory you give it is unique across all other projects that you build. "B built within A" is different than "standalone B" -- do not try to mix and match builds with add_subdirectory -- use it as a convenient way of building a project as a component of another project...

Does that help?

Hope so,
David


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

RE : add_subdirectory and build directory

Pierre-Julien VILLOUD-3
Thank you very much fo all your answers.. It is much clearer now... I was actually trying to use add_subdirectory to manage my dependencies but it is obviously not the best way to do it.
Well the question is still here though, how can I "build B standalone" and build "B within A" as a dependency (well check if B is up to date before building A ?)

Thanks again

Pierre-Julien
________________________________________
De : [hidden email] [[hidden email]] de la part de David Cole [[hidden email]]
Date d'envoi : samedi 12 septembre 2009 12:51
À : Michael Wild
Cc : cmake; Bill Hoffman
Objet : Re: [CMake] add_subdirectory and build directory

On Sat, Sep 12, 2009 at 2:45 AM, Michael Wild <[hidden email]<mailto:[hidden email]>> wrote

True, but then you wouldn't point it at a binary directory. AFAIK, if you point project A at an out-of-source source, say project B, that project B will be built completely within the binary tree of A.


The second argument to add_subdirectory allows you to put the binary tree of "project B's build tree within project A" anywhere you want...

Of course, it should not be the same as a build tree of "standalone project B".... Because that's a different build.

Perhaps that's where the confusion is in this case?

Pierre-Julien, is that what you are expecting? When you use add_subdirectory, you should typically leave off the 2nd argument unless you just want to organize things differently than CMake does by default. But if you do use it, make sure that the directory you give it is unique across all other projects that you build. "B built within A" is different than "standalone B" -- do not try to mix and match builds with add_subdirectory -- use it as a convenient way of building a project as a component of another project...

Does that help?

Hope so,
David

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Pierre-Julien VILLOUD-3
In reply to this post by Marcel Loose
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:[hidden email]]
Envoyé : vendredi 11 septembre 2009 18:09
À : Pierre-Julien Villoud
Cc : [hidden email]
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:[hidden email]]
> Envoyé : vendredi 11 septembre 2009 16:30
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Marcel Loose
In reply to this post by Pierre-Julien VILLOUD-3
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:[hidden email]]
> Envoyé : vendredi 11 septembre 2009 18:09
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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:[hidden email]]
> > Envoyé : vendredi 11 septembre 2009 16:30
> > À : Pierre-Julien Villoud
> > Cc : [hidden email]
> > 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
>

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Pierre-Julien VILLOUD-3
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:[hidden email]]
Envoyé : mardi 15 septembre 2009 09:38
À : Pierre-Julien Villoud
Cc : [hidden email]
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:[hidden email]]
> Envoyé : vendredi 11 septembre 2009 18:09
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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:[hidden email]]
> > Envoyé : vendredi 11 septembre 2009 16:30
> > À : Pierre-Julien Villoud
> > Cc : [hidden email]
> > 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
>

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Pierre-Julien VILLOUD-3
In reply to this post by Pierre-Julien VILLOUD-3

Here is another problem I'm facing with the previous example :

 

If I do this :

In C:\Maths :

> Cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release && make => builds

> libMaths

 

And after :

In C:\HelloMath (assuming the cmake has been called before Maths build :

> make => fails with the following output :

C:\Math\CMakeFiles\Maths.dir\build.make:43: CMakeFiles/Maths.dir/depend.make: No such file or directory

C:\Math\CMakeFiles\Maths.dir\build.make:46: CMakeFiles/Maths.dir/progress.make: No such file or directory

C:\Math\CMakeFiles\Maths.dir\build.make:49: CMakeFiles/Maths.dir/flags.make: No such file or directory

mingw32-make[2]: *** No rule to make target `CMakeFiles/Maths.dir/flags.make'.  Stop.

mingw32-make[1]: *** [C:/Math/CMakeFiles/Maths.dir/all] Error 2

mingw32-make: *** [all] Error 2

 

 

in build.make, the path of depend.make progress.make and flags.make is relative. In order to make the build work, I need it to be absolute (it is absolute when building HelloMath)

 

Is there a way to make it absolute ?

 

Thanks !

 

Pierre-Julien VILLOUD

 

-----Message d'origine-----

De : [hidden email] [mailto:[hidden email]] De la part de Pierre-Julien Villoud Envoyé : mardi 15 septembre 2009 10:17 À : Marcel Loose Cc : [hidden email] Objet : Re: [CMake] add_subdirectory and build directory

 

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

 


_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Marcel Loose
In reply to this post by Pierre-Julien VILLOUD-3
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:[hidden email]]
> Envoyé : mardi 15 septembre 2009 09:38
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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:[hidden email]]
> > Envoyé : vendredi 11 septembre 2009 18:09
> > À : Pierre-Julien Villoud
> > Cc : [hidden email]
> > 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:[hidden email]]
> > > Envoyé : vendredi 11 septembre 2009 16:30
> > > À : Pierre-Julien Villoud
> > > Cc : [hidden email]
> > > 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
> >
>

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: add_subdirectory and build directory

Pierre-Julien VILLOUD-3
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:[hidden email]]
Envoyé : mardi 15 septembre 2009 13:28
À : Pierre-Julien Villoud
Cc : [hidden email]
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:[hidden email]]
> Envoyé : mardi 15 septembre 2009 09:38
> À : Pierre-Julien Villoud
> Cc : [hidden email]
> 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:[hidden email]]
> > Envoyé : vendredi 11 septembre 2009 18:09
> > À : Pierre-Julien Villoud
> > Cc : [hidden email]
> > 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:[hidden email]]
> > > Envoyé : vendredi 11 septembre 2009 16:30
> > > À : Pierre-Julien Villoud
> > > Cc : [hidden email]
> > > 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
> >
>

_______________________________________________
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