[CMake] multiple cmake files in one directory

Clinton Stimpson clinton at elemtech.com
Thu Sep 24 10:45:27 EDT 2009


On 09/24/2009 01:32 AM, th.tom at gmx.de wrote:
>    
>> 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?
>
>    

Have you considered using other variables?
http://www.vtk.org/Wiki/CMake_Useful_Variables
Maybe you want to use CMAKE_CURRENT_SOURCE_DIR instead.

Clint



More information about the CMake mailing list