Re-order C/C++/Fortran compiler determination logic
Re-organize CMakeDetermine(C|CXX|Fortran)Compiler.cmake to search for the compiler command-line tool only under generators for which it makes sense. For the Visual Studio generators we do not expect to find the compiler tool from the environment, nor would we use the result anyway. Furthermore, set CMAKE_${lang}_COMPILER_ID_TEST_FLAGS only when it has a chance to be used. Extract _CMAKE_TOOLCHAIN_LOCATION from the compiler path after running the compiler id step so in the future that step can help find the path to the compiler.
This commit is contained in:
parent
2c7a451de0
commit
b8b5c8342a
@ -39,6 +39,12 @@ if(NOT CMAKE_C_COMPILER_NAMES)
|
||||
set(CMAKE_C_COMPILER_NAMES cc)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_C_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_C_PLATFORM_ID "Windows")
|
||||
set(CMAKE_C_COMPILER_ID "MSVC")
|
||||
set(CMAKE_C_COMPILER "${CMAKE_GENERATOR_CC}")
|
||||
else()
|
||||
if(NOT CMAKE_C_COMPILER)
|
||||
set(CMAKE_C_COMPILER_INIT NOTFOUND)
|
||||
|
||||
@ -96,20 +102,6 @@ else()
|
||||
endif()
|
||||
mark_as_advanced(CMAKE_C_COMPILER)
|
||||
|
||||
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
|
||||
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
|
||||
endif ()
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_C_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_C_PLATFORM_ID "Windows")
|
||||
set(CMAKE_C_COMPILER_ID "MSVC")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_C_COMPILER_ID_RUN)
|
||||
set(CMAKE_C_COMPILER_ID_RUN 1)
|
||||
|
||||
# Each entry in this list is a set of extra flags to try
|
||||
# adding to the compile line to see if it helps produce
|
||||
# a valid identification file.
|
||||
@ -120,6 +112,11 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
|
||||
# Try enabling ANSI mode on HP.
|
||||
"-Aa"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(NOT CMAKE_C_COMPILER_ID_RUN)
|
||||
set(CMAKE_C_COMPILER_ID_RUN 1)
|
||||
|
||||
# Try to identify the compiler.
|
||||
set(CMAKE_C_COMPILER_ID)
|
||||
@ -139,6 +136,10 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
|
||||
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
|
||||
endif ()
|
||||
|
||||
# If we have a gcc cross compiler, they have usually some prefix, like
|
||||
# e.g. powerpc-linux-gcc, arm-elf-gcc or i586-mingw32msvc-gcc, optionally
|
||||
# with a 3-component version number at the end (e.g. arm-eabi-gcc-4.5.2).
|
||||
|
@ -38,6 +38,12 @@ if(NOT CMAKE_CXX_COMPILER_NAMES)
|
||||
set(CMAKE_CXX_COMPILER_NAMES CC)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_CXX_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_CXX_PLATFORM_ID "Windows")
|
||||
set(CMAKE_CXX_COMPILER_ID "MSVC")
|
||||
set(CMAKE_CXX_COMPILER "${CMAKE_GENERATOR_CXX}")
|
||||
else()
|
||||
if(NOT CMAKE_CXX_COMPILER)
|
||||
set(CMAKE_CXX_COMPILER_INIT NOTFOUND)
|
||||
|
||||
@ -95,31 +101,6 @@ else()
|
||||
endif()
|
||||
mark_as_advanced(CMAKE_CXX_COMPILER)
|
||||
|
||||
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
|
||||
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
|
||||
endif ()
|
||||
|
||||
# This block was used before the compiler was identified by building a
|
||||
# source file. Unless g++ crashes when building a small C++
|
||||
# executable this should no longer be needed.
|
||||
#
|
||||
# The g++ that comes with BeOS 5 segfaults if you run "g++ -E"
|
||||
# ("gcc -E" is fine), which throws up a system dialog box that hangs cmake
|
||||
# until the user clicks "OK"...so for now, we just assume it's g++.
|
||||
# if(BEOS)
|
||||
# set(CMAKE_COMPILER_IS_GNUCXX 1)
|
||||
# set(CMAKE_COMPILER_IS_GNUCXX_RUN 1)
|
||||
# endif()
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_CXX_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_CXX_PLATFORM_ID "Windows")
|
||||
set(CMAKE_CXX_COMPILER_ID "MSVC")
|
||||
endif()
|
||||
if(NOT CMAKE_CXX_COMPILER_ID_RUN)
|
||||
set(CMAKE_CXX_COMPILER_ID_RUN 1)
|
||||
|
||||
# Each entry in this list is a set of extra flags to try
|
||||
# adding to the compile line to see if it helps produce
|
||||
# a valid identification file.
|
||||
@ -127,6 +108,11 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
|
||||
# Try compiling to an object file only.
|
||||
"-c"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(NOT CMAKE_CXX_COMPILER_ID_RUN)
|
||||
set(CMAKE_CXX_COMPILER_ID_RUN 1)
|
||||
|
||||
# Try to identify the compiler.
|
||||
set(CMAKE_CXX_COMPILER_ID)
|
||||
@ -146,6 +132,10 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
|
||||
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
|
||||
endif ()
|
||||
|
||||
# if we have a g++ cross compiler, they have usually some prefix, like
|
||||
# e.g. powerpc-linux-g++, arm-elf-g++ or i586-mingw32msvc-g++ , optionally
|
||||
# with a 3-component version number at the end (e.g. arm-eabi-gcc-4.5.2).
|
||||
|
@ -25,6 +25,12 @@ if(NOT CMAKE_Fortran_COMPILER_NAMES)
|
||||
set(CMAKE_Fortran_COMPILER_NAMES f95)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_Fortran_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_Fortran_PLATFORM_ID "Windows")
|
||||
set(CMAKE_Fortran_COMPILER_ID "Intel")
|
||||
set(CMAKE_Fortran_COMPILER "${CMAKE_GENERATOR_FC}")
|
||||
else()
|
||||
if(NOT CMAKE_Fortran_COMPILER)
|
||||
# prefer the environment variable CC
|
||||
if($ENV{FC} MATCHES ".+")
|
||||
@ -112,19 +118,8 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
mark_as_advanced(CMAKE_Fortran_COMPILER)
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
|
||||
set(CMAKE_Fortran_COMPILER_ID_RUN 1)
|
||||
set(CMAKE_Fortran_PLATFORM_ID "Windows")
|
||||
set(CMAKE_Fortran_COMPILER_ID "Intel")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_Fortran_COMPILER_ID_RUN)
|
||||
set(CMAKE_Fortran_COMPILER_ID_RUN 1)
|
||||
|
||||
# Each entry in this list is a set of extra flags to try
|
||||
# adding to the compile line to see if it helps produce
|
||||
# a valid identification executable.
|
||||
@ -135,6 +130,11 @@ if(NOT CMAKE_Fortran_COMPILER_ID_RUN)
|
||||
# Intel on windows does not preprocess by default.
|
||||
"-fpp"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Build a small source file to identify the compiler.
|
||||
if(NOT CMAKE_Fortran_COMPILER_ID_RUN)
|
||||
set(CMAKE_Fortran_COMPILER_ID_RUN 1)
|
||||
|
||||
# Table of per-vendor compiler id flags with expected output.
|
||||
list(APPEND CMAKE_Fortran_COMPILER_ID_VENDORS Compaq)
|
||||
|
Loading…
x
Reference in New Issue
Block a user