[CMake] How to find the path to the currently include() or find_package file()

John McGehee cmake at voom.net
Mon Jan 3 23:47:24 EST 2011


I am using CMake 2.8 on Linux and Windows.

When I include() or find_package() a .cmake file, is there a variable that I can use within the included .cmake file that will tell me its path?

For example,

  # In CMakeLists.txt
  include(somePath/foo.cmake)

Within somePath/foo.cmake, I want to include bar.cmake which is in the same directory as foo.cmake,

  # In somePath/foo.cmake
  include(${CMAKE_VARIABLE_THAT_IS_THE_ANSWER_TO_THIS_QUESTION}/bar.cmake)

where ${CMAKE_VARIABLE_THAT_IS_THE_ANSWER_TO_THIS_QUESTION} = "somePath", the path to foo.cmake, which is currently being evaluated.


More information about the CMake mailing list