Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lapack-reference|fortran] Add new port #12805

Merged
merged 30 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d7a475c
[vcpkg/script] add vcpkg_find_fortran
Neumann-A Aug 7, 2020
7dbb51c
[openblas] add pkg-config fixes
Neumann-A Aug 7, 2020
9470516
[lapack] add lapack-reference and reduce dependency on clapack
Neumann-A Aug 7, 2020
7602456
fix build issues
Neumann-A Aug 7, 2020
7c641d0
dont touch any main files
Neumann-A Aug 7, 2020
21fb89f
move toolchain var into parent scope
Neumann-A Aug 7, 2020
8247cd3
fix a few more issues
Neumann-A Aug 7, 2020
81cfb5b
create link in the noblas case
Neumann-A Aug 7, 2020
0685ce0
removed unnecessary check handled by vcpkg_find_fortran.
Neumann-A Aug 7, 2020
2035353
move dumpbin check
Neumann-A Aug 7, 2020
9ef1894
fix last issue
Neumann-A Aug 7, 2020
a9e0a17
depend on openblas
Neumann-A Aug 7, 2020
da34b28
set cmake_binary_dir so that compiler id run gets put into buildtree.
Neumann-A Aug 7, 2020
dc17471
more paths
Neumann-A Aug 7, 2020
fa569bc
add missing PARENT_SCOPE
Neumann-A Aug 7, 2020
61708ad
ws change
Neumann-A Aug 7, 2020
7eb3e03
[mlpack] remove dep on clapack
Neumann-A Aug 7, 2020
d8a31b8
comment out patches
Neumann-A Aug 7, 2020
66261d7
remove openblas again
Neumann-A Aug 7, 2020
3b357f4
Install lapack wrapper since it is missing linkage against -lm and -l…
Neumann-A Aug 7, 2020
fdfb8c6
PREPEND mingw path to make sure cmake picks it up correctly
Neumann-A Aug 7, 2020
7f78674
depend on openblas also on osx
Neumann-A Aug 7, 2020
824aa9c
add clapack on windows to skip due to conflicting library installs
Neumann-A Aug 7, 2020
4460b33
add clapack to skip on linux
Neumann-A Aug 7, 2020
6239ba9
add -fPIC as a fortran compiler flag
Neumann-A Aug 7, 2020
0fa6f86
do not add the flag on windows
Neumann-A Aug 7, 2020
147e01e
add gcc explicitly to the cmake args.
Neumann-A Aug 7, 2020
5e40b0a
ws change
Neumann-A Aug 7, 2020
9c2641d
applyrequested changes from CR
Neumann-A Aug 10, 2020
3887876
fix the failing patch
Neumann-A Aug 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ports/clapack/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ vcpkg_extract_source_archive_ex(
ARCHIVE ${ARCHIVE}
PATCHES
remove_internal_blas.patch
fix-ConfigFile.patch
fix-ConfigFile.patch
fix-install.patch
support-uwp.patch
)
Expand All @@ -37,10 +37,6 @@ vcpkg_copy_pdbs()
#TODO: fix the official exported targets, since they are broken (luckily it seems that no-one uses them for now)
vcpkg_fixup_cmake_targets(CONFIG_PATH share/clapack)

#we install a cmake wrapper since the official FindLAPACK module in cmake does find clapack easily, unfortunately...
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/lapack)
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/FindLAPACK.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/lapack)
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

# Handle copyright
Expand Down
16 changes: 16 additions & 0 deletions ports/lapack-reference/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Source: lapack-reference
Version: 3.8.0
Description: LAPACK — Linear Algebra PACKage http://www.netlib.org/lapack/
Default-Features: blas-select
Build-Depends: vcpkg-gfortran (windows)

Feature: cblas
Description: Builds CBLAS

Feature: noblas
Build-Depends: openblas (!osx)
Description: Use external optimized BLAS

Feature: blas-select
Build-Depends: lapack-reference[core, noblas](!windows)
Description: Use external optimized BLAS
106 changes: 106 additions & 0 deletions ports/lapack-reference/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#TODO: Features to add:
# USE_XBLAS??? extended precision blas. needs xblas
# LAPACKE should be its own PORT
# USE_OPTIMIZED_LAPACK (Probably not what we want. Does a find_package(LAPACK): probably for LAPACKE only builds _> own port?)
# LAPACKE Builds LAPACKE
# LAPACKE_WITH_TMG Build LAPACKE with tmglib routines
include(vcpkg_find_fortran)
SET(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled)

