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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With