diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 9e2ea7800a..ce8fdebc4b 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -858,8 +858,11 @@ void cmGlobalGenerator::EnableLanguage( this->SetLanguageEnabled("NONE", mf); continue; } - std::string loadedLang = cmStrCat("CMAKE_", lang, "_COMPILER_LOADED"); - if (!mf->GetDefinition(loadedLang)) { + // Compiler information may have already been detected and saved. + // Load it if we have not enabled the language anywhere yet, or + // if we have not loaded compiler information in this directory. + if (!this->GetLanguageEnabled(lang) || + !mf->GetDefinition(cmStrCat("CMAKE_", lang, "_COMPILER_LOADED"))) { fpath = cmStrCat(rootBin, "/CMake", lang, "Compiler.cmake"); // If the existing build tree was already configured with this diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake index b588ce03d1..5105e7afa9 100644 --- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake +++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake @@ -14,6 +14,7 @@ run_cmake_toolchain(LinkFlagsInit) run_cmake_toolchain(CMP0126-NEW) run_cmake_toolchain(CMP0126-OLD) run_cmake_toolchain(CMP0126-WARN) +run_cmake_toolchain(SetCompilerLoaded) run_cmake_toolchain(SetCrossCompiling) function(run_IncludeDirectories) diff --git a/Tests/RunCMake/ToolchainFile/SetCompilerLoaded-toolchain.cmake b/Tests/RunCMake/ToolchainFile/SetCompilerLoaded-toolchain.cmake new file mode 100644 index 0000000000..b127236eaa --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/SetCompilerLoaded-toolchain.cmake @@ -0,0 +1 @@ +set(CMAKE_C_COMPILER_LOADED 1) diff --git a/Tests/RunCMake/ToolchainFile/SetCompilerLoaded.cmake b/Tests/RunCMake/ToolchainFile/SetCompilerLoaded.cmake new file mode 100644 index 0000000000..e731cbc29e --- /dev/null +++ b/Tests/RunCMake/ToolchainFile/SetCompilerLoaded.cmake @@ -0,0 +1,5 @@ +enable_language(C) +try_compile(SHOULD_PASS SOURCE_FROM_CONTENT "main.c" "int main(void) { return 0; }") +if(NOT SHOULD_PASS) + message(FATAL_ERROR "try_compile failed but should have passed!") +endif()