Setting up QtCreator to correctly work with CMake
-
Hi,
my setup:
Qt Creator 4.5.1
CMake 3.9.4I'm trying to get a simple CMake HelloWorld to build with QtCreator. I just have a HelloWorld.cpp and a CMakeLists.txt with the following contents:
#include<iostream> int main(int argc, char *argv[]){ std::cout << "Hello World!" << std::endl; return 0; }
cmake_minimum_required(VERSION 3.9.4) project (hello) add_executable(hello helloworld.cpp)
If I import the CMakeLists.txt into QtCreator it tells me the file has successfully been parsed and I'm asked to select a Qt kit for building, in my case Qt 5.9.2 msvc2017.
First weird thing happening. My project view looks like this:
Why is every file showing up 4 times?If I then try to build my project, it fails with the inexpressive message "File not found: MSBUILD"
After digging around, I found out it's because the default build step for all of the 5 targets (default, Release, Debug, RelWithDebugInfo, MinSizeRelease) is cmake --build . --target all and the system is then missing a project file all.vcxproj, so I have to manually change this to sth reasonable for my project (why?)Still, building works then but again, I have 4 run configurations for my project each of them with the exact same parameters. None of them works however because they all point the the following directory:
<my project root>\build-helloworld-Qt_5_9_2_msvc2017_64-Debug\RelWithDebInfo\hello.exe
and none of them builds there. I.e. the run config for RelWithDebugInfo builds in
<my project root>\build-helloworld-Qt_5_9_2_msvc2017_64-Release with Debug Information\Debug
I tried to generate a new run configuration adjusting the output path but if I try to run this one, it also fails with the error message:
You asked to build the current Run Configuration's build target only, but it is not associated with a build target. Update the Make Step in your build settings.
So everything appears to be totally messed up. What am I doing wrong here?!
-
For the kit you selected, what is the 'CMake Generator' set to? You probably want to set it to 'NMake Makefiles'
Go to options ->Build & Run -> Kits
For your selected kit, go down to the 'CMake Generator' setting and hit the 'Change' button on the far right and change the generator to 'NMake Makefiles'.