From 9eab676340f05c65e1f5a91266de9450aa31649c Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:36:44 -0500 Subject: [PATCH] Use overlay ports to force x86 Windows to use clapack and openblas --- overlayPorts/blas/blas.pc.in | 8 +++ overlayPorts/blas/portfile.cmake | 71 +++++++++++++++++++ .../blas/vcpkg-cmake-wrapper.cmake.in | 9 +++ overlayPorts/blas/vcpkg.json | 26 +++++++ overlayPorts/lapack/lapack.pc.in | 9 +++ overlayPorts/lapack/portfile.cmake | 42 +++++++++++ .../lapack/vcpkg-cmake-wrapper.cmake.in | 15 ++++ overlayPorts/lapack/vcpkg.json | 23 ++++++ publish.gradle | 2 +- 9 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 overlayPorts/blas/blas.pc.in create mode 100644 overlayPorts/blas/portfile.cmake create mode 100644 overlayPorts/blas/vcpkg-cmake-wrapper.cmake.in create mode 100644 overlayPorts/blas/vcpkg.json create mode 100644 overlayPorts/lapack/lapack.pc.in create mode 100644 overlayPorts/lapack/portfile.cmake create mode 100644 overlayPorts/lapack/vcpkg-cmake-wrapper.cmake.in create mode 100644 overlayPorts/lapack/vcpkg.json diff --git a/overlayPorts/blas/blas.pc.in b/overlayPorts/blas/blas.pc.in new file mode 100644 index 0000000..49f7f10 --- /dev/null +++ b/overlayPorts/blas/blas.pc.in @@ -0,0 +1,8 @@ +prefix=${pcfiledir}/../.. + +Name: BLAS +Description: Implementation of BLAS +Version: +Requires: @requires@ +Libs: @libs@ +Cflags: @cflags@ diff --git a/overlayPorts/blas/portfile.cmake b/overlayPorts/blas/portfile.cmake new file mode 100644 index 0000000..f0e9094 --- /dev/null +++ b/overlayPorts/blas/portfile.cmake @@ -0,0 +1,71 @@ +SET(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +# Due to the interaction between BLAS and LAPACK, we need to choose implementations consistent with +# each other. +# +# First, if we are on Apple, we use the Accelerate framework. +# +# Then, we prefer to use openblas and lapack-reference for blas and lapack, respectively, but +# sometimes are unable. +# +# If we are on Windows and arm or uwp, that we use gfortran as our fortran compiler creates an issue +# because there is no available libgfortran. This means ew can't use lapack-reference at all. +# +# If we are on Windows and static, there is a linking problem caused by static gfortran in the same +# link as openblas, so we have to use the blas implementation from lapack-reference. +# +# That results in roughly the following decision tree: +# +# no_libgfortran = (uwp || windows) +# can_link_mixed_static_libgfortran = !windows || !static +# +# if (no_libgfortran) { +# return { +# "blas": "openblas", +# "lapack": "clapack" +# }; +# } else if (can_link_mixed_static_libgfortran) { +# return { +# "blas": "openblas", +# "lapack": "lapack-reference[noblas]" +# }; +# } else { +# return { +# "blas": "lapack-reference[blas]", +# "lapack": "lapack-reference[blas]" +# }; +# } +# +# Scoping this to just the 'can use openblas' question, we get: +# uwp || (windows && arm) || !windows || !static +# and for lapack-reference[blas], the DeMorgan'd inverse of that: +# !uwp && !(windows && arm) && windows && static + +if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS) + # Use Apple's accelerate framework where available + set(BLA_VENDOR Apple) + set(requires "") + set(libs "-framework Accelerate") + set(cflags "-framework Accelerate") +elseif(VCPKG_TARGET_IS_UWP + OR VCPKG_TARGET_IS_WINDOWS + OR NOT (VCPKG_LIBRARY_LINKAGE STREQUAL "static")) + set(BLA_VENDOR OpenBLAS) + set(requires openblas) +else() + set(BLA_VENDOR Generic) + set(requires "blas-reference") +endif() + +configure_file("${CMAKE_CURRENT_LIST_DIR}/blas.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/blas.pc" @ONLY) +if(NOT VCPKG_BUILD_TYPE) + configure_file("${CMAKE_CURRENT_LIST_DIR}/blas.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/blas.pc" @ONLY) +endif() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + set(BLA_STATIC ON) +else() + set(BLA_STATIC OFF) +endif() + +configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/blas/vcpkg-cmake-wrapper.cmake" @ONLY) diff --git a/overlayPorts/blas/vcpkg-cmake-wrapper.cmake.in b/overlayPorts/blas/vcpkg-cmake-wrapper.cmake.in new file mode 100644 index 0000000..67b63bc --- /dev/null +++ b/overlayPorts/blas/vcpkg-cmake-wrapper.cmake.in @@ -0,0 +1,9 @@ +# BLA_VENDOR and BLA_STATIC are documented at: +# * https://cmake.org/cmake/help/latest/module/FindBLAS.html +# * https://cmake.org/cmake/help/latest/module/FindLAPACK.html + +set(BLA_VENDOR @BLA_VENDOR@) +set(BLA_STATIC @BLA_STATIC@) +_find_package(${ARGS}) +unset(BLA_VENDOR) +unset(BLA_STATIC) diff --git a/overlayPorts/blas/vcpkg.json b/overlayPorts/blas/vcpkg.json new file mode 100644 index 0000000..738c7ad --- /dev/null +++ b/overlayPorts/blas/vcpkg.json @@ -0,0 +1,26 @@ +{ + "$comment": "Keep the platform expressions in sync with the wrappers installed by the portfiles!", + "name": "blas", + "version-date": "2023-04-14", + "port-version": 1, + "description": "Metapackage for packages which provide BLAS", + "license": null, + "supports": "!(android & arm32) & !(android & x64)", + "dependencies": [ + { + "name": "lapack-reference", + "features": [ + "cblas" + ], + "platform": "!osx & !ios & !uwp & !windows & static" + }, + { + "name": "openblas", + "platform": "!osx & !ios & (uwp | windows | !static)" + }, + { + "name": "vcpkg-cmake", + "host": true + } + ] +} \ No newline at end of file diff --git a/overlayPorts/lapack/lapack.pc.in b/overlayPorts/lapack/lapack.pc.in new file mode 100644 index 0000000..0551230 --- /dev/null +++ b/overlayPorts/lapack/lapack.pc.in @@ -0,0 +1,9 @@ +prefix=${pcfiledir}/../.. +libdir=${prefix}/lib + +Name: LAPACK +Description: Implementation of LAPACK +Version: +Requires: @requires@ +Libs: @libs@ +Cflags: @cflags@ diff --git a/overlayPorts/lapack/portfile.cmake b/overlayPorts/lapack/portfile.cmake new file mode 100644 index 0000000..c5cd611 --- /dev/null +++ b/overlayPorts/lapack/portfile.cmake @@ -0,0 +1,42 @@ +SET(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + set(BLA_STATIC ON) +else() + set(BLA_STATIC OFF) +endif() + +# See explanation of which lapack implementation is chosen in portfile.cmake in the blas port + +set(BLA_VENDOR Generic) +set(installed_wrapper "${CURRENT_INSTALLED_DIR}/share/lapack/vcpkg-cmake-wrapper.cmake") +set(installed_module "${CURRENT_INSTALLED_DIR}/share/lapack/FindLAPACK.cmake") +if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS) + # Use Apple's accelerate framework where available + set(BLA_VENDOR Apple) + configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/lapack/vcpkg-cmake-wrapper.cmake" @ONLY) + set(libs "-framework Accelerate") + set(cflags "-framework Accelerate") + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY) + if(NOT VCPKG_BUILD_TYPE) + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY) + endif() + unset(installed_module) +elseif(VCPKG_TARGET_IS_UWP OR VCPKG_TARGET_IS_WINDOWS) + configure_file("${CURRENT_INSTALLED_DIR}/share/clapack/wrapper/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/vcpkg-cmake-wrapper.cmake" COPYONLY) + configure_file("${CURRENT_INSTALLED_DIR}/share/clapack/FindLAPACK.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/FindLAPACK.cmake" COPYONLY) + set(libs "-llapack -llibf2c") + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY) + if(NOT VCPKG_BUILD_TYPE) + set(libs "-llapack -llibf2c") + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY) + endif() +else() + configure_file("${CURRENT_INSTALLED_DIR}/share/lapack-reference/wrapper/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/vcpkg-cmake-wrapper.cmake" COPYONLY) + configure_file("${CURRENT_INSTALLED_DIR}/share/lapack-reference/FindLAPACK.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/FindLAPACK.cmake" COPYONLY) + set(requires "lapack-reference") + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY) + if(NOT VCPKG_BUILD_TYPE) + configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY) + endif() +endif() diff --git a/overlayPorts/lapack/vcpkg-cmake-wrapper.cmake.in b/overlayPorts/lapack/vcpkg-cmake-wrapper.cmake.in new file mode 100644 index 0000000..64d7d98 --- /dev/null +++ b/overlayPorts/lapack/vcpkg-cmake-wrapper.cmake.in @@ -0,0 +1,15 @@ +# BLA_VENDOR and BLA_STATIC are documented at: +# * https://cmake.org/cmake/help/latest/module/FindBLAS.html +# * https://cmake.org/cmake/help/latest/module/FindLAPACK.html + +_find_package(BLAS) # Find BLAS before setting BLA_VENDOR (Will set/unset BLA_VENDOR itself) +set(BLA_VENDOR @BLA_VENDOR@) +if(APPLE AND "@BLA_STATIC@" AND CMAKE_VERSION VERSION_LESS "3.17.0") + # avoid `-Wl,--(start|end)-group` and wrong lib suffix + set(BLA_STATIC 0) +else() + set(BLA_STATIC @BLA_STATIC@) +endif() +_find_package(${ARGS}) +unset(BLA_VENDOR) +unset(BLA_STATIC) diff --git a/overlayPorts/lapack/vcpkg.json b/overlayPorts/lapack/vcpkg.json new file mode 100644 index 0000000..b4aa754 --- /dev/null +++ b/overlayPorts/lapack/vcpkg.json @@ -0,0 +1,23 @@ +{ + "$comment": "Keep the platform expressions in sync with the wrappers installed by the portfiles!", + "name": "lapack", + "version-date": "2023-06-10", + "port-version": 2, + "description": "Metapackage for packages which provide LAPACK", + "license": null, + "supports": "!android", + "dependencies": [ + { + "name": "clapack", + "platform": "uwp | windows" + }, + { + "name": "lapack-reference", + "platform": "!osx & !ios & !uwp & !windows" + }, + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/publish.gradle b/publish.gradle index b25d07a..ba83469 100644 --- a/publish.gradle +++ b/publish.gradle @@ -109,7 +109,7 @@ ext.addTaskToCopyAllOutputs = { task -> } task buildVcpkg(type: Exec) { - def baseArgs = ['install'] + def baseArgs = ['install', "--overlay-ports=$rootDir/overlayPorts"] outputs.dir "vcpkg_installed/$triplet" executable "$rootDir/vcpkg/vcpkg" args baseArgs + "--triplet=$triplet"