From 731427a646cd0ca81aa392872d18d125e917bf47 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 24 Jul 2014 12:44:05 -0400 Subject: [PATCH 1/2] cmGlobalGenerator: Do not re-add CMAKE__COMPILER The cmGlobalGenerator::ResolveLanguageCompiler method, invoked only by Makefile generators, contains code originally added by commit v2.4.0~796 (..., add new generators for msys and mingw, 2005-12-22) to compute the full path to the compiler and save the result back into the cache value. Since then the CMakeDetermine*Compiler modules have learned to resolve the full path to the compiler and save it in CMake*Compiler.cmake files configured in the build tree. The value of CMAKE__COMPILER in the cache is now only for reference of what the user originally specified. The full path is now available in a normal variable of the same name, and this is used by project code and the generators. When the user specifies -DCMAKE__COMPILER=name on the command-line of an existing build tree that uses a Makefile generator, it is first stored in the cache with an uninitialized type. Then later when ResolveLanguageCompiler updates the cache entry and sets the type to FILEPATH, cmMakefile::AddCacheDefinition does CollapseFullPath on the "name" and ends up with something like "$PWD/name" which is unlikely to be correct. Furthermore, cmMakefile::AddCacheDefinition proceeds to remove the normal variable of the same name, so the value originally saved in CMakeCompiler.cmake is ignored and the generators use the wrong path to the compiler. Resolve this by dropping the code from ResolveLanguageCompiler that touches the cache value of CMAKE__COMPILER. As explained above it is no longer needed anyway. --- Source/cmGlobalGenerator.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index ae6861e0b..249373cf2 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -148,8 +148,6 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang, { return; } - std::string doc = lang; - doc += " compiler."; const char* cname = this->GetCMakeInstance()-> GetCacheManager()->GetCacheValue(langComp); std::string changeVars; @@ -186,8 +184,6 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string &lang, changeVars.c_str()); } } - mf->AddCacheDefinition(langComp, path.c_str(), - doc.c_str(), cmCacheManager::FILEPATH); } void cmGlobalGenerator::AddBuildExportSet(cmExportBuildFileGenerator* gen) From 8981513a810a97d10e299407e12c46aabe68f00a Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 24 Jul 2014 13:10:05 -0400 Subject: [PATCH 2/2] CMakeDetermineCompiler: Simplify CMAKE__COMPILER default force-cache If find_program does not find CMAKE__COMPILER, use set_property() to force the value to be that of CMAKE__COMPILER_INIT instead of set(). This allows us to set the value without re-specifying the type and documentation, thus preserving what find_program set. --- Modules/CMakeDetermineCompiler.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index cd0f8b8ee..0ab3af62c 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -65,7 +65,7 @@ macro(_cmake_find_compiler lang) endif() find_program(CMAKE_${lang}_COMPILER NAMES ${CMAKE_${lang}_COMPILER_LIST} DOC "${lang} compiler") if(CMAKE_${lang}_COMPILER_INIT AND NOT CMAKE_${lang}_COMPILER) - set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_INIT}" CACHE FILEPATH "${lang} compiler" FORCE) + set_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${CMAKE_${lang}_COMPILER_INIT}") endif() unset(_${lang}_COMPILER_HINTS) unset(_languages)