You are not logged in.

#1 2011-01-14 15:03:03

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

[SOLVED] CMake: how to retrieve the current directory?

Hi, I'm facing a little puzzle with CMake and I need some help. I have two projects:

Project1
    CMakeLists.txt
    file1.cmake
    file2.cmake

Project2
    CMakeLists.txt

Project1 contains two files with some pieces of CMake configurations. CMakeLists.txt includes file1.cmake:

include(file1.cmake)

Similarly, file1.cmake includes file2.cmake. Everything works fine.
Now, also Project2 have to be configured using file1.cmake and file2.cmake. Its CMakeLists.txt looks like:

include(../Project1/file1.cmake)

This is ok, but when file1.cmake tries to include file2.cmake I get the following error:

CMake Error at ../Project1/file1.cmake:57 (include):
  include could not find load file:

    file2.cmake
Call Stack (most recent call first):
  CMakeLists.txt:11 (include)

I think the error is due to the fact that CMake current directory is Project2 so I tried to modify file1.cmake in this way:

include(${CMAKE_CURRENT_SOURCE_DIR}/file1.cmake)

but it gives the same error:

CMake Error at ../Project1/file1.cmake:57 (include):
  include could not find load file:

    Project2/file2.cmake
Call Stack (most recent call first):
  CMakeLists.txt:11 (include)

Indeed, CMAKE_CURRENT_SOURCE_DIR points to Project2, not to Project1 where file1,cmake is. Is there a CMake variable which actually tells the path of the currently processed file?
Thanks.

Last edited by snack (2011-01-14 15:09:11)

Offline

#2 2011-01-14 15:08:23

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] CMake: how to retrieve the current directory?

Nevermind, I found the solution just after opening  this thread (which in turn has been opened after a couple of hours of searching the web with no results...). The variable I was looking for is CMAKE_CURRENT_LIST_DIR. Hope someone else could benefit from this smile

Last edited by snack (2011-01-14 15:08:59)

Offline

Board footer

Powered by FluxBB