MSYS/MinGW Makfiles: Select the compiler occurring first in PATH

Extend the change from commit e01990999a (Ninja: On Windows, select the
compiler occurring first in PATH, 2020-04-17, v3.18.0-rc1~291^2) to
apply to the MSYS/MinGW Makefiles generators too.  Drop the implied
`gcc` and `g++` default compilers.  This allows MinGW/Clang environments
to work out of the box.

Inspired-by: Mehdi Chinoune <mehdi.chinoune@hotmail.com>
Fixes: #23542
This commit is contained in:
Brad King
2022-05-26 13:05:38 -04:00
parent d45b4f59a4
commit 9019537670
4 changed files with 10 additions and 28 deletions

View File

@@ -0,0 +1,7 @@
mingw-compiler-PATH
-------------------
* The :generator:`MSYS Makefiles` and :generator:`MinGW Makefiles`
generators, when a compiler is not explicitly specified, now select
the first compiler (of any name) found in directories listed by the
``PATH`` environment variable.

View File

@@ -53,10 +53,9 @@ macro(_cmake_find_compiler lang)
NO_DEFAULT_PATH
DOC "${lang} compiler")
endif()
if(CMAKE_HOST_WIN32 AND CMAKE_GENERATOR MATCHES "Ninja")
# On Windows command-line builds, the Makefile generators each imply
# a preferred compiler tool. The Ninja generator does not imply a
# compiler tool, so use the compiler that occurs first in PATH.
if(CMAKE_HOST_WIN32 AND CMAKE_GENERATOR MATCHES "Ninja|MSYS Makefiles|MinGW Makefiles")
# On Windows command-line builds, some generators imply a preferred compiler tool.
# These generators do not, so use the compiler that occurs first in PATH.
find_program(CMAKE_${lang}_COMPILER
NAMES ${CMAKE_${lang}_COMPILER_LIST}
NAMES_PER_DIR

View File

@@ -51,24 +51,12 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage(
locations.push_back(makeloc);
locations.push_back("/mingw/bin");
locations.push_back("c:/mingw/bin");
std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
std::string gcc = "gcc.exe";
if (!tgcc.empty()) {
gcc = tgcc;
}
std::string tgxx = cmSystemTools::FindProgram("g++", locations);
std::string gxx = "g++.exe";
if (!tgxx.empty()) {
gxx = tgxx;
}
std::string trc = cmSystemTools::FindProgram("windres", locations);
std::string rc = "windres.exe";
if (!trc.empty()) {
rc = trc;
}
mf->AddDefinition("MSYS", "1");
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc);
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx);
mf->AddDefinition("CMAKE_GENERATOR_RC", rc);
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);

View File

@@ -29,23 +29,11 @@ void cmGlobalMinGWMakefileGenerator::EnableLanguage(
locations.push_back(cmSystemTools::GetProgramPath(makeProgram));
locations.push_back("/mingw/bin");
locations.push_back("c:/mingw/bin");
std::string tgcc = cmSystemTools::FindProgram("gcc", locations);
std::string gcc = "gcc.exe";
if (!tgcc.empty()) {
gcc = tgcc;
}
std::string tgxx = cmSystemTools::FindProgram("g++", locations);
std::string gxx = "g++.exe";
if (!tgxx.empty()) {
gxx = tgxx;
}
std::string trc = cmSystemTools::FindProgram("windres", locations);
std::string rc = "windres.exe";
if (!trc.empty()) {
rc = trc;
}
mf->AddDefinition("CMAKE_GENERATOR_CC", gcc);
mf->AddDefinition("CMAKE_GENERATOR_CXX", gxx);
mf->AddDefinition("CMAKE_GENERATOR_RC", rc);
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
}