diff --git a/CMakeLists.txt b/CMakeLists.txt index a6b9965..76d558a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,12 @@ cmake_minimum_required(VERSION 3.18) + +if(MSVC AND ENV{CC} MATCHES ".*clang-cl.*") + set(CMAKE_GENERATOR_TOOLSET "ClangCL") + set(CLANG_CL TRUE) +else() + set(CLANG_CL FALSE) +endif() + include(tools/CompilerWarnings.cmake) include(tools/CPUFeatures.cmake) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/pyproject.toml b/pyproject.toml index 17b0119..ae50961 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ archs = ["auto64"] # arm64 windows builds not yet supported test-command = "cd /d {project} && python -m unittest --verbose" # windows why is this flag required # MSVC compiled wheels will just have to be serial ops until distutil supports clang-cl # https://github.com/python/cpython/pull/18371 -environment = { CXX = "clang-cl.exe", CC = "clang-cl.exe" } +environment = { QUICKTEX_HWY_MODE = "SSE4", CXX = "clang-cl.exe", CC = "clang-cl.exe" } [tool.cibuildwheel.linux] skip = ["cp37-musllinux*", "*musllinux_aarch64*"] # skip targets without available Pillow wheels diff --git a/setup.py b/setup.py index 5bf8686..7ff4698 100644 --- a/setup.py +++ b/setup.py @@ -66,8 +66,8 @@ class CMakeBuild(build_ext): cmake_args += ["-GNinja"] else: - if 'CC' in os.environ and 'clang-cl' in os.environ['CC']: - cmake_args += ["-T", 'ClangCL'] # https://stackoverflow.com/a/64189112/7645957 + # if 'CC' in os.environ and 'clang-cl' in os.environ['CC']: + # cmake_args += ["-T", 'ClangCL'] # https://stackoverflow.com/a/64189112/7645957 # Single config generators are handled "normally" single_config = any(x in cmake_generator for x in {"NMake", "Ninja"}) diff --git a/tools/CPUFeatures.cmake b/tools/CPUFeatures.cmake index 2ee4425..00e364b 100644 --- a/tools/CPUFeatures.cmake +++ b/tools/CPUFeatures.cmake @@ -42,20 +42,32 @@ function(set_simd_flags target_name) if (highway_mode STREQUAL "AUTO") # setting -march=native on an M1 causes Clang to freak out if (MSVC) - #MSVC has no -march=native equivalent. womp - message(WARNING "Compiling using MSVC without settig an explicit QUICKTEX_HWY_MODE defaults to serial operations. Please compile with Clang if you need vectorization") + if (CLANG_CL) + target_compile_options(${target_name} PUBLIC /clang:-march=native) + else() + #MSVC has no -march=native equivalent. womp + message(WARNING "Compiling using cl.exe without settig an explicit QUICKTEX_HWY_MODE defaults to serial operations. Please compile with clang-cl if you need vectorization") + endif() elseif (!ARM) target_compile_options(${target_name} PUBLIC -march=native) endif () elseif (highway_mode STREQUAL "SSSE3") if (MSVC) - message(SEND_ERROR "Compiling using SSSE3 is not supported with the MSVC compiler. Please use AVX or compile withClang") + if (CLANG_CL) + target_compile_options(${target_name} PUBLIC /clang:-mssse3) + else() + message(SEND_ERROR "Compiling using SSSE3 is not supported with the cl.exe compiler. Please use AVX or compile with clang-cl") + endif() else () target_compile_options(${target_name} PUBLIC -mssse3) endif () elseif (highway_mode STREQUAL "SSE4") if (MSVC) - message(SEND_ERROR "Compiling using SSE4 is not supported with the MSVC compiler. Please use AVX or compile with Clang") + if (CLANG_CL) + target_compile_options(${target_name} PUBLIC /clang:-msse4) + else() + message(SEND_ERROR "Compiling using SSE4 is not supported with the MSVC compiler. Please use AVX or compile with Clang") + endif() else () target_compile_options(${target_name} PUBLIC -msse4) endif ()