QtCreator runs CMake from /tmp directory
-
I have a CMake project in which one of the first things done is to run
execute_process (COMMAND git rev-parse --show-toplevel OUTPUT_VARIABLE FOCUS_REPO_ROOT OUTPUT_STRIP_TRAILING_WHITESPACE)
to get the root directory of the repository. It fails though because qtcreator appears to be running cmake from a /tmp folder:
Running "/usr/bin/cmake /home/overlord/focus/build/cmake '-GCodeBlocks - Unix Makefiles' -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++ -DQT_QMAKE_EXECUTABLE:STRING=/home/overlord/Qt5.7.0/5.7/gcc_64/bin/qmake" in /tmp/qtc-cmake-DU5v5x
The error received is
fatal: Not a git repository (or any of the parent directories): .git
and qtcreator quits parsing the CMakeLists.txt file.
Is there a way to tell qtcreator to run CMake from a specific directory?
-
Hi,
You should add which version of Qt Creator you are using.
-
I am using Qt Creator 4.0.2 (Qt 5.7.0, although I am not using the qt libraries in this project)
-
After a quick check, you should add
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
to your execute_process calls. That way the command will be called in your project source tree whatever the folder cmake is called from. -
Perfect. Thanks!
-
CMake insists on creating the build directory, and it is annoying that you have to delete build directories all over the place when all you want to do is take a quick look at some sources. So creator "builds" in a temporary directory to extract information from CMake -- till you actually trigger an explicit build from creator. At that point the actual build directory is created and all the files go there.
You need to tell cmake to run your command in the source directory if those commands depend on being run from there: CMake usually does not build in the directory your sources are and will default to running stuff in the build directory.