CMake: how to get the name of parent directory

I have been looking for how to get the name of parent directory of CMAKE_SOURCE_DIR and could find the answer today. The solution is to use get_filename_component() function with “PATH” argument.

Let’s say CMAKE_SOURCE_DIR is “/code/testCmake/“. I wanna access “/code/data/” directory using CMake. The solution is
get_filename_component(DATA_DIR ${CMAKE_SOURCE_DIR} PATH)
set(DATA_DIR ${DATA_DIR}/data/)
Then, DATA_DIR stores “/code/data/“.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s