How to specify relative paths in CMAKE?

I want to specify a path related to the current directory in CMake, and could not find a solution.

My project is on the way with something like:

C:/Projects/ProjectA/CMakeLists.txt 

and I want to specify the name of the relative path in the following directory using the set () command

 C:/External/Library 

In other words, what is CMake broadcast

 ../../External/Library? 

Thanks,

+6
source share
1 answer

This is pretty much the same, except that you allow CMake to run elsewhere for out-of-assembly assembly. You do this by specifying a path relative to ${CMAKE_CURRENT_SOURCE_DIR} , which is the directory containing the current CMakeLists.txt file.

 ${CMAKE_CURRENT_SOURCE_DIR}/../../External/Library 

But you might want to review and use the FIND_LIBRARY and FIND_FILE commands instead to search for a set of predefined locations so that your library users don’t have to keep the same relative structure.

+10
source

Source: https://habr.com/ru/post/977849/


All Articles