[CLANG-CL] Initial commit that allows us to compile ReactOS with clang-cl.

This commit is contained in:
Amine Khaldi 2017-10-27 22:18:01 +01:00
parent 861360c65f
commit 09c06a2f45
18 changed files with 91 additions and 50 deletions

View file

@ -193,8 +193,13 @@ else()
endif()
if (CMAKE_COMPILER_SUPPORTS_PDBTYPE)
set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept")
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
if(NOT USE_CLANG_CL)
set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug /pdbtype:sept")
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug /pdbtype:sept ${MSVC_INCREMENTAL_YES_FLAG}")
else()
set(CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug")
endif()
else ()
set (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "/debug")
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "/debug ${MSVC_INCREMENTAL_YES_FLAG}")

View file

@ -36,7 +36,7 @@ else()
"Whether to compile for debugging.")
endif()
if(MSVC)
if(MSVC AND (NOT USE_CLANG_CL))
set(KDBG FALSE CACHE BOOL
"Whether to compile in the integrated kernel debugger.")
if(CMAKE_BUILD_TYPE STREQUAL "Release")

View file

@ -23,6 +23,11 @@ foreach(_host_tool ${host_tools_list})
add_dependencies(native-${_host_tool} host-tools)
endforeach()
if(USE_CLANG_CL)
# FIXME: Fix host tools build with clang
#set(USE_CLANG_CL_ARG "-DCMAKE_C_COMPILER=clang-cl;-DCMAKE_CXX_COMPILER=clang-cl")
endif()
include(ExternalProject)
ExternalProject_Add(host-tools
@ -32,6 +37,6 @@ ExternalProject_Add(host-tools
BUILD_ALWAYS 1
PREFIX host-tools
EXCLUDE_FROM_ALL 1
CMAKE_ARGS "-DNEW_STYLE_BUILD=1;-DARCH:STRING=${ARCH}"
CMAKE_ARGS "-DNEW_STYLE_BUILD=1;-DARCH:STRING=${ARCH};${USE_CLANG_CL_ARG}"
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${tools_binaries})

View file

@ -29,7 +29,15 @@ endif()
add_definitions(/Dinline=__inline /D__STDC__=1)
add_compile_flags("/X /GR- /EHs-c- /GS- /Zl /W3")
if(NOT USE_CLANG_CL)
add_compile_flags("/X /Zl")
endif()
add_compile_flags("/GR- /EHs-c- /GS- /W3")
if(USE_CLANG_CL)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file: ")
endif()
# HACK: for VS 11+ we need to explicitly disable SSE, which is off by
# default for older compilers. See CORE-6507
@ -88,6 +96,11 @@ endif()
# - C4115: named type definition in parentheses
add_compile_flags("/w14115")
if(USE_CLANG_CL)
add_compile_flags_language("-nostdinc -Wno-multichar -Wno-char-subscripts -Wno-microsoft-enum-forward-reference -Wno-pragma-pack -Wno-microsoft-anon-tag -Wno-unknown-pragmas" "C")
add_compile_flags_language("-nostdinc -Wno-multichar -Wno-char-subscripts -Wno-microsoft-enum-forward-reference -Wno-pragma-pack -Wno-microsoft-anon-tag -Wno-unknown-pragmas" "CXX")
endif()
# Debugging
#if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
@ -101,7 +114,9 @@ endif()
# Hotpatchable images
if(ARCH STREQUAL "i386")
add_compile_flags("/hotpatch")
if(NOT USE_CLANG_CL)
add_compile_flags("/hotpatch")
endif()
set(_hotpatch_link_flag "/FUNCTIONPADMIN:5")
elseif(ARCH STREQUAL "amd64")
set(_hotpatch_link_flag "/FUNCTIONPADMIN:6")
@ -135,7 +150,8 @@ if(MSVC_IDE AND (CMAKE_VERSION MATCHES "ReactOS"))
add_definitions(/DLANGUAGE_EN_US)
else()
# Only VS 10+ resource compiler supports /nologo
if(MSVC_VERSION GREATER 1599)
# CMAKE_CXX_SIMULATE_VERSION is a similar check for our clang-cl builds
if((MSVC_VERSION GREATER 1599) OR (CMAKE_CXX_SIMULATE_VERSION VERSION_GREATER 15.99))
set(rc_nologo_flag "/nologo")
else()
set(rc_nologo_flag)
@ -218,12 +234,18 @@ if(PCH)
set(_pch_path_name_flag "/Fp${_gch}")
endif()
if(USE_CLANG_CL)
set(_pch_compile_flags "${_cl_lang_flag} /Yc${_pch} /FI${_pch} /Fp${_gch}")
else()
set(_pch_compile_flags "${_cl_lang_flag} /Yc /Fp${_gch}")
endif()
# Build the precompiled header
# HEADER_FILE_ONLY FALSE: force compiling the header
set_source_files_properties(${_pch} PROPERTIES
HEADER_FILE_ONLY FALSE
LANGUAGE ${_pch_language}
COMPILE_FLAGS "${_cl_lang_flag} /Yc /Fp${_gch}"
COMPILE_FLAGS ${_pch_compile_flags}
OBJECT_OUTPUTS ${_gch})
# Prevent a race condition related to writing to the PDB files between the PCH and the excluded list of source files