[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

@ -97,7 +97,10 @@ if(NOT CMAKE_CROSSCOMPILING)
if(MSVC_VERSION GREATER 1699)
add_definitions(/D_ALLOW_KEYWORD_MACROS)
endif()
add_definitions(/Dinline=__inline)
if(NOT USE_CLANG_CL)
# FIXME: Inspect
add_definitions(/Dinline=__inline)
endif()
endif()
include_directories(sdk/include/host)
@ -182,7 +185,10 @@ else()
# Arch Options
if(ARCH STREQUAL "i386")
add_definitions(-D_M_IX86 -D_X86_ -D__i386__ -Di386)
if(NOT USE_CLANG_CL)
add_definitions(-D_M_IX86)
endif()
add_definitions(-D_X86_ -D__i386__ -Di386)
elseif(ARCH STREQUAL "amd64")
add_definitions(-D_M_AMD64 -D_AMD64_ -D__x86_64__ -D_WIN64)
elseif(ARCH STREQUAL "arm")

View file

@ -34,11 +34,6 @@ list(APPEND SOURCE
settings.c
usetup.h)
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
#FIXME: Investigate Clang "illegal character encoding in string literal" warning
set_property(SOURCE mui.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-invalid-source-encoding")
endif()
add_executable(usetup ${SOURCE} usetup.rc)
target_link_libraries(usetup zlib inflib ext2lib vfatlib)
set_module_type(usetup nativecui)

View file

@ -198,6 +198,11 @@ add_library(freeldr_common ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON
add_pch(freeldr_common include/freeldr.h FREELDR_COMMON_SOURCE)
add_dependencies(freeldr_common bugcodes asm xdk)
if(USE_CLANG_CL)
# We need to reduce the binary size
set_property(SOURCE ${FREELDR_BOOTLIB_COMMON_SOURCE} ${FREELDR_ARC_COMMON_SOURCE} APPEND_STRING PROPERTY COMPILE_FLAGS " /Os")
endif()
if(ARCH STREQUAL "i386" AND NOT MSVC)
list(APPEND FREELDR_BASE_SOURCE arch/i386/multiboot.S)
target_link_libraries(freeldr_common mini_hal)

View file

@ -83,6 +83,7 @@ if not defined ARCH (
)
set NEW_STYLE_BUILD=1
set USE_CLANG_CL=0
REM Parse command line parameters
:repeat
@ -95,8 +96,6 @@ REM Parse command line parameters
set CMAKE_GENERATOR="Eclipse CDT4 - MinGW Makefiles"
) else if /I "%1" == "Makefiles" (
set CMAKE_GENERATOR="MinGW Makefiles"
) else if /I "%1" == "clang" (
set MINGW_TOOCHAIN_FILE=toolchain-clang.cmake
) else (
goto continue
)
@ -107,6 +106,8 @@ REM Parse command line parameters
set CMAKE_GENERATOR="Eclipse CDT4 - NMake Makefiles"
) else if /I "%1" == "Makefiles" (
set CMAKE_GENERATOR="NMake Makefiles"
) else if /I "%1" == "clang" (
set USE_CLANG_CL=1
) else if /I "%1" == "VSSolution" (
set VS_SOLUTION=1
REM explicitly set VS version for project generator
@ -239,6 +240,8 @@ if "%NEW_STYLE_BUILD%"=="0" (
if "%BUILD_ENVIRONMENT%" == "MinGW" (
cmake -G %CMAKE_GENERATOR% -DENABLE_CCACHE:BOOL=0 -DCMAKE_TOOLCHAIN_FILE:FILEPATH=%MINGW_TOOCHAIN_FILE% -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% %* "%REACTOS_SOURCE_DIR%"
) else if %USE_CLANG_CL% == 1 (
cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DUSE_CLANG_CL:BOOL=1 -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
) else (
cmake -G %CMAKE_GENERATOR% -DCMAKE_TOOLCHAIN_FILE:FILEPATH=toolchain-msvc.cmake -DARCH:STRING=%ARCH% %BUILD_TOOLS_FLAG% -DRUNTIME_CHECKS:BOOL=%VS_RUNTIME_CHECKS% %* "%REACTOS_SOURCE_DIR%"
)

View file

@ -42,7 +42,9 @@ add_subdirectory(faultrep)
add_subdirectory(fltlib)
add_subdirectory(fmifs)
add_subdirectory(fontsub)
add_subdirectory(framedyn)
if(NOT USE_CLANG_CL)
add_subdirectory(framedyn)
endif()
add_subdirectory(fusion)
add_subdirectory(gdiplus)
add_subdirectory(getuname)

View file

@ -45,10 +45,7 @@ add_pch(browseui precomp.h SOURCE)
add_cd_file(TARGET browseui DESTINATION reactos/system32 FOR all)
if(NOT MSVC)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_target_compile_flags(browseui "-Wno-unused-but-set-variable")
endif()
add_target_compile_flags(browseui "-Wno-unused-but-set-variable")
# Binutils linker bug
if(LTCG)
add_target_link_flags(browseui "-Wl,--allow-multiple-definition")

View file

@ -20,7 +20,5 @@ add_dependencies(shellbars xdk)
target_link_libraries(shellbars atlnew)
if(NOT MSVC)
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_target_compile_flags(shellbars "-Wno-unused-but-set-variable")
endif()
add_target_compile_flags(shellbars "-Wno-unused-but-set-variable")
endif()

View file

@ -33,11 +33,6 @@ else()
list(APPEND SOURCE txthost.c txtsrv.c)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
#FIXME: http://llvm.org/bugs/show_bug.cgi?id=19027
set_property(SOURCE txthost.c txtsrv.c APPEND_STRING PROPERTY COMPILE_FLAGS " -no-integrated-as")
endif()
list(APPEND ADDITIONAL_SOURCE
version.rc
${CMAKE_CURRENT_BINARY_DIR}/riched20.def)

View file

@ -27,7 +27,7 @@ add_importlibs(winmm advapi32 user32 msvcrt kernel32 ntdll)
add_pch(winmm winemm.h SOURCE)
add_cd_file(TARGET winmm DESTINATION reactos/system32 FOR all)
if((NOT MSVC) AND (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang"))
if(NOT MSVC)
add_target_compile_flags(winmm "-Wno-unused-but-set-variable")
endif()

View file

@ -88,11 +88,13 @@ list(APPEND SOURCE
add_library(ext2fs SHARED ${SOURCE} ext2fs.rc)
if(USE_CLANG_CL)
set_property(SOURCE src/create.c src/fileinfo.c src/memory.c src/read.c APPEND_STRING PROPERTY COMPILE_FLAGS " /fallback")
endif()
if(NOT MSVC)
add_target_compile_flags(ext2fs "-Wno-pointer-sign -Wno-unused-function")
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_target_compile_flags(ext2fs "-Wno-unused-but-set-variable -Wno-unused-variable -Wno-missing-braces")
endif()
add_target_compile_flags(ext2fs "-Wno-unused-but-set-variable -Wno-unused-variable -Wno-missing-braces")
else()
#disable warnings: "unreferenced local variable", "initialized, but not used variable", "benign include"
replace_compile_flags("/we\"4189\"" " ")
@ -103,5 +105,10 @@ target_link_libraries(ext2fs memcmp ${PSEH_LIB})
add_definitions(-D__KERNEL__)
set_module_type(ext2fs kernelmodedriver)
add_importlibs(ext2fs ntoskrnl hal)
add_pch(ext2fs inc/ext2fs.h SOURCE)
if(NOT USE_CLANG_CL)
# The fallback we have above prevents cl and clang-cl from using the same PCH
add_pch(ext2fs inc/ext2fs.h SOURCE)
endif()
add_cd_file(TARGET ext2fs DESTINATION reactos/system32/drivers NO_CAB FOR all)

View file

@ -426,12 +426,3 @@ else() # _WINKD_
endif()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
#FIXME: http://llvm.org/bugs/show_bug.cgi?id=19027
set_property(SOURCE
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/i386/cpu.c
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/i386/kiinit.c
${REACTOS_SOURCE_DIR}/ntoskrnl/ke/i386/traphdlr.c
APPEND_STRING PROPERTY COMPILE_FLAGS " -no-integrated-as")
endif()

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

View file

@ -581,9 +581,10 @@ endif()
set_source_files_properties(${CRT_ASM_SOURCE} PROPERTIES COMPILE_DEFINITIONS "__MINGW_IMPORT=extern;USE_MSVCRT_PREFIX;_MSVCRT_LIB_;_MSVCRT_;_MT;CRTDLL")
add_asm_files(crt_asm ${CRT_ASM_SOURCE})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
#FIXME: http://llvm.org/bugs/show_bug.cgi?id=19027
set_property(SOURCE except/cpp.c APPEND_STRING PROPERTY COMPILE_FLAGS " -no-integrated-as")
if(USE_CLANG_CL)
# clang-cl is missing pragma function support
# https://bugs.llvm.org/show_bug.cgi?id=35116
set_property(SOURCE stdlib/rot.c APPEND_STRING PROPERTY COMPILE_FLAGS " /fallback")
endif()
add_library(crt ${CRT_SOURCE} ${crt_asm})

View file

@ -107,9 +107,10 @@ function(add_asm16_bin _target _binary_file _base_address)
set(_pp_asm16_compile_command ${CMAKE_ASM16_COMPILER} /nologo /Cp /Fo${_object_file} /c /Ta ${_preprocessed_asm_file})
endif()
# FIXME: clang-cl can't compile this so use cl here instead of ${CMAKE_C_COMPILER} in the meantime
add_custom_command(
OUTPUT ${_preprocessed_asm_file} ${_object_file}
COMMAND ${CMAKE_C_COMPILER} /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_concatenated_asm_file} > ${_preprocessed_asm_file} && ${_pp_asm16_compile_command}
COMMAND cl /nologo /X /I${REACTOS_SOURCE_DIR}/sdk/include/asm /I${REACTOS_BINARY_DIR}/sdk/include/asm ${_directory_includes} ${_source_file_defines} ${_directory_defines} /D__ASM__ /D_USE_ML /EP /c ${_concatenated_asm_file} > ${_preprocessed_asm_file} && ${_pp_asm16_compile_command}
DEPENDS ${_concatenated_asm_file})
add_custom_command(

View file

@ -14,13 +14,21 @@ set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER cl)
if(USE_CLANG_CL)
set(CMAKE_C_COMPILER clang-cl)
else()
set(CMAKE_C_COMPILER cl)
endif()
if(ARCH STREQUAL "arm")
include(CMakeForceCompiler)
CMAKE_FORCE_CXX_COMPILER(cl MSVC)
else()
set(CMAKE_CXX_COMPILER cl)
if(USE_CLANG_CL)
set(CMAKE_CXX_COMPILER clang-cl)
else()
set(CMAKE_CXX_COMPILER cl)
endif()
endif()
set(CMAKE_MC_COMPILER mc)