diff --git a/.github/workflows/generate_cmake_matrix.py b/.github/workflows/generate_cmake_matrix.py index 0fcbfd489..4a07b6a6d 100644 --- a/.github/workflows/generate_cmake_matrix.py +++ b/.github/workflows/generate_cmake_matrix.py @@ -11,10 +11,14 @@ "toolchain": ["llvm", "gcc"], "arch_flags": ["-march=native", "-march=x86-64", "native"] }, - "windows-2022": { - "toolchain": ["msvc", "llvm"], + "windows-2022-msvc": { + "toolchain": ["msvc"], "arch_flags": ["/arch:AVX2", "/arch:SSE2", "native"] }, + "windows-2022-llvm": { + "toolchain": ["msvc"], + "arch_flags": ["-march=native", "-march=x86-64", "native"] + }, "macos-13": { "toolchain": ["llvm", "gcc-14"], "arch_flags": ["-march=native", "-march=x86-64", "native"] diff --git a/CMakeLists.txt b/CMakeLists.txt index ee9e3ef27..97c83806d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ set(FINUFFT_FFTW_SUFFIX "OpenMP" CACHE STRING "Suffix for FFTW libraries (e.g. O # if FINUFFT_USE_CUDA is OFF, the following options are ignored set(FINUFFT_CUDA_ARCHITECTURES "native" CACHE STRING "CUDA architectures to build for (e.g. 60;70;75;)") # if FINUFFT_USE_CPU is OFF, the following options are ignored -set(FINUFFT_ARCH_FLAGS native CACHE STRING "Compiler flags for specifying target architecture, defaults to -march=native") +set(FINUFFT_ARCH_FLAGS "native" CACHE STRING "Compiler flags for specifying target architecture, defaults to -march=native") # sphinx tag (don't remove): @cmake_opts_end cmake_dependent_option(FINUFFT_ENABLE_INSTALL "Disable installation in the case of python builds" OFF "FINUFFT_BUILD_PYTHON" OFF) cmake_dependent_option(FINUFFT_STATIC_LINKING "Disable static libraries in the case of python builds" ON "NOT FINUFFT_BUILD_PYTHON" OFF) @@ -77,10 +77,10 @@ message( STATUS "FINUFFT RelWithDebInfo flags: ${FINUFFT_CXX_FLAGS_RELWITHDEBINFO}") if(FINUFFT_ARCH_FLAGS STREQUAL "native") - set(FINUFFT_ARCH_FLAGS -march=native) + set(FINUFFT_ARCH_FLAGS CACHE STRING -march=native FORCE) filter_supported_compiler_flags(FINUFFT_ARCH_FLAGS FINUFFT_ARCH_FLAGS) if(NOT FINUFFT_ARCH_FLAGS) - set(FINUFFT_ARCH_FLAGS -mtune=native) + set(FINUFFT_ARCH_FLAGS CACHE STRING -mtune=native FORCE) filter_supported_compiler_flags(FINUFFT_ARCH_FLAGS FINUFFT_ARCH_FLAGS) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -172,15 +172,7 @@ function(finufft_link_test target) set_target_properties( ${target} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - if(WIN32) - # copy the .dll file to the same folder as the executable on windows make we - # should provide a helper cmake function for the users to use - add_custom_command( - TARGET ${target} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory $ - $) - endif() + copy_dll(finufft ${target}) endfunction() # Utility function to set finufft compilation options. diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 909cbfaf7..4dbf1e03b 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -40,20 +40,47 @@ function(check_arch_support) if(RUN_OUTPUT MATCHES "AVX512") set(FINUFFT_ARCH_FLAGS "/arch:AVX512" - CACHE STRING "Compiler flags for specifying target architecture.") + CACHE STRING FORCE) elseif(RUN_OUTPUT MATCHES "AVX") set(FINUFFT_ARCH_FLAGS "/arch:AVX" - CACHE STRING "Compiler flags for specifying target architecture.") + CACHE STRING FORCE) elseif(RUN_OUTPUT MATCHES "SSE") set(FINUFFT_ARCH_FLAGS "/arch:SSE" - CACHE STRING "Compiler flags for specifying target architecture.") + CACHE STRING FORCE) else() set(FINUFFT_ARCH_FLAGS "" - CACHE STRING "Compiler flags for specifying target architecture.") + CACHE STRING FORCE) endif() message(STATUS "CPU supports: ${RUN_OUTPUT}") message(STATUS "Using MSVC flags: ${FINUFFT_ARCH_FLAGS}") endfunction() + +function(copy_dll source_target destination_target) + if(NOT WIN32) + return() + endif() + # Get the binary directory of the destination target + get_target_property(DESTINATION_DIR ${destination_target} BINARY_DIR) + set(DESTINATION_FILE ${DESTINATION_DIR}/$) + if(NOT EXISTS ${DESTINATION_FILE}) + message( + STATUS + "Copying ${source_target} to ${DESTINATION_DIR} directory for ${destination_target}" + ) + # Define the custom command to copy the source target to the destination + # directory + add_custom_command( + TARGET ${destination_target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ + ${DESTINATION_FILE} + COMMENT "Copying ${source_target} to ${destination_target} directory") + endif() + # Unset the variables to leave a clean state + unset(DESTINATION_DIR) + unset(SOURCE_FILE) + unset(DESTINATION_FILE) +endfunction()