Creating a directory in CMake

Viewed 117081

In CMake, I want to create a directory if it doesn't already exist. How can I do this?

3 Answers

In addition to Chin Huang's reply, you can also do this at build time with add_custom_command:

add_custom_command(TARGET ${target_name} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E make_directory ${directory})

You can also change the moment, when your directory is created with PRE_BUILD | PRE_LINK | POST_BUILD parameters.

Related