Skip to content

Commit

Permalink
[blas/lapack] force vendor (microsoft#24327)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Neumann <you@example.com>
Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
  • Loading branch information
3 people authored and Thomas1664 committed Apr 9, 2024
1 parent 8bbe98b commit 4391188
Show file tree
Hide file tree
Showing 44 changed files with 1,226 additions and 1,018 deletions.
7 changes: 6 additions & 1 deletion ports/armadillo/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ vcpkg_cmake_configure(
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup(CONFIG_PATH share/Armadillo/CMake)

vcpkg_cmake_config_fixup(PACKAGE_NAME Armadillo CONFIG_PATH share/Armadillo/CMake)
vcpkg_replace_string( "${CURRENT_PACKAGES_DIR}/share/Armadillo/ArmadilloConfig.cmake"
[[include("${VCPKG_IMPORT_PREFIX}/share/Armadillo/ArmadilloLibraryDepends.cmake")]]
"include(CMakeFindDependencyMacro)\nfind_dependency(LAPACK)\ninclude(\"\${VCPKG_IMPORT_PREFIX}/share/Armadillo/ArmadilloLibraryDepends.cmake\")"
)
vcpkg_fixup_pkgconfig()
vcpkg_copy_pdbs()

Expand Down
1 change: 1 addition & 0 deletions ports/armadillo/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "armadillo",
"version": "12.6.6",
"port-version": 1,
"description": "Armadillo is a high quality linear algebra library (matrix maths) for the C++ language, aiming towards a good balance between speed and ease of use",
"homepage": "https://arma.sourceforge.net/",
"license": "Apache-2.0",
Expand Down
8 changes: 8 additions & 0 deletions ports/blas/blas.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prefix=${pcfiledir}/../..

Name: BLAS
Description: Implementation of BLAS
Version:
Requires: @requires@
Libs: @libs@
Cflags: @cflags@
87 changes: 72 additions & 15 deletions ports/blas/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,72 @@
SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" DESTINATION "${CURRENT_PACKAGES_DIR}/share/blas")

# Make sure BLAS can be found
vcpkg_list(SET CMAKE_IGNORE_PATH)
if(NOT DEFINED ENV{MKLROOT})
list(APPEND CMAKE_IGNORE_PATH "${CURRENT_INSTALLED_DIR}/lib/intel64")
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}"
OPTIONS
"-DCMAKE_PREFIX_PATH=${CURRENT_PACKAGES_DIR}"
"-DCMAKE_IGNORE_PATH=${CMAKE_IGNORE_PATH}"
)
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 && arm))
# 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 AND VCPKG_TARGET_ARCHITECTURE MATCHES "arm")
OR NOT 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)
9 changes: 0 additions & 9 deletions ports/blas/vcpkg-cmake-wrapper.cmake

This file was deleted.

9 changes: 9 additions & 0 deletions ports/blas/vcpkg-cmake-wrapper.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 13 additions & 2 deletions ports/blas/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
{
"$comment": "Keep the platform expressions in sync with the wrappers installed by the portfiles!",
"name": "blas",
"version-date": "2023-03-25",
"version-date": "2023-04-14",
"description": "Metapackage for packages which provide BLAS",
"license": null,
"dependencies": [
"openblas",
{
"name": "lapack-reference",
"features": [
"cblas"
],
"platform": "!osx & !ios & !uwp & !(windows & arm) & windows & static"
},
{
"name": "openblas",
"platform": "!osx & !ios & (uwp | (windows & arm) | !windows | !static)"
},
{
"name": "vcpkg-cmake",
"host": true
Expand Down
8 changes: 8 additions & 0 deletions ports/cblas/cblas.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prefix=${pcfiledir}/../..

Name: CBLAS
Description: Implementation of CBLAS
Version:
Requires: @requires@
Libs: @libs@
Cflags: @cflags@
24 changes: 24 additions & 0 deletions ports/cblas/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)

# This block should be kept in sync with the port 'blas'
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 AND VCPKG_TARGET_ARCHITECTURE MATCHES "arm")
OR NOT 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 "cblas-reference")
endif()

configure_file("${CMAKE_CURRENT_LIST_DIR}/cblas.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/cblas.pc" @ONLY)
if(NOT VCPKG_BUILD_TYPE)
configure_file("${CMAKE_CURRENT_LIST_DIR}/cblas.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/cblas.pc" @ONLY)
endif()
24 changes: 24 additions & 0 deletions ports/cblas/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$comment": "Keep the platform expressions in sync with the wrappers installed by the portfiles!",
"name": "cblas",
"version-date": "2024-03-19",
"description": "Metapackage for packages which provide CBLAS",
"license": null,
"dependencies": [
{
"name": "lapack-reference",
"features": [
"cblas"
],
"platform": "!osx & !ios & !uwp & !(windows & arm) & windows & static"
},
{
"name": "openblas",
"platform": "!osx & !ios & (uwp | (windows & arm) | !windows | !static)"
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}
Loading

0 comments on commit 4391188

Please sign in to comment.