Commit 067a4f48 authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'clang-gnulike-support'

74829f01 Help: Add notes for topic 'clang-gnulike-support'
19669abe Tests: handle string escaping differences with NMake+clang
a2a90f41 Tests: require C++14 for the Tutorial
4819ff96 Tests: fix failures with gnu mode clang on windows
26af0b25 cmake: use correct stack size with gnu mode clang on windows
d44c0db0 clang: setup correct configuration in gnu mode
b7d5ef23 cmGlobalNinjaGenerator: use gnu compatible paths with clang in gnu mode
3d0210d8 binutils: add the llvm-* variants to the tool lists.
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Francesco Bertolaccini's avatarFrancesco Bertolaccini <francesco@bertolaccini.dev>
Acked-by: Stanislav Ershov's avatarStanislav Ershov <digital.stream.of.mind@gmail.com>
Acked-by: Saleem Abdulrasool's avatarSaleem Abdulrasool <compnerd@compnerd.org>
Merge-request: !2992
parents 8b42d560 74829f01
Pipeline #138017 passed with stage
in 0 seconds
......@@ -21,6 +21,12 @@ if(MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
endif()
#silence duplicate symbol warnings on AIX
if(CMAKE_SYSTEM_NAME MATCHES "AIX")
if(NOT CMAKE_COMPILER_IS_GNUCXX)
......
clang-gnulike-support
---------------------
* The ``Clang`` compiler variant on Windows that targets the MSVC ABI
but has a GNU-like command line is now supported.
......@@ -12,6 +12,7 @@ set(CMAKE_C11_COMPILE_FEATURES "@CMAKE_C11_COMPILE_FEATURES@")
set(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@")
set(CMAKE_C_SIMULATE_ID "@CMAKE_C_SIMULATE_ID@")
set(CMAKE_C_COMPILER_FRONTEND_VARIANT "@CMAKE_C_COMPILER_FRONTEND_VARIANT@")
set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
@_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@
@SET_MSVC_C_ARCHITECTURE_ID@
......
......@@ -14,6 +14,7 @@ set(CMAKE_CXX20_COMPILE_FEATURES "@CMAKE_CXX20_COMPILE_FEATURES@")
set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "@CMAKE_CXX_COMPILER_FRONTEND_VARIANT@")
set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
@_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@
@SET_MSVC_CXX_ARCHITECTURE_ID@
......
......@@ -114,7 +114,6 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c)
CMAKE_DIAGNOSE_UNSUPPORTED_CLANG(C CC)
# Set old compiler and platform id variables.
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
......
......@@ -109,7 +109,6 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp)
CMAKE_DIAGNOSE_UNSUPPORTED_CLANG(CXX CXX)
# Set old compiler and platform id variables.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
......
......@@ -136,6 +136,31 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "")
endif()
set(_variant "")
if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang")
if(CMAKE_HOST_WIN32 AND "x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
else()
# Test whether an MSVC-like command-line option works.
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
RESULT_VARIABLE _clang_result
OUTPUT_VARIABLE _clang_stdout
ERROR_VARIABLE _clang_stderr)
if(_clang_result EQUAL 0)
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
else()
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
endif()
endif()
set(_variant " with ${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}-like command-line")
else()
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
endif()
else()
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "")
endif()
# Display the final identification result.
if(CMAKE_${lang}_COMPILER_ID)
if(CMAKE_${lang}_COMPILER_VERSION)
......@@ -149,9 +174,10 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(_archid "")
endif()
message(STATUS "The ${lang} compiler identification is "
"${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}")
"${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}${_variant}")
unset(_archid)
unset(_version)
unset(_variant)
else()
message(STATUS "The ${lang} compiler identification is unknown")
endif()
......@@ -163,6 +189,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
PARENT_SCOPE)
set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_WRAPPER "${CMAKE_${lang}_COMPILER_WRAPPER}" PARENT_SCOPE)
......@@ -864,38 +891,3 @@ function(CMAKE_DETERMINE_MSVC_SHOWINCLUDES_PREFIX lang userflags)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "" PARENT_SCOPE)
endif()
endfunction()
function(CMAKE_DIAGNOSE_UNSUPPORTED_CLANG lang envvar)
if(NOT CMAKE_HOST_WIN32 OR CMAKE_GENERATOR MATCHES "Visual Studio" OR
NOT "${CMAKE_${lang}_COMPILER_ID};${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "Clang;MSVC")
return()
endif()
# Test whether an MSVC-like command-line option works.
execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
RESULT_VARIABLE _clang_result
OUTPUT_VARIABLE _clang_stdout
ERROR_VARIABLE _clang_stderr)
if(_clang_result EQUAL 0)
return()
endif()
# Help the user configure the environment to use the MSVC-like Clang.
string(CONCAT _msg
"The Clang compiler tool\n"
" \"${CMAKE_${lang}_COMPILER}\"\n"
"targets the MSVC ABI but has a GNU-like command-line interface. "
"This is not supported. "
"Use 'clang-cl' instead, e.g. by setting '${envvar}=clang-cl' in the environment."
)
execute_process(COMMAND rc -help
RESULT_VARIABLE _rc_result
OUTPUT_VARIABLE _rc_stdout
ERROR_VARIABLE _rc_stderr)
if(NOT _rc_result EQUAL 0)
string(APPEND _msg " "
"Furthermore, use the MSVC command-line environment."
)
endif()
message(FATAL_ERROR "${_msg}")
endfunction()
......@@ -60,7 +60,9 @@ __resolve_tool_path(CMAKE_MT "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Manifes
set(_CMAKE_TOOL_VARS "")
# if it's the MS C/CXX compiler, search for link
if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC"
if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND
("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"
OR NOT "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang"))
OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC"
OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI")
OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xNVIDIA")
......@@ -80,17 +82,26 @@ else()
if(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN)
set(_CMAKE_TOOLCHAIN_LOCATION ${_CMAKE_TOOLCHAIN_LOCATION} ${CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN}/bin)
endif()
find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL Clang)
set(LLVM_OBJDUMP "llvm-objdump")
set(LLVM_LLD "ld.lld")
set(LLVM_RANLIB "llvm-ranlib")
set(LLVM_AR "llvm-ar")
endif()
find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${LLVM_AR} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${LLVM_RANLIB} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if(NOT CMAKE_RANLIB)
set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
endif()
find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${LLVM_LLD} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${LLVM_OBJDUMP} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
list(APPEND _CMAKE_TOOL_VARS CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
......
include(Compiler/Clang)
__compiler_clang(CXX)
if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
endif()
......@@ -10,7 +10,8 @@ if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
return()
endif()
if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 2.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
......@@ -56,6 +57,14 @@ if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
unset(_clang_version_std17)
if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
# This clang++ is missing some features because of MSVC compatibility.
unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)
unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT)
unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT)
endif()
__compiler_check_default_language_standard(CXX 2.1 98)
elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9
AND CMAKE_CXX_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0)
......
......@@ -8,13 +8,120 @@ if(__WINDOWS_CLANG)
endif()
set(__WINDOWS_CLANG 1)
macro(__windows_compiler_clang_gnu lang)
set(CMAKE_LIBRARY_PATH_FLAG "-L")
set(CMAKE_LINK_LIBRARY_FLAG "-l")
set(CMAKE_IMPORT_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
set(CMAKE_STATIC_LIBRARY_PREFIX "")
set(CMAKE_EXECUTABLE_SUFFIX ".exe")
set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <OBJECT> -MF <DEPFILE>")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a" ".lib")
set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1)
set (CMAKE_LINK_DEF_FILE_FLAG "-Xlinker /DEF:")
if("${CMAKE_${lang}_SIMULATE_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
endif()
# No -fPIC on Windows
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
# Create archiving rules to support large object file lists for static libraries.
set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
"<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <OBJECTS> <LINK_LIBRARIES>")
set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
set(CMAKE_${lang}_LINK_EXECUTABLE
"<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -Xclang -flto-visibility-public-std -D_MT -Xclang --dependent-lib=libcmt)
set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -D_DLL -D_MT -Xclang --dependent-lib=msvcrt)
set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -D_DEBUG -Xclang -flto-visibility-public-std -D_MT -Xclang --dependent-lib=libcmtd)
set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd)
if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)
set(__ADDED_FLAGS "")
set(__ADDED_FLAGS_DEBUG "")
else()
set(__ADDED_FLAGS_DEBUG "-D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd")
set(__ADDED_FLAGS "-D_DLL -D_MT -Xclang --dependent-lib=msvcrt")
endif()
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g -Xclang -gcodeview -O0 ${__ADDED_FLAGS_DEBUG}")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG ${__ADDED_FLAGS}")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG ${__ADDED_FLAGS}")
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG -Xclang -gcodeview ${__ADDED_FLAGS}")
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
unset(__ADDED_FLAGS)
unset(__ADDED_FLAGS_DEBUG)
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER)
set(CMAKE_${lang}_STANDARD_LIBRARIES_INIT "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames")
enable_language(RC)
endmacro()
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
include(Platform/Windows-MSVC)
macro(__windows_compiler_clang lang)
set(_COMPILE_${lang} "${_COMPILE_${lang}_MSVC}")
__windows_compiler_msvc(${lang})
endmacro()
if ( DEFINED CMAKE_C_COMPILER_ID AND DEFINED CMAKE_CXX_COMPILER_ID
AND NOT "x${CMAKE_C_COMPILER_ID}" STREQUAL "x${CMAKE_CXX_COMPILER_ID}")
message(FATAL_ERROR "The current configuration mixes Clang and MSVC or "
"some other CL compatible compiler tool. This is not supported. "
"Use either clang or MSVC as both C and C++ compilers.")
endif()
if ( DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT AND DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT
AND NOT "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
message(FATAL_ERROR "The current configuration uses the Clang compiler "
"tool with mixed frontend variants, both the GNU and in MSVC CL "
"like variants. This is not supported. Use either clang/clang++ "
"or clang-cl as both C and C++ compilers.")
endif()
if ( "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" )
include(Platform/Windows-MSVC)
macro(__windows_compiler_clang lang)
set(_COMPILE_${lang} "${_COMPILE_${lang}_MSVC}")
__windows_compiler_msvc(${lang})
endmacro()
else()
cmake_policy(GET CMP0091 __WINDOWS_CLANG_CMP0091)
if(__WINDOWS_CLANG_CMP0091 STREQUAL "NEW")
set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "")
endif()
unset(__WINDOWS_CLANG_CMP0091)
set(CMAKE_BUILD_TYPE_INIT Debug)
macro(__windows_compiler_clang lang)
__windows_compiler_clang_gnu(${lang})
endmacro()
endif()
else()
include(Platform/Windows-GNU)
macro(__windows_compiler_clang lang)
......
......@@ -639,13 +639,20 @@ void cmGlobalNinjaGenerator::EnableLanguage(
this->ResolveLanguageCompiler(l, mf, optional);
}
#ifdef _WIN32
if ((mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID") != "MSVC") &&
(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID") != "MSVC") &&
(mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "GNU") ||
(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") ||
(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") ||
(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang"))) {
const bool clangGnuMode =
((mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") &&
(mf->GetSafeDefinition("CMAKE_C_COMPILER_FRONTEND_VARIANT") == "GNU")) ||
((mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang") &&
(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_FRONTEND_VARIANT") == "GNU"));
if (clangGnuMode ||
((mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID") != "MSVC") &&
(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID") != "MSVC") &&
(mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "GNU") ||
(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") ||
(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") ||
(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang")))) {
this->UsingGCCOnWindows = true;
}
#endif
......
......@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 98)
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
endif()
add_library(foo SHARED empty.cpp)
......
......@@ -7,7 +7,7 @@ add_library(testc1 STATIC libc1.c)
add_library(testc2 SHARED libc2.c)
add_executable (COnly conly.c foo.c foo.h)
target_link_libraries(COnly testc1 testc2)
if(MSVC_VERSION)
if(MSVC_VERSION AND NOT CMAKE_C_COMPILER_ID STREQUAL Clang OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
set_target_properties(COnly PROPERTIES
LINK_FLAGS " /NODEFAULTLIB:\"libcdg.lib\" /NODEFAULTLIB:\"libcmtg.lib\" /NODEFAULTLIB:\"foomsvcrt.lib\" /NODEFAULTLIB:\"libbar.lib\" /NODEFAULTLIB:\"libfooba.lib\"")
endif()
......
......@@ -43,7 +43,7 @@ else()
)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero" AND NOT "${CMAKE_GENERATOR}" MATCHES "NMake Makefiles")
set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS
"-DTEST_OCTOTHORPE=\"#\""
)
......
......@@ -446,6 +446,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
set(CMAKE_CXX_STANDARD 11)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(CMAKE_CXX_STANDARD 14)
endif()
#
# Create the libs and the main exe
#
......
......@@ -403,6 +403,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
set(CMAKE_CXX_STANDARD 11)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(CMAKE_CXX_STANDARD 14)
endif()
#
# Create the libs and the main exe
#
......
......@@ -18,7 +18,12 @@ if(NOT CTEST_CONFIGURATION_TYPE)
endif()
endforeach()
if(NOT CTEST_CONFIGURATION_TYPE)
set(CTEST_CONFIGURATION_TYPE NoConfig)
if("@CMAKE_C_COMPILER_ID@;@CMAKE_C_SIMULATE_ID@;@CMAKE_C_COMPILER_FRONTEND_VARIANT@" STREQUAL "Clang;MSVC;GNU")
# A valid configuration is required for this compiler in tests that do not set CMP0091 to NEW.
set(CTEST_CONFIGURATION_TYPE Debug)
else()
set(CTEST_CONFIGURATION_TYPE NoConfig)
endif()
endif()
message("Guessing configuration ${CTEST_CONFIGURATION_TYPE}")
endif()
......
......@@ -133,7 +133,9 @@ endif()
# for msvc the compiler version determines which c++11 features are available.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" ))
if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
......
......@@ -5,6 +5,17 @@ project(Plugin)
# We need proper C++98 support from the compiler
set(CMAKE_CXX_STANDARD 98)
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
set(CMAKE_CXX_STANDARD 11)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(CMAKE_CXX_STANDARD 14)
endif()
# Test per-target output directory properties.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
......@@ -29,12 +40,6 @@ include_directories(
${Plugin_SOURCE_DIR}/include
)
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
set(CMAKE_CXX_STANDARD 11)
endif()
# Create an executable that exports an API for use by plugins.
add_executable(example_exe src/example_exe.cxx)
set_target_properties(example_exe PROPERTIES
......
......@@ -28,6 +28,11 @@ endif()
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
set(PP_VS 1)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
"x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" AND
"x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
set(CLANG_GNULIKE_WINDOWS 1)
endif()
# Some tests below check the PP_* variables set above. They are meant
# to test the case that the build tool is at fault. Other tests below
......@@ -53,7 +58,7 @@ endif()
string(APPEND STRING_EXTRA " ")
if(NOT PP_BORLAND AND NOT PP_WATCOM)
if(NOT PP_BORLAND AND NOT PP_WATCOM AND NOT CLANG_GNULIKE_WINDOWS)
# Borland, WMake: multiple spaces
# The make tool seems to remove extra whitespace from inside
# quoted strings when passing to the compiler. It does not have
......@@ -70,14 +75,14 @@ if(NOT PP_VS)
string(APPEND STRING_EXTRA ",")
endif()
if(NOT PP_MINGW)
if(NOT PP_MINGW AND NOT CLANG_GNULIKE_WINDOWS)
# MinGW: &
# When inside -D"FOO=\"a & b\"" MinGW make wants -D"FOO=\"a "&" b\""
# but it does not like quoted ampersand elsewhere.
string(APPEND STRING_EXTRA "&")
endif()
if(NOT PP_MINGW)
if(NOT PP_MINGW AND NOT CLANG_GNULIKE_WINDOWS)
# MinGW: |
# When inside -D"FOO=\"a | b\"" MinGW make wants -D"FOO=\"a "|" b\""
# but it does not like quoted pipe elsewhere.
......@@ -100,7 +105,8 @@ endif()
set(EXPR_OP1 "/")
if((NOT MSVC OR PP_NMAKE) AND
NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
NOT CMAKE_C_COMPILER_ID STREQUAL "Intel" AND
NOT CLANG_GNULIKE_WINDOWS)
# MSVC cl, Intel icl: %
# When the cl compiler is invoked from the command line then % must
# be written %% (to distinguish from %ENV% syntax). However cl does
......
......@@ -10,7 +10,8 @@ int check_defines_C(void)
{
int result = 1;
if (strcmp(FILE_STRING, STRING_VALUE) != 0) {
fprintf(stderr, "FILE_STRING has wrong value in C [%s]\n", FILE_STRING);
fprintf(stderr, "FILE_STRING has wrong value in C [%s] vs [%s]\n",
FILE_STRING, STRING_VALUE);
result = 0;
}
if (strcmp(TARGET_STRING, STRING_VALUE) != 0) {
......
......@@ -51,6 +51,11 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
set(CMAKE_CXX_STANDARD 11)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(CMAKE_CXX_STANDARD 14)
endif()
add_subdirectory(lib_shared_and_static)
if(CMAKE_SYSTEM_NAME MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
......
......@@ -6,4 +6,5 @@ __declspec(dllexport)
void greeting(void)
{
printf("Hello world!\n");
fflush(stdout);
}
......@@ -3,4 +3,5 @@
void greeting2(void)
{
printf("Hello world 2!\n");
fflush(stdout);
}
......@@ -5,7 +5,9 @@ cmake_policy(SET CMP0054 NEW)
set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
if (RunCMake_C_COMPILER_ID STREQUAL "MSVC"
OR ("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" AND
NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"))
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set (undef_flag /INCLUDE:_func)
else()
......
......@@ -5,7 +5,9 @@ cmake_policy(SET CMP0054 NEW)
set (lib_name "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lib${CMAKE_STATIC_LIBRARY_SUFFIX}")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
if (RunCMake_C_COMPILER_ID STREQUAL "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
if (RunCMake_C_COMPILER_ID STREQUAL "MSVC"
OR ("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" AND
NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"))
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
set (undef_flag /INCLUDE:_func)
else()
......
......@@ -7,8 +7,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
......
cmake_minimum_required(VERSION 3.3)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
endif()
......
......@@ -7,8 +7,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
......
......@@ -7,8 +7,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# the version number.
set(Tutorial_VERSION_MAJOR 1)
set(Tutorial_VERSION_MINOR 0)
......
......@@ -44,8 +44,7 @@ the following:
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# the version number.
set(Tutorial_VERSION_MAJOR 1)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 14)
# the version number.
set(Tutorial_VERSION_MAJOR 1)
......
cmake_minimum_required(VERSION 3.3)
project(Tutorial)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set