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

Michael Hertling mhertling at online.de
Tue Jan 4 02:00:45 EST 2011


On 01/04/2011 07:41 AM, Michael Hertling wrote:
> On 01/04/2011 05:47 AM, John McGehee wrote:
>> 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.
> 
> Use CMAKE_CURRENT_LIST_FILE in conjunction with GET_FILENAME_COMPONENT():

Oops...or just CMAKE_CURRENT_LIST_DIR. ;|

Regards,

Michael


More information about the CMake mailing list