A CMAKE file is a CMake language source file used by CMake, a collection of tools designed to build, test, and package software. The file may contain a script or module written in the CMake language. CMake Language source files are organized into "Directories" (CMakeLists. txt), "Scripts" (script.
Building with Qt Creator In Qt Creator, go to File → Open File or Project… and choose CMakeLists. txt from the source folder you want to build. Qt Creator will prompt you for the location of the binary folder, calling it the “build directory”. By default, it suggests a path adjacent to the source folder.
When do you want to create the directory?
To create a directory when CMake generates the build system,
file(MAKE_DIRECTORY ${directory})
In the add_custom_command()
command (which adds a custom build rule to the generated build system), and the add_custom_target()
command (which adds a target with no output so it will always be built), you specify the commands to execute at build time. Create a directory by executing the command ${CMAKE_COMMAND} -E make_directory
. For example:
add_custom_target(build-time-make-directory ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${directory})
To create a directory at install time,
install(DIRECTORY DESTINATION ${directory})
To create a directory at install time,
install(DIRECTORY DESTINATION ${directory})
These will both run at configure time:
file(MAKE_DIRECTORY ${directory})
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${directory})
To create during the build, use a custom target:
add_custom_target(mytargetname ALL COMMAND ${CMAKE_COMMAND} -E make_directory ${directory})
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.
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