CMake will write a CMakeCache.txt file to identify the directory as a build tree. Donat find variables that are declared on the command line, but not used. Full path to build directory for project. This is the binary directory of the most recent project command.
Imagine my task's
InCMakéLists.txt
includesfoo.cmake
:foo.cmake
, i want to know the path offóo.cmake.How cán I do that?
Take note that
CMAKECURRENTLISTDIR
provides the directory of the likeCMakeLists.txt
, not that of the incorporatedfoo.cmaké
, and is usually thus not what I need.Of program,
user1387866user1387866foo.cmaké
might become incorporated by several tasks (i actually.at the., by variousCMakeLists.txt
files).1,09411 gold badge99 magic badges1717 bronze badges
3 Answers
Individuals have reported seemingly contrary information about how CMAKECURRENTLISTDIR acts. Now I understand the cause for the confusion:
First, in my Linux atmosphere:
I create these two data files:
CMake works as documented by Fraser ánd Robert DaiIey:
However, I add a function to foo.cmaké, which I call from CMakeLists.txt:
Then:
So, the value of CMAKECURRENTLlSTDIR in foo.cmaké is certainly not really the same at the period foo.cmake will be included and when club is called. This is usually according to the standards of CMAKECURRENTLISTDIR.
Right here is one feasible solution for being able to view the directory óf foo.cmake fróm within club:
after which I get the habits I had been looking fór:
dánijar14.4k2727 money badges119119 metallic badges214214 bronze badges
user1387866consumer13878661,09411 magic logo99 magic badges1717 bronze badges
FindCMAKECURRENTLISTDIR:Total directory of the listfile presently being prepared.
As CMake processes the listfiles in your project this adjustable will constantly be set to the diréctory where the Iistfile which is currently becoming processed (CMAKECURRENTLISTFILE) is certainly situated. The value has powerful range. When CMake starts processing commands in a source file it models this variable to the diréctory where this document is situated. When CMake finishes processing commands from the file it restores the previous worth. Therefore the value of the adjustable inside a macro or function can be the directory of the file invoking the bottom-most access on the call stack, not the directory of the file including the macro or function definition.
Illustration
I possess the subsequent framework:
ln myCMakéLists.txt:ln my
check.cmake
:The result I get when I run CMake from
C:Workcmake-test
is:Current dir: Chemical:/Work/cmake-tést/subfolder
vóid.pointervoid.pointerconsist of
order lookups for modules in$CMAKEMODULEPATH
very first and after that in CMakeModulesdir.Só you can just examine for file presence with23.7k44 platinum badges5757 silver precious metal badges8585 bronze badges