Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed issue that was causing delocate to fail to find libraries while…
Browse files Browse the repository at this point in the history
… building wheels on Mac
  • Loading branch information
daminton committed Feb 17, 2024
1 parent fcc50b5 commit 88f7b88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
33 changes: 26 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ ELSE()
CMAKE_POLICY(SET CMP0148 OLD)
ENDIF ()

# The following section is modified from Numpy f2py documentation
IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
ENDIF()

# Set some options the user may choose
OPTION(USE_COARRAY "Use Coarray Fortran for parallelization of test particles" OFF)
OPTION(USE_OPENMP "Use OpenMP for parallelization" ON)
Expand All @@ -49,16 +54,18 @@ ELSE()
SET(INSTALL_INCLUDEDIR ${SKBUILD_HEADERS_DIR})
SET(INSTALL_PYPROJ ${SKBUILD_PLATLIB_DIR}/${SKBUILD_PROJECT_NAME})
IF (APPLE)
SET(CMAKE_INSTALL_RPATH "@loader_path/../lib")
SET(CMAKE_INSTALL_RPATH "@loader_path;${CMAKE_BINARY_DIR}/bin")
ELSEIF (LINUX)
SET(CMAKE_INSTALL_RPATH $ORIGIN/../lib)
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib;@ORIGIN")
ENDIF ()
ELSE ()
SET(INSTALL_PYPROJ ${PY})
SET(INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR})
SET(INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
SET(INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
ENDIF ()

SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Have the .mod files placed in the include folder
SET(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mod)
Expand All @@ -67,20 +74,32 @@ ELSE()
FILE(TO_CMAKE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" LOCAL_MODULE_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${LOCAL_MODULE_PATH})

# Add in the external dependency libraries
IF (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
SET(COMPILER_OPTIONS "Intel" CACHE STRING "Compiler identified as Intel")
FIND_PACKAGE(MKL)
FIND_PACKAGE(MKL) # Possibly not needed any more due to BLAS and LAPACK being found
ELSEIF (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
SET(COMPILER_OPTIONS "GNU" CACHE STRING "Compiler identified as gfortran")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler ${CMAKE_Fortran_COMPILER_ID} not recognized!")
ENDIF ()
FIND_PACKAGE(SHTOOLS REQUIRED)

# The following section is modified from Numpy f2py documentation
IF(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
MESSAGE(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.\n")
IF (COMPILER_OPTIONS STREQUAL "GNU")
IF (APPLE)
SET(BLA_VENDOR "Apple" CACHE STRING "BLAS vendor")
ELSE ()
SET(BLA_VENDOR "OpenBLAS" CACHE STRING "BLAS vendor")
ENDIF ()
ELSEIF (COMPILER_OPTIONS STREQUAL "INTEL")
SET(BLA_VENDOR "Intel10_64lp" CACHE STRING "BLAS vendor")
ENDIF()
SET(BLA_STATIC ON)
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
FIND_PACKAGE(FFTW3 REQUIRED)
FIND_PACKAGE(SHTOOLS REQUIRED)



FIND_PACKAGE(NETCDF_Fortran REQUIRED)
IF (MSVC)
Expand Down
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ PREFIX="/usr/local"
HOMEBREW_PREFIX="$(brew --prefix)"
ARCH="$(uname -m)"
LD_LIBRARY_PATH="/usr/local/lib:${PREFIX}/lib:${HOMEBREW_PREFIX}/lib"
DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}"
REPAIR_LIBRARY_PATH="${LD_LIBRARY_PATH}"
LDFLAGS="-Wl,-rpath,${ROOT_DIR}/lib -Wl,-no_compact_unwind -L${PREFIX}/lib -L${HOMEBREW_PREFIX}/lib"
CPATH="/usr/local/include:${PREFIX}/include:${HOMEBREW_PREFIX}/include:${ROOT_DIR}/include"
CPPFLAGS="-isystem ${PREFIX}/include -isystem /usr/local/include"
Expand Down Expand Up @@ -119,6 +121,11 @@ before-all = [
"brew install coreutils pkg-config fftw vecLibFort",
"LIBS=\"\" buildscripts/build_dependencies.sh -p ${PREFIX} -d ${HOME}/Downloads -m ${MACOSX_DEPLOYMENT_TARGET}"
]
repair-wheel-command = """\
DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel \
--require-archs {delocate_archs} -w {dest_dir} -v {wheel}
"""



[tool.cibuildwheel.linux.environment]
Expand All @@ -143,11 +150,13 @@ CMAKE_INSTALL_LIBDIR="lib"
skip = "cp312-* pp* -manylinux_i686* *-musllinux*"
before-all = [
"yum install epel-release -y",
"yum install doxygen libxml2-devel libcurl-devel fftw-devel openblas-devel lapack-devel -y",
"yum install doxygen libxml2-devel libcurl-devel fftw-static openblas-devel lapack-devel -y",
"buildscripts/build_dependencies.sh -p /usr/local"
]

[[tool.scikit-build.generate]]
path = "version.txt"
location = "source"
template = '''${version}'''


15 changes: 0 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,6 @@ ELSE ()
TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC SHTOOLS::serial)
ENDIF()

# Add in the BLAS, LAPACK, and FFTW3 libraries
IF (COMPILER_OPTIONS STREQUAL "GNU")
IF (APPLE)
SET(BLA_VENDOR "Apple" CACHE STRING "BLAS vendor")
ELSE ()
SET(BLA_VENDOR "OpenBLAS" CACHE STRING "BLAS vendor")
ENDIF ()
ELSEIF (COMPILER_OPTIONS STREQUAL "INTEL")
SET(BLA_VENDOR "Intel10_64lp" CACHE STRING "BLAS vendor")
ENDIF()
SET(BLA_STATIC ON)
FIND_PACKAGE(BLAS REQUIRED)
FIND_PACKAGE(LAPACK REQUIRED)
FIND_PACKAGE(FFTW3 REQUIRED)

TARGET_LINK_LIBRARIES(${SWIFTEST_LIBRARY} PUBLIC BLAS::BLAS LAPACK::LAPACK FFTW3::FFTW3)

TARGET_LINK_LIBRARIES(${SWIFTEST_DRIVER} PUBLIC ${SWIFTEST_LIBRARY})
Expand Down

0 comments on commit 88f7b88

Please sign in to comment.