[Cmake] Finding current directory

Zachary Pincus zpincus at stanford.edu
Mon, 12 Apr 2004 18:25:22 -0700


Hello,

Is there any way to get the "current working directory" in a CMake 
variable?

Here's why I think that this would be useful:
I've got a cmake project with several sub directories that I build via  
a SUBDIRS command, for example:
Root
	Dir1
		Headers
			nnn.h
			...
		Sources
			nnn.cpp
			...
	Dir2
	...

Thus, the CMakeLists.txt file in Dir1 needs to set INCLUDE_DIRECTORIES 
to include Root/Dir1/Headers. Is there any simple way to get the 
"current working directory" in a cmake variable, so I can use a 
construct like this:
INCLUDE_DIRECTORIES("${CURRENT_DIR}/Headers")
instead of
INCLUDE_DIRECTORIES("${ROOT_SOURCE_DIR}/Dir1/Headers") ?
(where ROOT_SOURCE_DIR is set by the PROJECT(ROOT) command in the top 
level CMakeLists file.)

Admittedly, this example is trivial, but for a more nested structure 
(like I have), the latter approach gets very unwieldy, and the former 
would seem a lot better.

Any thoughts?

Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine