|
| 1 | +include(CheckCXXCompilerFlag) |
| 2 | +# Define the function |
| 3 | +function(filter_supported_compiler_flags input_flags_var output_flags_var) |
| 4 | + # Create an empty list to store supported flags |
| 5 | + set(supported_flags) |
| 6 | + |
| 7 | + # Iterate over each flag in the input list |
| 8 | + foreach(flag ${${input_flags_var}}) |
| 9 | + string(REPLACE "=" "_" flag_var ${flag}) # Convert flag to a valid variable |
| 10 | + # name |
| 11 | + string(REPLACE "-" "" flag_var ${flag_var}) # Remove '-' for the variable |
| 12 | + # name |
| 13 | + |
| 14 | + # Append the test linker flag to the existing flags |
| 15 | + list(APPEND CMAKE_EXE_LINKER_FLAGS ${flag}) |
| 16 | + check_cxx_compiler_flag(${flag} ${flag_var}) |
| 17 | + if(${flag_var}) |
| 18 | + # If supported, append the flag to the list of supported flags |
| 19 | + list(APPEND supported_flags ${flag}) |
| 20 | + else() |
| 21 | + message(STATUS "Flag ${flag} is not supported") |
| 22 | + endif() |
| 23 | + unset(${flag_var} CACHE) |
| 24 | + # remove last flag from linker flags |
| 25 | + list(REMOVE_ITEM CMAKE_EXE_LINKER_FLAGS ${flag}) |
| 26 | + endforeach() |
| 27 | + # Set the output variable to the list of supported flags |
| 28 | + set(${output_flags_var} |
| 29 | + ${supported_flags} |
| 30 | + PARENT_SCOPE) |
| 31 | +endfunction() |
| 32 | + |
| 33 | +function(check_arch_support) |
| 34 | + message(STATUS "Checking for AVX, AVX512 and SSE support") |
| 35 | + try_run( |
| 36 | + RUN_RESULT_VAR COMPILE_RESULT_VAR ${CMAKE_BINARY_DIR} |
| 37 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CheckAVX.cpp |
| 38 | + COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT |
| 39 | + RUN_OUTPUT_VARIABLE RUN_OUTPUT) |
| 40 | + if(RUN_OUTPUT MATCHES "AVX512") |
| 41 | + set(FINUFFT_ARCH_FLAGS |
| 42 | + "/arch:AVX512" |
| 43 | + CACHE STRING "" FORCE) |
| 44 | + elseif(RUN_OUTPUT MATCHES "AVX2") |
| 45 | + set(FINUFFT_ARCH_FLAGS |
| 46 | + "/arch:AVX2" |
| 47 | + CACHE STRING "" FORCE) |
| 48 | + elseif(RUN_OUTPUT MATCHES "AVX") |
| 49 | + set(FINUFFT_ARCH_FLAGS |
| 50 | + "/arch:AVX" |
| 51 | + CACHE STRING "" FORCE) |
| 52 | + elseif(RUN_OUTPUT MATCHES "SSE") |
| 53 | + set(FINUFFT_ARCH_FLAGS |
| 54 | + "/arch:SSE" |
| 55 | + CACHE STRING "" FORCE) |
| 56 | + else() |
| 57 | + set(FINUFFT_ARCH_FLAGS |
| 58 | + "" |
| 59 | + CACHE STRING "" FORCE) |
| 60 | + endif() |
| 61 | + message(STATUS "CPU supports: ${RUN_OUTPUT}") |
| 62 | + message(STATUS "Using MSVC flags: ${FINUFFT_ARCH_FLAGS}") |
| 63 | +endfunction() |
| 64 | + |
| 65 | +function(copy_dll source_target destination_target) |
| 66 | + if(NOT WIN32) |
| 67 | + return() |
| 68 | + endif() |
| 69 | + # Get the binary directory of the destination target |
| 70 | + get_target_property(DESTINATION_DIR ${destination_target} BINARY_DIR) |
| 71 | + set(DESTINATION_FILE ${DESTINATION_DIR}/$<TARGET_FILE_NAME:${source_target}>) |
| 72 | + if(NOT EXISTS ${DESTINATION_FILE}) |
| 73 | + message( |
| 74 | + STATUS |
| 75 | + "Copying ${source_target} to ${DESTINATION_DIR} directory for ${destination_target}" |
| 76 | + ) |
| 77 | + # Define the custom command to copy the source target to the destination |
| 78 | + # directory |
| 79 | + add_custom_command( |
| 80 | + TARGET ${destination_target} |
| 81 | + POST_BUILD |
| 82 | + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${source_target}> |
| 83 | + ${DESTINATION_FILE} |
| 84 | + COMMENT "Copying ${source_target} to ${destination_target} directory") |
| 85 | + endif() |
| 86 | + # Unset the variables to leave a clean state |
| 87 | + unset(DESTINATION_DIR) |
| 88 | + unset(SOURCE_FILE) |
| 89 | + unset(DESTINATION_FILE) |
| 90 | +endfunction() |
0 commit comments