You are not logged in.
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
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
Last edited by snack (2011-01-14 15:08:59)
Offline