Search code examples
cmakebuild-process

Cmake: Create directory command in suddirectory's CMakeLists.txt file


I have included a subdirectory in root's CMakeLists.txt with explicitly specifying the binary_dir as follow

add_subdirectory(subdir_with_CMakeLists.txt out_dir)

all the target are built into the out_dir as it supposed to, however MAKE_DIRECTORY command - file(MAKE_DIRECTORY some_dir) inside the included CMakeLists.txt creates the directory relative to the location of subdirectory's CMakeLists.txt, not inside the out_dir as I expected.

Now, Is there a way to create a directory relative to the binary_dir specified in add_subdirecoty command?.

Note: The included subdirectory is a portable module so directory creation command should reside in its CMakeLists.txt file, not inside the root's CMakeLists.txt


Solution

  • there's CMAKE_CURRENT_BINARY_DIR variable. You may use it in expressions in CMake commands