From 9019537670003d8d35b6d838c7b22a751b4119b2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 May 2022 13:05:38 -0400 Subject: 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 Fixes: #23542 --- Help/release/dev/mingw-compiler-PATH.rst | 7 +++++++ Modules/CMakeDetermineCompiler.cmake | 7 +++---- Source/cmGlobalMSYSMakefileGenerator.cxx | 12 ------------ Source/cmGlobalMinGWMakefileGenerator.cxx | 12 ------------ 4 files changed, 10 insertions(+), 28 deletions(-) create mode 100644 Help/release/dev/mingw-compiler-PATH.rst diff --git a/Help/release/dev/mingw-compiler-PATH.rst b/Help/release/dev/mingw-compiler-PATH.rst new file mode 100644 index 0000000..7452da0 --- /dev/null +++ b/Help/release/dev/mingw-compiler-PATH.rst @@ -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. diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index ec2a865..3156ca9 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -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 diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index c8520b8..cb63110 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -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); diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index 54d048d..781912f 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -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); } -- cgit v0.12 From 55ba10dcfdfb1f69b81284810aa6f07dc1527ccb Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 26 May 2022 13:23:24 -0400 Subject: MSYS/MinGW Makefiles: Simplify selection of windres as Resource Compiler Since commit 957c2aac7f (RC: Simplify selection of resource compiler based on C/C++ toolchain, 2015-05-07, v3.3.0-rc1~101^2~3), `windres` is selected automatically when using compilers that target the GNU ABI. Drop the generator-specific preference to make behavior more consistent with the Ninja generator. Issue: #23542 --- Source/cmGlobalMSYSMakefileGenerator.cxx | 15 --------------- Source/cmGlobalMinGWMakefileGenerator.cxx | 19 ------------------- Source/cmGlobalMinGWMakefileGenerator.h | 7 ------- 3 files changed, 41 deletions(-) diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx index cb63110..d4ff1e0 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.cxx +++ b/Source/cmGlobalMSYSMakefileGenerator.cxx @@ -42,22 +42,7 @@ std::string cmGlobalMSYSMakefileGenerator::FindMinGW( void cmGlobalMSYSMakefileGenerator::EnableLanguage( std::vector const& l, cmMakefile* mf, bool optional) { - this->FindMakeProgram(mf); - const std::string& makeProgram = - mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - std::vector locations; - std::string makeloc = cmSystemTools::GetProgramPath(makeProgram); - locations.push_back(this->FindMinGW(makeloc)); - locations.push_back(makeloc); - locations.push_back("/mingw/bin"); - locations.push_back("c:/mingw/bin"); - 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_RC", rc); this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); if (!mf->IsSet("CMAKE_AR") && !this->CMakeInstance->GetIsInTryCompile() && diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx index 781912f..5a7edae 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.cxx +++ b/Source/cmGlobalMinGWMakefileGenerator.cxx @@ -19,25 +19,6 @@ cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator(cmake* cm) cm->GetState()->SetMinGWMake(true); } -void cmGlobalMinGWMakefileGenerator::EnableLanguage( - std::vector const& l, cmMakefile* mf, bool optional) -{ - this->FindMakeProgram(mf); - const std::string& makeProgram = - mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM"); - std::vector locations; - locations.push_back(cmSystemTools::GetProgramPath(makeProgram)); - locations.push_back("/mingw/bin"); - locations.push_back("c:/mingw/bin"); - std::string trc = cmSystemTools::FindProgram("windres", locations); - std::string rc = "windres.exe"; - if (!trc.empty()) { - rc = trc; - } - mf->AddDefinition("CMAKE_GENERATOR_RC", rc); - this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional); -} - void cmGlobalMinGWMakefileGenerator::GetDocumentation( cmDocumentationEntry& entry) { diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h index 1574faf..92d495c 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.h +++ b/Source/cmGlobalMinGWMakefileGenerator.h @@ -36,11 +36,4 @@ public: /** Get the documentation entry for this generator. */ static void GetDocumentation(cmDocumentationEntry& entry); - - /** - * Try to determine system information such as shared library - * extension, pthreads, byte order etc. - */ - virtual void EnableLanguage(std::vector const& languages, - cmMakefile*, bool optional); }; -- cgit v0.12