[CMake] multiple cmake files in one directory

th.tom at gmx.de th.tom at gmx.de
Thu Sep 24 16:12:02 EDT 2009


> > 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.
> 
> Maybe you explained it upthread but why not put your top-level
> CMakeLists.txt in [whatever]?

Because I have two (more or less) independent projects, that joins the same root! And I want to have two build process and packages created by cpack in the end.

> You could also set a myProjectRoot and point it to
> "${CMAKE_SOURCE_DIR}/../..". If you don't like the .. in your path, use
> get_filename_component to normalize that path.

That's an option, that hurts less. My intention is to make the build process as logical and convenient as possible to convince people to switch to cmake. So reading ${MY_PROJECT_ROOT} is ok, but having ${CMAKE_SOURCE_DIR} would be better at least, because it is documented. I am afraid that people write their first CMakeLists.txt from a tutorial, add it with ADD_SUBDIRECORY() to the projects CMakeLists.txt and nothing works as expected, as their CMAKE_SOURCE_DIR is placed somewhere, but not at the root they expected.

-tom


More information about the CMake mailing list