I am trying to build a cmake project. However cmake fails to find gcc and insists on using my system MSVC install instead. Even when the compiler is explicitly set in arguments.
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=C:/msys32/mingw32/bin/gcc.exe -DCMAKE_C_FLAGS=-O1 -DCMAKE_CXX_COMPILER=C:/msys32/mingw32/bin/g++.exe -DCMAKE_CXX_FLAGS=-O1 -DCMAKE_EXE_LINKER_FLAGS='' -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_MODULE_LINKER_FLAGS='' -DCMAKE_SHARED_LINKER_FLAGS='' -- C:/redacted/openage/openage
-- The C compiler identification is MSVC 18.0.30501.0
-- The CXX compiler identification is MSVC 18.0.30501.0
-- Check for working C compiler using: Visual Studio 12 2013
-- Check for working C compiler using: Visual Studio 12 2013 -- works
...[snipped]
Setting the _COMPILER flags to just gcc/g++ has the same issue.
Weirdly, if the CMakeLists.txt file contains e.g. message(" ${CMAKE_CXX_COMPILER_ID} ") then g++ is displayed.
Package version:
$ pacman -Qs cmake
local/mingw-w64-i686-cmake 3.0.2-1
$ which cmake
/mingw32/bin/cmake
$ cmake --version
cmake version 3.0.2
I'm a little unexperienced with cmake so it might be my problem. But surely, setting CMAKE_C_COMPILER should work properly.
How did you launch your shell? Pass -G'MSYS Makefiles' too.
Thank you, adding -G "MSYS Makefiles" to cmake's argument fixed the issue. I'm just using mingw32_shell.bat to launch my shell.
Is that documented somewhere? What should i have read first before asking?
CMake documentation regarding generators, or "cmake --help"? I can't point you to a specific page.
CMake is a meta-build system, so it generates build files to be run through some other tool, usually the platform 'default' - whatever that means. So on Windows it generates Visual Studio projects on OS X it's Xcode projects and on Linux it's GNU Makefiles.
Understood, thanks.
Would it be sensible to make gcc the default generator instead of MSVC when running cmake under MSYS2?
You mean 'MSYS Makefiles'? Maybe, but really, it's academic. Just set it to what you want and be happy.
I would love to see cmake use "MSYS Makefiles" by default in msys2. On Windows cmake uses the VS toolchain and solution files by default, on Linux Makefiles, on OSX Xcode, so setting MSYS as default for msys2 would be very cmake conform and save typing. Not academic but practical ;)
Most helpful comment
I would love to see cmake use "MSYS Makefiles" by default in msys2. On Windows cmake uses the VS toolchain and solution files by default, on Linux Makefiles, on OSX Xcode, so setting MSYS as default for msys2 would be very cmake conform and save typing. Not academic but practical ;)