From 95337da55839743bbc831a302235de34beca9bf4 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Sat, 8 Oct 2022 23:26:41 -0700 Subject: [PATCH] [build] Add basic clang-cl support XAudio2 is disabled because the included header needs to be updated to be parseable by clang. --- CMakeLists.txt | 11 +++++++++-- cmake/Set-Toolchain-vcpkg.cmake | 2 +- cmake/SetCompilerLinkerFlags.cmake | 2 +- fex/7z_C/CpuArch.c | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 733df46c..a46bfadf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,6 +250,12 @@ if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() +if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) + # TODO: We should update the XAudio headers to build with clang-cl. See + # https://github.com/visualboyadvance-m/visualboyadvance-m/issues/1021 + add_definitions(-DNO_XAUDIO2) +endif() + option(ENABLE_GBA_LOGGING "Enable extended GBA logging" ON) if(ENABLE_GBA_LOGGING) add_definitions(-DGBA_LOGGING ) @@ -561,11 +567,12 @@ option(UPSTREAM_RELEASE "do some optimizations and release automation tasks" OFF include(SetCompilerLinkerFlags) -if(CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang) +if(CMAKE_C_COMPILER_ID STREQUAL Clang AND CMAKE_CXX_COMPILER_ID STREQUAL Clang AND NOT MSVC) + # TODO: This should also be done for clang-cl. include(LLVMToolchain) endif() -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang AND NOT MSVC) unset(LTO_FLAGS) if(ENABLE_LTO) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index f2c03e1a..181a7f1a 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -290,7 +290,7 @@ function(vcpkg_set_toolchain) set(CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE) endif() - if(WIN32 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio") + if(WIN32 AND NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT DEFINED CMAKE_CXX_COMPILER) if(VCPKG_TARGET_TRIPLET MATCHES "^x[68][46]-windows-") # set toolchain to VS for e.g. Ninja or jom set(CMAKE_C_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE) diff --git a/cmake/SetCompilerLinkerFlags.cmake b/cmake/SetCompilerLinkerFlags.cmake index 1cf291bf..c923031b 100644 --- a/cmake/SetCompilerLinkerFlags.cmake +++ b/cmake/SetCompilerLinkerFlags.cmake @@ -27,7 +27,7 @@ endfunction() function(add_linker_flags) # Set linker flags if not already set. foreach(flag ${ARGV}) - foreach(var EXE SHARED MODULE STATIC) + foreach(var EXE SHARED) set(var "CMAKE_${var}_LINKER_FLAGS") # Remove any duplicates first. diff --git a/fex/7z_C/CpuArch.c b/fex/7z_C/CpuArch.c index 8433e84b..fe0fa836 100644 --- a/fex/7z_C/CpuArch.c +++ b/fex/7z_C/CpuArch.c @@ -5,7 +5,7 @@ #ifdef MY_CPU_X86_OR_AMD64 -#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__) +#if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__) || defined(__clang__) #define USE_ASM #endif