cmake + mingw32: invalid option '-?'

Can’t compile anything by cmake, including Step 1 tutorial example. There is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)

set( CMAKE_CXX_COMPILER "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/g++.exe" )
set( CMAKE_C_COMPILER "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/gcc.exe" )
set( CMAKE_MAKE_PROGRAM "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" )

# set the project name
project(Tutorial)

# add the executable
add_executable(Tutorial tutorial.cxx)

cmake returns error:

CMake Error at CMakeLists.txt:8 (project):
  Running

   'c:/PROGRA~1/MINGW-~1/X86_64~1.0-W/mingw64/bin/mingw32-make.exe' '-?'

  failed with:

   c:/PROGRA~1/MINGW-~1/X86_64~1.0-W/mingw64/bin/mingw32-make.exe: invalid option -- ?

  Usage: mingw32-make.exe [options] [target] ...

  Options:

    -b, -m                      Ignored for compatibility.
    -B, --always-make           Unconditionally make all targets.
(long list of all mingw32-make options )

Why cmake run mingw32-make.exe with option ‘-?’ ? Tried to find answer via Internet, but found nothing :frowning:

What is the CMake command line you’re using? I would guess that you’re probably using a Windows CMake build which is trying to use MSBuild internally. Rather than setting the compilers in the CMake source directly, it is recommended that you instead just run CMake from a MinGW environment and let it discover things on its own.

Yes, I use a Windows CMake. Run it by the simplest command:

cmake .

Current directory is source files directory, of course.
How can I use CMake from a MinGW environment? I do not use graphic interfaces, just command line tools. Should I run something from mingw bin directory to do it?
By the way, I think there must be a way to explicitly point to CMake which build tool to use.

That will probably use a Visual Studio generator. Trying to get that to use MinGW is certainly doomed to failure. Your MinGW source should have a package manager to be able to get its cmake (pacman?).

So, this line of my CMakeLists.txt

set( CMAKE_MAKE_PROGRAM "c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" )

is completely useless? And CMake tries to use Visual Studio nmake instead of it?

No? Without a -G, Windows CMake defaults to Visual Studio for its builds. Neither NMake nor MinGW make is going to work under such expectations.

1 Like

So I should run CMake in such way:

cmake -G "MinGW Makefiles" .

?

Is there any way to point this in CMakeLists.txt? Or only in command line?

The CMake code cannot affect the generator; it must be set on the command line (or through the CMAKE_GENERATOR environment variable).

1 Like

Thank you for an explanation