summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-04-17 09:44:30 -0400
committerBrad King <brad.king@kitware.com>2020-04-22 08:03:16 -0400
commite01990999a83fb08b0e46b3131501c01e3256944 (patch)
treecb89821b1aea1bbab3566897e12cb569aa0912dd /Modules/CMakeDetermineCompiler.cmake
parent8bc757c8f68d653526dce3f723950ccf221a4c6c (diff)
downloadcmake-e01990999a83fb08b0e46b3131501c01e3256944.tar.gz
Ninja: On Windows, select the compiler occurring first in PATH
On Windows, toolchains like MSVC require a set of environment variables to be configured for the compiler to work correctly. The scripts that prepare these environments typically put the compiler's directory ahead of others in the `PATH`. Teach the Ninja generators to use this as a heuristic to select the compiler when none is explicitly specified. This is not necessary with Makefile generators because each toolchain's environment comes with its own make tool variant, and the corresponding Makefile generator (e.g. "NMake Makefiles") automatically implies the matching compiler. Fixes: #20585
Diffstat (limited to 'Modules/CMakeDetermineCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCompiler.cmake14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index 7afae8af6b..da93b5c09b 100644
--- a/Modules/CMakeDetermineCompiler.cmake
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -53,6 +53,20 @@ 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.
+ find_program(CMAKE_${lang}_COMPILER
+ NAMES ${CMAKE_${lang}_COMPILER_LIST}
+ NAMES_PER_DIR
+ DOC "${lang} compiler"
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ )
+ 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_property(CACHE CMAKE_${lang}_COMPILER PROPERTY VALUE "${CMAKE_${lang}_COMPILER_INIT}")