Lukas
Lukas

Reputation: 2613

Qt Creator using MinGW compiler with CMake

I'm trying to use Qt Creator for C++ CMake project which doesn't use the Qt libraries.

I'm following the official guide, but it does not work at all. Here are my steps:

  1. Add my MinGW bin directory to PATH.
  2. Run QtCreator and setup CMake.
  3. Open a a very basic CMakeLists.txt file.
  4. Select "Ninja (Desktop)" as CMake generator.
  5. Getting errors from CMake.

You may have noticed that step 4 is actually not mentioned at all in the official guide. I'm quite used to CMake and as such I'm asking myself:

Why doesn't the Qt Creator offer the normal "MinGW Makefiles" generator?

Ninja or NMake only

And finally the ultimate question:

How can I make the Qt Creator use a MinGW compiler through CMake?


Answered questions:

According to the official guide and as usual when you set PATH correctly, step 5 should not happen.

Why doesn't CMake find the compiler set in PATH?

It's the Ninja Generator that creates these errors, the same thing happens if you do it manually with CMake.

My PATH settings

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: D:/Programming/C++/Test/SupportQt/build/CMakeFiles/3.0.2/CMakeCXXCompiler.cmake
CMake Error at CMakeLists.txt:1 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting the CMake cache entry
  CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name
  if it is in the PATH.


CMake Error at CMakeLists.txt:1 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting the CMake cache entry
  CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler
  name if it is in the PATH.


CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file: D:/Programming/C++/Test/SupportQt/build/CMakeFiles/3.0.2/CMakeCCompiler.cmake

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.-- Configuring incomplete, errors occurred!

Looking at the configuration menu to see whether I have forgotten to setup something, I stumbled across the compiler setup page. I then of course added my compiler there as well, but it did nothing.

Why doesn't CMake use the compiler list when using CMake?

It does use the compiler list, IF you pick the right compiler in the kits selection.

Options -> Build & Run

Upvotes: 4

Views: 8730

Answers (1)

Lukas
Lukas

Reputation: 2613

As usually if you ask for help only to shortly after figure it out, I feel quite stupid now...

Why doesn't the Qt Creator use the compiler list when using CMake?

It does, but only if you set the Kit to use the right compiler!

Qt Creator Kits

Why doesn't CMake find the compiler set in PATH?

This is actually the problem of the Ninja Generator with CMake. The same thing happens if you use CMake directly.

Why doesn't the Qt Creator offer the normal "MinGW Makefiles" generator?

It does, but only if you picked a MinGW compiler in your Kit!

MinGW Generator

How can I make the Qt Creator use a MinGW compiler through CMake?

By setting everything up correctly and not relying too heavily on the official guide.

It works!

Upvotes: 6

Related Questions