set(lapack_ver 3.8.0)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO "Reference-LAPACK/lapack"
REF "v${lapack_ver}"
SHA512 17786cb7306fccdc9b4a242de7f64fc261ebe6a10b6ec55f519deb4cb673cb137e8742aa5698fd2dc52f1cd56d3bd116af3f593a01dcf6770c4dcc86c50b2a7f
HEAD_REF master
)

set(CBLAS OFF)
if("cblas" IN_LIST FEATURES)
set(CBLAS ON)
endif()

set(USE_OPTIMIZED_BLAS OFF)
if("noblas" IN_LIST FEATURES)
set(USE_OPTIMIZED_BLAS ON)
set(pcfile "${CURRENT_INSTALLED_DIR}/lib/pkgconfig/openblas.pc")
if(EXISTS "${pcfile}")
file(CREATE_LINK "${pcfile}" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/blas.pc" COPY_ON_ERROR)
endif()
set(pcfile "${CURRENT_INSTALLED_DIR}/debug/lib/pkgconfig/openblas.pc")
if(EXISTS "${pcfile}")
file(CREATE_LINK "${pcfile}" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/blas.pc" COPY_ON_ERROR)
endif()
endif()

vcpkg_find_fortran(FORTRAN_CMAKE)
if(VCPKG_USE_INTERNAL_Fortran)
set(USE_OPTIMIZED_BLAS OFF)
#Cannot use openblas from vcpkg if we are building with gfortran here.
if("noblas" IN_LIST FEATURES)
message(FATAL_ERROR "Feature 'noblas' cannot be used without supplying an external fortran compiler")
endif()
else()
set(USE_OPTIMIZED_BLAS ON)
endif()
vcpkg_configure_cmake(
PREFER_NINJA
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
"-DUSE_OPTIMIZED_BLAS=${USE_OPTIMIZED_BLAS}"
"-DCBLAS=${CBLAS}"
"${FORTRAN_CMAKE}"
)

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/lapack-${lapack_ver}) #Should the target path be lapack and not lapack-reference?

set(pcfile "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
endif()
set(pcfile "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}/debug\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
endif()
set(pcfile "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/blas.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
endif()
set(pcfile "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/blas.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}/debug\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
endif()
vcpkg_fixup_pkgconfig()
vcpkg_copy_pdbs()

# Handle copyright
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

# remove debug includs
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

if(VCPKG_TARGET_IS_WINDOWS)
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/liblapack.lib")
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/liblapack.lib" "${CURRENT_PACKAGES_DIR}/lib/lapack.lib")
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/liblapack.lib")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/liblapack.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/lapack.lib")
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/libblas.lib")
file(RENAME "${CURRENT_PACKAGES_DIR}/lib/libblas.lib" "${CURRENT_PACKAGES_DIR}/lib/blas.lib")
endif()
if(EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/libblas.lib")
file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/libblas.lib" "${CURRENT_PACKAGES_DIR}/debug/lib/blas.lib")
endif()
endif()
4 changes: 2 additions & 2 deletions ports/lapack/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Source: lapack
Version: 0
Version: 1
Description: Metapackage for packages which provide LAPACK
Build-Depends: clapack (!osx)
Build-Depends: clapack ((arm&windows)|uwp), lapack-reference(!uwp&!(arm&windows))
File renamed without changes.
9 changes: 8 additions & 1 deletion ports/lapack/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)
# Make sure LAPACK can be found
vcpkg_configure_cmake(SOURCE_PATH ${CURRENT_PORT_DIR})

if(VCPKG_TARGET_IS_UWP OR VCPKG_TARGET_IS_WINDOWS AND VCPKG_TARGET_ARCHITECTURE MATCHES "arm")
# Install clapack wrappers.
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/clapack/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/lapack)
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/clapack/FindLAPACK.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/lapack)
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
endif()
vcpkg_configure_cmake(SOURCE_PATH ${CURRENT_PORT_DIR}
OPTIONS -DCMAKE_PREFIX_PATH="${CURRENT_PACKAGES_DIR}")
3 changes: 2 additions & 1 deletion ports/openblas/CONTROL
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Source: openblas
Version: 0.3.9-1
Version: 0.3.9
Port-Version: 2
Homepage: https://github.com/xianyi/OpenBLAS
Build-Depends: pthread (linux)
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
25 changes: 21 additions & 4 deletions ports/openblas/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include(vcpkg_common_functions)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO xianyi/OpenBLAS
Expand All @@ -22,7 +20,9 @@ set(SED_EXE_PATH "${GIT_EXE_PATH}/../usr/bin")
# openblas require perl to generate .def for exports
vcpkg_find_acquire_program(PERL)
get_filename_component(PERL_EXE_PATH ${PERL} DIRECTORY)
set(ENV{PATH} "$ENV{PATH};${PERL_EXE_PATH};${SED_EXE_PATH}")
set(PATH_BACKUP "$ENV{PATH}")
vcpkg_add_to_path("${PERL_EXE_PATH}")
vcpkg_add_to_path("${SED_EXE_PATH}")

set(COMMON_OPTIONS -DBUILD_WITHOUT_LAPACK=ON)

Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -46,7 +46,7 @@ if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")

# add just built path to environment for gen_config_h.exe,
# getarch.exe and getarch_2nd.exe
set(ENV{PATH} "$ENV{PATH};${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
vcpkg_add_to_path("${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")

# restore target build information
set(VCPKG_CMAKE_SYSTEM_NAME "${TEMP_CMAKE_SYSTEM_NAME}")
Expand Down Expand Up @@ -85,6 +85,23 @@ endif()

vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/cmake/OpenBLAS TARGET_PATH share/openblas)
set(ENV{PATH} "${PATH_BACKUP}")

set(pcfile "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/openblas.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
#file(CREATE_LINK "${pcfile}" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/blas.pc" COPY_ON_ERROR)
endif()
set(pcfile "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/openblas.pc")
if(EXISTS "${pcfile}")
file(READ "${pcfile}" _contents)
set(_contents "prefix=${CURRENT_INSTALLED_DIR}/debug\n${_contents}")
file(WRITE "${pcfile}" "${_contents}")
#file(CREATE_LINK "${pcfile}" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/blas.pc" COPY_ON_ERROR)
endif()
vcpkg_fixup_pkgconfig()
#maybe we need also to write a wrapper inside share/blas to search implicitly for openblas, whenever we feel it's ready for its own -config.cmake file

# openblas do not make the config file , so I manually made this
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 4 additions & 0 deletions ports/vcpkg-gfortran/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Source: vcpkg-gfortran
Version: 1
Description: Metaport to install gfortran dependencies from msys if VCPKG_USE_EXTERNAL_Fortran is false
Supports: windows & !arm
52 changes: 52 additions & 0 deletions ports/vcpkg-gfortran/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include(vcpkg_find_fortran)
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
vcpkg_find_fortran(FORTRAN_CMAKE)
if(VCPKG_USE_INTERNAL_Fortran)
set(VCPKG_CRT_LINKAGE dynamic) # Will always be dynamic no way to overwrite internal CRT linkage here
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
if(DEFINED ENV{PROCESSOR_ARCHITEW6432})
set(HOST_ARCH $ENV{PROCESSOR_ARCHITEW6432})
else()
set(HOST_ARCH $ENV{PROCESSOR_ARCHITECTURE})
endif()

if(HOST_ARCH MATCHES "(amd|AMD)64")
set(MINGW_W w64)
set(MSYS_HOST x86_64)
elseif(HOST_ARCH MATCHES "(x|X)86")
set(MINGW_W w32)
set(MSYS_HOST i686)
else()
message(FATAL_ERROR "Unsupported host architecture ${HOST_ARCH}!" )
endif()

if(VCPKG_TARGET_ARCHITECTURE MATCHES "(x|X)64")
set(MSYS_TARGET x86_64)
set(MINGW_W_TARGET 64)
set(GCC_LIB_SUFFIX s_seh-1)
elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "(x|X)86")
set(MSYS_TARGET i686)
set(MINGW_W_TARGET 32)
set(GCC_LIB_SUFFIX s_dw2-1)
else()
message(FATAL_ERROR "Unsupported target architecture ${VCPKG_TARGET_ARCHITECTURE}!" )
endif()


vcpkg_acquire_msys(MSYS_ROOT PACKAGES "mingw-w64-${MSYS_TARGET}-gcc-fortran") # TODO: make x86 work

set(MINGW_BIN "${MSYS_ROOT}/mingw${MINGW_W_TARGET}/bin/")
set(MINGW_Fortran_DLLS "${MINGW_BIN}/libgfortran-5.dll"
"${MINGW_BIN}/libquadmath-0.dll"
"${MINGW_BIN}/libwinpthread-1.dll"
"${MINGW_BIN}/libgcc_${GCC_LIB_SUFFIX}.dll")
file(INSTALL ${MINGW_Fortran_DLLS} DESTINATION "${CURRENT_PACKAGES_DIR}/bin")
file(INSTALL ${MINGW_Fortran_DLLS} DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin")
set(VCPKG_POLICY_SKIP_DUMPBIN_CHECKS enabled) # due to outdated msvcrt
set(VCPKG_POLICY_DLLS_WITHOUT_LIBS enabled)
set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled)
file(INSTALL "${MSYS_ROOT}/mingw${MINGW_W_TARGET}/share/licenses/winpthreads" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/license")
file(INSTALL "${MSYS_ROOT}/mingw${MINGW_W_TARGET}/share/licenses/gcc-libs" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/license")
file(INSTALL "${MSYS_ROOT}/mingw${MINGW_W_TARGET}/share/licenses/crt/COPYING.MinGW-w64-runtime.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
else()
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
endif()
57 changes: 57 additions & 0 deletions scripts/cmake/vcpkg_find_fortran.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## # vcpkg_find_fortran
##
## Checks if a Fortran compiler can be found.
## Windows(x86/x64) Only: If not it will switch/enable MinGW gfortran
## and return required cmake args for building.
##
## ## Usage
## ```cmake
## vcpkg_find_fortran(<additional_cmake_args_out>
## )
## ```

function(vcpkg_find_fortran additional_cmake_args_out)
set(ARGS_OUT)
include(CMakeDetermineFortranCompiler)
if(NOT CMAKE_Fortran_COMPILER AND NOT VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
# This intentionally breaks users with a custom toolchain which do not have a Fortran compiler setup
# because they either need to use a port-overlay (for e.g. lapack), remove the toolchain for the port using fortran
# or setup fortran in their VCPKG_CHAINLOAD_TOOLCHAIN_FILE themselfs!
if(WIN32)
message(STATUS "No Fortran compiler found on the PATH. Using MinGW gfortran!")
# If no Fortran compiler is on the path we switch to use gfortan from MinGW within vcpkg
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/mingw.cmake") # Switching to mingw toolchain
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(MINGW_PATH mingw32)
set(MSYS_TARGET i686)
set(MACHINE_FLAG -m32)
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
set(MINGW_PATH mingw64)
set(MSYS_TARGET x86_64)
set(MACHINE_FLAG -m64)
else()
message(FATAL_ERROR "Unknown architecture '${VCPKG_TARGET_ARCHITECTURE}' for MinGW Fortran build!")
endif()
vcpkg_acquire_msys(MSYS_ROOT "mingw-w64-${MSYS_TARGET}-gcc-fortran")
set(MINGW_BIN "${MSYS_ROOT}/${MINGW_PATH}/bin")
vcpkg_add_to_path("${MINGW_BIN}")
list(APPEND ARGS_OUT -DCMAKE_GNUtoMS=ON
"-DCMAKE_Fortran_COMPILER=${MINGW_BIN}/gfortran.exe"
"-DCMAKE_Fortran_FLAGS_INIT:STRING= -mabi=ms ${MACHINE_FLAG} ${VCPKG_Fortran_FLAGS}")
set(VCPKG_USE_INTERNAL_Fortran TRUE PARENT_SCOPE)
set(VCPKG_POLICY_SKIP_DUMPBIN_CHECKS enabled PARENT_SCOPE)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/mingw.cmake" PARENT_SCOPE) # Switching to MinGW toolchain for Fortran
if(VCPKG_CRT_LINKAGE STREQUAL "static")
set(VCPKG_CRT_LINKAGE dynamic)
message(STATUS "VCPKG_CRT_LINKAGE linkage for ${PORT} using vcpkg's internal gfortran cannot be static due to linking against MinGW libraries. Forcing dynamic CRT linkage")
endif()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
set(VCPKG_LIBRARY_LINKAGE dynamic)
message(STATUS "VCPKG_LIBRARY_LINKAGE linkage for ${PORT} using vcpkg's internal gfortran cannot be static due to linking against MinGW libraries. Forcing dynamic library linkage")
endif()
else()
message(FATAL_ERROR "Unable to find a Fortran compiler using 'CMakeDetermineFortranCompiler'. Please install one (e.g. gfortran) and make it available on the PATH!")
endif()
endif()
set(${additional_cmake_args_out} ${ARGS_OUT} PARENT_SCOPE)
endfunction()