From 3d8356d486ae736d1ba151aedfeb928222e7a084 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 4 Oct 2013 10:13:08 -0400 Subject: Clang: Support Windows variants for GNU and MSVC (#13035, #14458) Teach the compiler identification preprocessor tests to report when Clang simulates MSVC, and what version. If not MSVC, assume GNU. Teach compiler information modules Clang-(C|CXX) to recognize when Clang simulates MSVC and skip loading the GNU information. Teach the Windows-MSVC platform information to recognize when it is loaded as the simulated compiler and use that version information instead of the real compiler's (different) version scheme. Add platform modules Windows-Clang-(C|CXX) and support module Windows-Clang to load either Windows-MSVC or Windows-GNU and wrap the corresponding information macros. --- Modules/CMakeCCompilerId.c.in | 6 ++++++ Modules/CMakeCXXCompilerId.cpp.in | 6 ++++++ Modules/CMakeFindBinUtils.cmake | 6 ++++-- Modules/Compiler/Clang-CXX.cmake | 4 +++- Modules/Compiler/Clang.cmake | 20 +++++++++++++------- Modules/Platform/Windows-Clang-C.cmake | 2 ++ Modules/Platform/Windows-Clang-CXX.cmake | 2 ++ Modules/Platform/Windows-Clang.cmake | 32 ++++++++++++++++++++++++++++++++ Modules/Platform/Windows-MSVC.cmake | 8 ++++++-- 9 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 Modules/Platform/Windows-Clang-C.cmake create mode 100644 Modules/Platform/Windows-Clang-CXX.cmake create mode 100644 Modules/Platform/Windows-Clang.cmake diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 48b46fa..dda7bf6 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -33,6 +33,12 @@ # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # 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__) # define COMPILER_ID "Embarcadero" diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index f4a4176..915ae7f 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -38,6 +38,12 @@ # define COMPILER_VERSION_MAJOR DEC(__clang_major__) # define COMPILER_VERSION_MINOR DEC(__clang_minor__) # 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__) # define COMPILER_ID "Embarcadero" diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index e70c013..b4e2ae5 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -30,8 +30,10 @@ # License text for the above reference.) # if it's the MS C/CXX compiler, search for link -if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" - OR "${CMAKE_C_COMPILER_ID}" MATCHES "MSVC" +if("${CMAKE_C_SIMULATE_ID}" STREQUAL "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") find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake index 972d889..0372e18 100644 --- a/Modules/Compiler/Clang-CXX.cmake +++ b/Modules/Compiler/Clang-CXX.cmake @@ -1,4 +1,6 @@ include(Compiler/Clang) __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() diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake index ec4562a..7d7be5c 100644 --- a/Modules/Compiler/Clang.cmake +++ b/Modules/Compiler/Clang.cmake @@ -18,11 +18,17 @@ if(__COMPILER_CLANG) endif() 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) - __compiler_gnu(${lang}) - set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") - set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") - set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") -endmacro() + macro(__compiler_clang lang) + __compiler_gnu(${lang}) + set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE") + set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ") + set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=") + endmacro() +endif() diff --git a/Modules/Platform/Windows-Clang-C.cmake b/Modules/Platform/Windows-Clang-C.cmake new file mode 100644 index 0000000..d007105 --- /dev/null +++ b/Modules/Platform/Windows-Clang-C.cmake @@ -0,0 +1,2 @@ +include(Platform/Windows-Clang) +__windows_compiler_clang(C) diff --git a/Modules/Platform/Windows-Clang-CXX.cmake b/Modules/Platform/Windows-Clang-CXX.cmake new file mode 100644 index 0000000..2c3688a --- /dev/null +++ b/Modules/Platform/Windows-Clang-CXX.cmake @@ -0,0 +1,2 @@ +include(Platform/Windows-Clang) +__windows_compiler_clang(CXX) diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake new file mode 100644 index 0000000..4c936fe --- /dev/null +++ b/Modules/Platform/Windows-Clang.cmake @@ -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() diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake index 7036ba0..a2cfe33 100644 --- a/Modules/Platform/Windows-MSVC.cmake +++ b/Modules/Platform/Windows-MSVC.cmake @@ -65,7 +65,11 @@ else() endif() 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}) else() 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}) 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 set(_CMAKE_VS_LINK_DLL " -E vs_link_dll ") set(_CMAKE_VS_LINK_EXE " -E vs_link_exe ") -- cgit v0.12