https://git.reactos.org/?p=reactos.git;a=commitdiff;h=09c06a2f457ec9557bcdf1...
commit 09c06a2f457ec9557bcdf1809ecb4b50b2fb654a Author: Amine Khaldi amine.khaldi@reactos.org AuthorDate: Fri Oct 27 22:18:01 2017 +0100
[CLANG-CL] Initial commit that allows us to compile ReactOS with clang-cl. --- CMakeLists.txt | 10 ++++++++-- base/setup/usetup/CMakeLists.txt | 5 ----- boot/freeldr/freeldr/CMakeLists.txt | 5 +++++ configure.cmd | 7 +++++-- dll/win32/CMakeLists.txt | 4 +++- dll/win32/browseui/CMakeLists.txt | 5 +---- dll/win32/browseui/shellbars/CMakeLists.txt | 4 +--- dll/win32/riched20/CMakeLists.txt | 5 ----- dll/win32/winmm/CMakeLists.txt | 2 +- drivers/filesystems/ext2/CMakeLists.txt | 15 +++++++++++---- ntoskrnl/ntos.cmake | 9 --------- sdk/cmake/Platform/Windows-MSVC.cmake | 9 +++++++-- sdk/cmake/config.cmake | 2 +- sdk/cmake/host-tools.cmake | 7 ++++++- sdk/cmake/msvc.cmake | 30 +++++++++++++++++++++++++---- sdk/lib/crt/crt.cmake | 7 ++++--- subsystems/mvdm/asm16.cmake | 3 ++- toolchain-msvc.cmake | 12 ++++++++++-- 18 files changed, 91 insertions(+), 50 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt index f4c38c85f8..bcf4c18d30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/base/setup/usetup/CMakeLists.txt b/base/setup/usetup/CMakeLists.txt index d78f9d7bf7..d90103f16a 100644 --- a/base/setup/usetup/CMakeLists.txt +++ b/base/setup/usetup/CMakeLists.txt @@ -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) diff --git a/boot/freeldr/freeldr/CMakeLists.txt b/boot/freeldr/freeldr/CMakeLists.txt index c4ca5b4a33..df7cc0a53b 100644 --- a/boot/freeldr/freeldr/CMakeLists.txt +++ b/boot/freeldr/freeldr/CMakeLists.txt @@ -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) diff --git a/configure.cmd b/configure.cmd index 6b0c5dfbb9..922a8f1d94 100755 --- a/configure.cmd +++ b/configure.cmd @@ -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%" ) diff --git a/dll/win32/CMakeLists.txt b/dll/win32/CMakeLists.txt index c0a16ad1d8..e4639acf65 100644 --- a/dll/win32/CMakeLists.txt +++ b/dll/win32/CMakeLists.txt @@ -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) diff --git a/dll/win32/browseui/CMakeLists.txt b/dll/win32/browseui/CMakeLists.txt index 30ab6a2969..45afa685c4 100644 --- a/dll/win32/browseui/CMakeLists.txt +++ b/dll/win32/browseui/CMakeLists.txt @@ -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") diff --git a/dll/win32/browseui/shellbars/CMakeLists.txt b/dll/win32/browseui/shellbars/CMakeLists.txt index 28c55176b5..f42c74f722 100644 --- a/dll/win32/browseui/shellbars/CMakeLists.txt +++ b/dll/win32/browseui/shellbars/CMakeLists.txt @@ -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() diff --git a/dll/win32/riched20/CMakeLists.txt b/dll/win32/riched20/CMakeLists.txt index b0cf90e428..002fc5ad9b 100644 --- a/dll/win32/riched20/CMakeLists.txt +++ b/dll/win32/riched20/CMakeLists.txt @@ -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) diff --git a/dll/win32/winmm/CMakeLists.txt b/dll/win32/winmm/CMakeLists.txt index c82fda5822..eb3cbecbbe 100644 --- a/dll/win32/winmm/CMakeLists.txt +++ b/dll/win32/winmm/CMakeLists.txt @@ -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()
diff --git a/drivers/filesystems/ext2/CMakeLists.txt b/drivers/filesystems/ext2/CMakeLists.txt index abc1c2489d..66278740f2 100644 --- a/drivers/filesystems/ext2/CMakeLists.txt +++ b/drivers/filesystems/ext2/CMakeLists.txt @@ -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) diff --git a/ntoskrnl/ntos.cmake b/ntoskrnl/ntos.cmake index 9affb1e68a..ceb287656a 100644 --- a/ntoskrnl/ntos.cmake +++ b/ntoskrnl/ntos.cmake @@ -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() diff --git a/sdk/cmake/Platform/Windows-MSVC.cmake b/sdk/cmake/Platform/Windows-MSVC.cmake index dc09c7479f..5c3912cfea 100644 --- a/sdk/cmake/Platform/Windows-MSVC.cmake +++ b/sdk/cmake/Platform/Windows-MSVC.cmake @@ -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}") diff --git a/sdk/cmake/config.cmake b/sdk/cmake/config.cmake index 1374cab3ba..3fc9ce212e 100644 --- a/sdk/cmake/config.cmake +++ b/sdk/cmake/config.cmake @@ -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") diff --git a/sdk/cmake/host-tools.cmake b/sdk/cmake/host-tools.cmake index 40c4eb1735..100df6fd52 100644 --- a/sdk/cmake/host-tools.cmake +++ b/sdk/cmake/host-tools.cmake @@ -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}) diff --git a/sdk/cmake/msvc.cmake b/sdk/cmake/msvc.cmake index 4705b3cae9..19790ed91c 100644 --- a/sdk/cmake/msvc.cmake +++ b/sdk/cmake/msvc.cmake @@ -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 diff --git a/sdk/lib/crt/crt.cmake b/sdk/lib/crt/crt.cmake index 8de8a67063..66c5b52e1d 100644 --- a/sdk/lib/crt/crt.cmake +++ b/sdk/lib/crt/crt.cmake @@ -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}) diff --git a/subsystems/mvdm/asm16.cmake b/subsystems/mvdm/asm16.cmake index eb6d05dfcd..c25f676c73 100644 --- a/subsystems/mvdm/asm16.cmake +++ b/subsystems/mvdm/asm16.cmake @@ -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( diff --git a/toolchain-msvc.cmake b/toolchain-msvc.cmake index e0f2b2b8b3..6028e61493 100644 --- a/toolchain-msvc.cmake +++ b/toolchain-msvc.cmake @@ -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)