Skip to content

Commit

Permalink
fixed native and dll copy
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamonDinoia committed Jul 29, 2024
1 parent f1f8595 commit 5ea371d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/generate_cmake_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
16 changes: 4 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -172,15 +172,7 @@ function(finufft_link_test target)
set_target_properties(
${target} PROPERTIES MSVC_RUNTIME_LIBRARY
"MultiThreaded$<$<CONFIG:Debug>: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 $<TARGET_FILE_DIR:finufft>
$<TARGET_FILE_DIR:${target}>)
endif()
copy_dll(finufft ${target})
endfunction()

# Utility function to set finufft compilation options.
Expand Down
35 changes: 31 additions & 4 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}/$<TARGET_FILE_NAME:${source_target}>)
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 $<TARGET_FILE:${source_target}>
${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()

0 comments on commit 5ea371d

Please sign in to comment.