[CMake] Problem with design and ADD_SUBDIRECTORY

Michael Jackson mike.jackson at bluequartz.net
Tue Jul 14 11:21:41 EDT 2009


In the top level CMakeLists.txt you should be able to do something like:

add_executable(Foo .. )
target_link_libraries(Foo package1 package2)

and it should just work. CMake will figure out the dependencies.

Also in package2/CMakeLists.txt

  target_link_libraries(package2 package1)
will work the same way.

As far as the include directories goes there are different ways to  
solve that issue. One way would be to define some variables in the  
root level CMakeLists.txt file such as:
  set(PACKAGE1_SRC_DIR  ${ROOT_SRC_DIR}/package1)
  set(PACKAGE2_SRC_DIR  ${ROOT_SRC_DIR}/package2)

Each of those variables will be available in all the other sub- 
directories as cmake variables can be passed down the chain.

  You could also define the variables in each sub-directory and use  
the "PARENT_SCOPE" argument to the "SET()" command although I am not  
sure if that would work or not.

HTH
_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio



On Jul 14, 2009, at 11:08 AM, Martin Santa María wrote:

> Hello everyone,
>
> I have a design problem. I have a new project consisting on  
> different packages. Each package should be built as a library but it  
> could depend on libraries generated by other packages. Also there is  
> an executable built from some of these libraries:
>
> root/
>   CMakeLists.txt   -> generates executable with some package libraries
>   package1/
>     CMakeLists.txt -> generates package1.lib
>   package2/
>     CMakeLists.txt -> generates package2.lib that depends on  
> package1 library and its header files. so it must include root/ 
> package1/
>
>
> My problem begins with INCLUDE_DIRECTORIES and LINK_DIRECTORIES. I  
> would like that packages include those directories that are really  
> needed to search for headers and libraries, in the previous example  
> package2 should includes directory package 1 so it could find  
> package1's headers, but package1 shouldn't know about package2. To  
> archive this, I think I need to use ADD_SUBDIRECTORY so each sub  
> directory has its own includes and libraries directories. The  
> problem is that the root CMakeLists.txt should known the list of  
> generated libraries and source files so it could make the global  
> executable.
> I don't find the way to pass this information from package's  
> CMakeLists.txt to the root CMakeLists.txt.
>
> Do you have some idea?
> Regards,
>
> Martin
>
> ¡Es hora que descubras quién sos! Alguien puede conocerte mejor que  
> vos mismo._______________________________________________
> 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