I am Charmie

メモとログ

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/".