[CMake] multiple cmake files in one directory

th.tom at gmx.de th.tom at gmx.de
Thu Sep 24 03:32:54 EDT 2009


> On Wednesday 23 September 2009 10:25:37 am th.tom at gmx.de wrote:
> > hm, right - this would solve my problem, but sadly writing everything in
> > one CMakeLists.txt file was not a clever idea, as the projects should be
> > build independently.
> >
> > Another solution I had (someone posted that) is creating a subdirectory
> for
> > every project and place the specific CMakeLists.txt file there. However,
> > this would change the CMAKE_SOURCE_DIR to the projects subdirectory;
> what
> > is kind of nasty.
> >
> > Any ideas to change the root back?
> 
> A subdirectory per project sounds good, but why is CMAKE_SOURCE_DIR a
> problem 
> then?  Its just a variable pointing to some directory.

Maybe I did not get the point of CMAKE_SOURCE_DIR :-/
What I do is creating a directory "packages\project1" here I place the starting CMakeLists.txt file and another subdirectory "build". 

The CMakeLists.txt consists of 

ADD_SUBDIRECTORY(../../myfirstdir)
ADD_SUBDIRECTORY(../../myseconddir)
ADD_SUBDIRECTORY(../../mythirddir)

Within the "build" directory I start "cmake ..".

What I think is happening is that the CMAKE_SOURCE_DIR is set to [whatever]\package\project1
 
This is not what I want, as the source root (where all CMakeLists.txt-files written up until now depend on) is [whatever].

So the solution would be to change _all_ ${CMAKE_SOURCE_DIR} to ${CMAKE_SOURCE_DIR}\..\.. or not to use ${CMAKE_SOURCE_DIR} and to navigate by relative paths.

Both are not very nice.

However is there another better solution for that? Or do I miss the point somewhere?

-tom



More information about the CMake mailing list