Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake : parent directory?

Tags:

cmake

How to find the parent directory in CMake ?

Assume that ${MYPROJECT_DIR}=/dir1/dir2/dir3/myproject/ and I want ${PARENT_DIR}=/dir1/dir2/dir3/.

How to do that ? SET(PARENT_DIR ${MYPROJECT_DIR}/../) doesn't seem to be the right syntax.

like image 608
Vincent Avatar asked Aug 12 '11 04:08

Vincent


1 Answers

As of CMake 2.8.12, the recommended way is to use the get_filename_component command with the DIRECTORY option:

get_filename_component(PARENT_DIR ${MYPROJECT_DIR} DIRECTORY) 

For older versions of CMake, use the PATH option:

set (MYPROJECT_DIR /dir1/dir2/dir3/myproject/) get_filename_component(PARENT_DIR ${MYPROJECT_DIR} PATH) 
like image 165
sakra Avatar answered Sep 29 '22 19:09

sakra