Merge topic 'clang-cl-compiler'

3d8356d Clang: Support Windows variants for GNU and MSVC (#13035, #14458)
51ab85c CMakeDetermineCompilerId: Add notion of "simulated" id/version
be10826 CMakeDetermineCompilerId: Fix local var init
This commit is contained in:
Brad King 2013-10-08 10:58:56 -04:00 committed by CMake Topic Stage
commit 5a6c15155c
14 changed files with 155 additions and 14 deletions

View File

@ -3,6 +3,8 @@ set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@")
set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@") set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@") set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@") set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@")
set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@")
set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
@SET_MSVC_C_ARCHITECTURE_ID@ @SET_MSVC_C_ARCHITECTURE_ID@
set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@") set(CMAKE_RANLIB "@CMAKE_RANLIB@")

View File

@ -33,6 +33,12 @@
# define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
# define COMPILER_ID "Embarcadero" # define COMPILER_ID "Embarcadero"
@ -206,6 +212,9 @@
because some compilers will just produce instructions to fill the because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */ array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
@CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@ @CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
@ -222,6 +231,12 @@ int main(int argc, char* argv[])
require += info_arch[argc]; require += info_arch[argc];
#ifdef COMPILER_VERSION_MAJOR #ifdef COMPILER_VERSION_MAJOR
require += info_version[argc]; require += info_version[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif #endif
(void)argv; (void)argv;
return require; return require;

View File

@ -3,6 +3,8 @@ set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@")
set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@") set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@") set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@") set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
@SET_MSVC_CXX_ARCHITECTURE_ID@ @SET_MSVC_CXX_ARCHITECTURE_ID@
set(CMAKE_AR "@CMAKE_AR@") set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@") set(CMAKE_RANLIB "@CMAKE_RANLIB@")

View File

@ -38,6 +38,12 @@
# define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MAJOR DEC(__clang_major__)
# define COMPILER_VERSION_MINOR DEC(__clang_minor__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__)
# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) # define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__)
# if defined(_MSC_VER)
# define SIMULATE_ID "MSVC"
/* _MSC_VER = VVRR */
# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100)
# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100)
# endif
#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) #elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)
# define COMPILER_ID "Embarcadero" # define COMPILER_ID "Embarcadero"
@ -199,6 +205,9 @@
because some compilers will just produce instructions to fill the because some compilers will just produce instructions to fill the
array rather than assigning a pointer to a static array. */ array rather than assigning a pointer to a static array. */
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
#ifdef SIMULATE_ID
char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
#endif
@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@ @CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
@ -211,6 +220,12 @@ int main(int argc, char* argv[])
require += info_platform[argc]; require += info_platform[argc];
#ifdef COMPILER_VERSION_MAJOR #ifdef COMPILER_VERSION_MAJOR
require += info_version[argc]; require += info_version[argc];
#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
#ifdef SIMULATE_VERSION_MAJOR
require += info_simulate_version[argc];
#endif #endif
(void)argv; (void)argv;
return require; return require;

View File

@ -80,6 +80,8 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
PARENT_SCOPE) PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
endfunction() endfunction()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
@ -309,9 +311,12 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
set(COMPILER_ID) set(COMPILER_ID)
set(COMPILER_VERSION) set(COMPILER_VERSION)
set(PLATFORM_ID) set(PLATFORM_ID)
set(ARCHITECTURE_ID)
set(SIMULATE_ID)
set(SIMULATE_VERSION)
file(STRINGS ${file} file(STRINGS ${file}
CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 4 REGEX "INFO:") CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 6 REGEX "INFO:")
set(HAVE_COMPILER_TWICE 0) set(COMPILER_ID_TWICE)
foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS}) foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS})
if("${info}" MATCHES ".*INFO:compiler\\[([^]\"]*)\\].*") if("${info}" MATCHES ".*INFO:compiler\\[([^]\"]*)\\].*")
if(COMPILER_ID) if(COMPILER_ID)
@ -333,6 +338,14 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION "${COMPILER_VERSION}") string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION "${COMPILER_VERSION}")
string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}") string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
endif() endif()
if("${info}" MATCHES ".*INFO:simulate\\[([^]\"]*)\\].*")
set(SIMULATE_ID "${CMAKE_MATCH_1}")
endif()
if("${info}" MATCHES ".*INFO:simulate_version\\[([^]\"]*)\\].*")
set(SIMULATE_VERSION "${CMAKE_MATCH_1}")
string(REGEX REPLACE "^0+([0-9])" "\\1" SIMULATE_VERSION "${SIMULATE_VERSION}")
string(REGEX REPLACE "\\.0+([0-9])" ".\\1" SIMULATE_VERSION "${SIMULATE_VERSION}")
endif()
endforeach() endforeach()
# Detect the exact architecture from the PE header. # Detect the exact architecture from the PE header.
@ -370,6 +383,8 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}") set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}")
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}") set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}") set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}")
set(CMAKE_${lang}_SIMULATE_ID "${SIMULATE_ID}")
set(CMAKE_${lang}_SIMULATE_VERSION "${SIMULATE_VERSION}")
endif() endif()
# Check the compiler identification string. # Check the compiler identification string.
@ -418,6 +433,8 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
PARENT_SCOPE) PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE) set(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE)
endfunction() endfunction()

View File

@ -30,8 +30,10 @@
# License text for the above reference.) # License text for the above reference.)
# if it's the MS C/CXX compiler, search for link # if it's the MS C/CXX compiler, search for link
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"
OR "${CMAKE_C_COMPILER_ID}" MATCHES "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC"
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"
OR "${CMAKE_GENERATOR}" MATCHES "Visual Studio") OR "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})

