I'm building project with CMake. While configuration and building I'm in directory project/build . How can I change the directory in CMake and execute a bash script from another directory.
execute_process( COMMAND cd ../ ) - doesn't work. When I execute this CMake doesn't change its directory and I'm again in project/build.
CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache. So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src> .
You can edit CMakeLists. txt files right in the Editor. Make sure to reload the project after editing. Automatic reload feature is disabled by default, you can turn it on by selecting the Automatically reload CMake project on editing checkbox in Settings / Preferences | Build, Execution, Deployment | CMake.
CMakeLists. txt is placed at the root of the source tree of any application, library it will work for. If there are multiple modules, and each module can be compiled and built separately, CMakeLists. txt can be inserted into the sub folder.
The WORKING_DIRECTORY
directive of the execute_process
command lets you directly specify the directory the script is to be run from.
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/script.sh args
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
With ${CMAKE_SOURCE_DIR}
you get the source path. Executing a binary from the source directory would be
execute_process(${CMAKE_SOURCE_DIR}/bin/myscript.sh)
If you need to handle files from the build directory you have to add them like
execute_process(${CMAKE_SOURCE_DIR}/bin/myscript.sh ${CMAKE_CURRENT_BINARY_DIR}/input.txt)
Overall the variables CMAKE_SOURCE_DIR
, CMAKE_CURRENT_SOURCE_DIR
, CMAKE_BINARY_DIR
, and CMAKE_CURRENT_BINARY_DIR
are very helpful. You can find a more complete list at http://www.cmake.org/Wiki/CMake_Useful_Variables
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