[CMake] out of source shared source

Mike Jackson imikejackson at gmail.com
Sat Jan 5 20:27:47 EST 2008


I have something similar to this where I have a library that I build  
for other projects. Sometimes it is easier just to directly include  
the source code from the library INSTEAD of building the intermediate  
library. In your situation I might be inclined to try the following:

source_tree/static_shared_source_for_projects/CMakeLists.txt might  
have something like:
GET_FILENAME_COMPONENT(static_shared_source_DIR $ 
{CMAKE_CURRENT_LIST_FILE} PATH)
then in that same file refer to the actual source code like this:
SET (static_shared_sources ${static_shared_source_DIR}/foo.cpp )

Now, in source_tree/projects/project1/CMakeLists.txt do the following:

PROJECT( Project1 )
IF (NOT DEFINED Project1_SOURCE_DIR)
     SET (Project1_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
ENDIF (NOT DEFINED Project1_SOURCE_DIR)

INCLUDE (${Project1_SOURCE_DIR}/../static_shared_source_for_projects/ 
CMakeLists.txt)

Because you used the 'INCLUDE' command everything in the source_tree/ 
static_shared_source_for_projects/CMakeLists.txt file is immediately  
processed (like a #include in a C/C++ source file) and you have  
access to all the variables that you set in the source_tree/ 
static_shared_source_for_projects/CMakeLists.txt file.

So, for instance you can create your executable in the following  
fashion:
ADD_EXECUTABLE( Project1 ${static_shared_sources} ${Project1_Sources})

Does any of this help?
-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services

On Jan 5, 2008, at 6:34 PM, Timm Reichert wrote:

> Hi,
>
> Is it possible to set an out of tree directory to include a
> CMakeLists.txt file ?
> I want to have a shared static code base for many projects like this:
>
> source_tree/
> source_tree/static_shared_source_for_projects/CMakeLists.txt
> source_tree/static_shared_source_for_projects/...
> source_tree/projects
> source_tree/projects/project1/CMakeLists.txt
> source_tree/projects/project1/...
> source_tree/projects/project2/CMakeLists.txt
> source_tree/projects/project2/...
> source_tree/projects/project3/CMakeLists.txt
> source_tree/projects/project3/...
>
> I have solved this problem earlier with qmake by including a project
> file.
> I can not find this kind of include-mechanism because if I include the
> shared source CMakeLists.txt file
> with INCLUDE(...) the cmake variable CMAKE_CURRENT_SOURCE_DIR  
> points to
> the project location.
> In qmake the macro $$PWD always points to the "current" directory.
> The ADD_SUBDIRECTORY macro seems to work only with "in tree source"
> relative to the top-level CMakeLists.txt.
> I look for a kind of "ADD_DIRECTORY"!
>
> tr
>
> Powered by Open-Xchange.com
>






More information about the CMake mailing list