View File

@ -151,6 +151,24 @@ char const info_version[] = {
']','\0'}; ']','\0'};
#endif #endif
/* Construct a string literal encoding the version number components. */
#ifdef SIMULATE_VERSION_MAJOR
char const info_simulate_version[] = {
'I', 'N', 'F', 'O', ':',
's','i','m','u','l','a','t','e','_','v','e','r','s','i','o','n','[',
SIMULATE_VERSION_MAJOR,
# ifdef SIMULATE_VERSION_MINOR
'.', SIMULATE_VERSION_MINOR,
# ifdef SIMULATE_VERSION_PATCH
'.', SIMULATE_VERSION_PATCH,
# ifdef SIMULATE_VERSION_TWEAK
'.', SIMULATE_VERSION_TWEAK,
# endif
# endif
# endif
']','\0'};
#endif
/* Construct the string literal in pieces to prevent the source from /* Construct the string literal in pieces to prevent the source from
getting matched. Store it in a pointer rather than an array getting matched. Store it in a pointer rather than an array
because some compilers will just produce instructions to fill the because some compilers will just produce instructions to fill the

View File

@ -1,4 +1,6 @@
include(Compiler/Clang) include(Compiler/Clang)
__compiler_clang(CXX) __compiler_clang(CXX)
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden") if(NOT CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
endif()

View File

@ -18,11 +18,17 @@ if(__COMPILER_CLANG)
endif() endif()
set(__COMPILER_CLANG 1) set(__COMPILER_CLANG 1)
include(Compiler/GNU) if(CMAKE_C_SIMULATE_ID STREQUAL "MSVC"
OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
macro(__compiler_clang lang)
endmacro()
else()
include(Compiler/GNU)
macro(__compiler_clang lang) macro(__compiler_clang lang)
__compiler_gnu(${lang}) __compiler_gnu(${lang})
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
endmacro() endmacro()
endif()

View File

@ -0,0 +1,2 @@
include(Platform/Windows-Clang)
__windows_compiler_clang(C)

View File

@ -0,0 +1,2 @@
include(Platform/Windows-Clang)
__windows_compiler_clang(CXX)

View File

@ -0,0 +1,32 @@
#=============================================================================
# Copyright 2001-2013 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# This module is shared by multiple languages; use include blocker.
if(__WINDOWS_CLANG)
return()
endif()
set(__WINDOWS_CLANG 1)
if(CMAKE_C_SIMULATE_ID STREQUAL "MSVC"
OR CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
include(Platform/Windows-MSVC)
macro(__windows_compiler_clang lang)
__windows_compiler_msvc(${lang})
endmacro()
else()
include(Platform/Windows-GNU)
macro(__windows_compiler_clang lang)
__windows_compiler_gnu(${lang})
endmacro()
endif()

View File

@ -65,7 +65,11 @@ else()
endif() endif()
if(NOT MSVC_VERSION) if(NOT MSVC_VERSION)
if(CMAKE_C_COMPILER_VERSION) if(CMAKE_C_SIMULATE_VERSION)
set(_compiler_version ${CMAKE_C_SIMULATE_VERSION})
elseif(CMAKE_CXX_SIMULATE_VERSION)
set(_compiler_version ${CMAKE_CXX_SIMULATE_VERSION})
elseif(CMAKE_C_COMPILER_VERSION)
set(_compiler_version ${CMAKE_C_COMPILER_VERSION}) set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
else() else()
set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION}) set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
@ -220,7 +224,7 @@ set (CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT ${CMAKE_EXE_LINKER_FLAGS_RELEASE_INI
set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT}) set (CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL_INIT})
macro(__windows_compiler_msvc lang) macro(__windows_compiler_msvc lang)
if(NOT "${CMAKE_${lang}_COMPILER_VERSION}" VERSION_LESS 14) if(NOT MSVC_VERSION LESS 1400)
# for 2005 make sure the manifest is put in the dll with mt # for 2005 make sure the manifest is put in the dll with mt
set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll ") set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll ")
set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe ") set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe ")

View File

@ -1674,6 +1674,28 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
false, false,
"Variables for Languages"); "Variables for Languages");
cm->DefineProperty
("CMAKE_<LANG>_SIMULATE_ID", cmProperty::VARIABLE,
"Identification string of \"simulated\" compiler.",
"Some compilers simulate other compilers to serve as drop-in "
"replacements. "
"When CMake detects such a compiler it sets this variable to what "
"would have been the CMAKE_<LANG>_COMPILER_ID for the simulated "
"compiler.",
false,
"Variables for Languages");
cm->DefineProperty
("CMAKE_<LANG>_SIMULATE_VERSION", cmProperty::VARIABLE,
"Version string of \"simulated\" compiler.",
"Some compilers simulate other compilers to serve as drop-in "
"replacements. "
"When CMake detects such a compiler it sets this variable to what "
"would have been the CMAKE_<LANG>_COMPILER_VERSION for the simulated "
"compiler.",
false,
"Variables for Languages");
cm->DefineProperty cm->DefineProperty
("CMAKE_<LANG>_SIZEOF_DATA_PTR", cmProperty::VARIABLE, ("CMAKE_<LANG>_SIZEOF_DATA_PTR", cmProperty::VARIABLE,
"Size of pointer-to-data types for language <LANG>.", "Size of pointer-to-data types for language <LANG>.",