Skip to content

Commit

Permalink
[clapack,openblas] improve libraries integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cenit committed Jun 5, 2019
1 parent fb95b01 commit a646a7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
62 changes: 33 additions & 29 deletions ports/clapack/FindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,53 +70,56 @@ include(${CMAKE_ROOT}/Modules/CMakeFindDependencyMacro.cmake)

set(CLAPACK_VERSION "3.2.1")

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_dependency(Threads)

if(UNIX)
find_library(ADDITIONAL_LAPACK_LIBRARY m)
set(PTHREAD_LINK_NAME "-pthread")
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_dependency(Threads)

if(NOT F2C_LIBRARY)
find_library(F2C_LIBRARY_RELEASE NAMES f2c libf2c)
find_library(F2C_LIBRARY_DEBUG NAMES f2cd libf2cd)
select_library_configurations(F2C)

#keep a list of "pure" f2c libs, without dependencies
set(oF2C_LIBRARY_RELEASE ${F2C_LIBRARY_RELEASE})
set(oF2C_LIBRARY_DEBUG ${F2C_LIBRARY_DEBUG})
list(APPEND F2C_LIBRARY_RELEASE ${ADDITIONAL_LAPACK_LIBRARY})
list(APPEND F2C_LIBRARY_DEBUG ${ADDITIONAL_LAPACK_LIBRARY})
select_library_configurations(oF2C)
select_library_configurations(F2C)
set(oF2C_LIBRARY ${F2C_LIBRARY})

list(APPEND F2C_LIBRARY ${ADDITIONAL_LAPACK_LIBRARY})
endif()

if(NOT LAPACK_LIBRARY)
find_library(LAPACK_LIBRARY_RELEASE NAMES lapack)
find_library(LAPACK_LIBRARY_DEBUG NAMES lapackd)

#keep a list of "pure" lapack libs, without dependencies
set(oLAPACK_LIBRARY_RELEASE ${LAPACK_LIBRARY_RELEASE})
set(oLAPACK_LIBRARY_DEBUG ${LAPACK_LIBRARY_DEBUG})
select_library_configurations(oLAPACK)

list(APPEND LAPACK_LIBRARY_RELEASE ${F2C_LIBRARY_RELEASE})
list(APPEND LAPACK_LIBRARY_DEBUG ${F2C_LIBRARY_DEBUG})

if(UNIX AND NOT APPLE)
find_dependency(OpenBLAS)
find_dependency(Threads)
find_dependency(OpenBLAS)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY IMPORTED_IMPLIB_RELEASE)
if(NOT _loc)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_RELEASE)
set(LAPACK_BLAS_LIBRARY_RELEASE ${_loc})
set(oLAPACK_BLAS_LIBRARY_RELEASE ${_loc})
endif()
set(LAPACK_BLAS_LIBRARY_RELEASE ${_loc})
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY IMPORTED_IMPLIB_DEBUG)
if(NOT _loc)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_DEBUG)
set(LAPACK_BLAS_LIBRARY_DEBUG ${_loc})
set(oLAPACK_BLAS_LIBRARY_DEBUG ${_loc})
list(APPEND LAPACK_LIBRARY_RELEASE ${LAPACK_BLAS_LIBRARY_RELEASE} Threads::Threads)
list(APPEND LAPACK_LIBRARY_DEBUG ${LAPACK_BLAS_LIBRARY_DEBUG} Threads::Threads)
select_library_configurations(oLAPACK_BLAS)
select_library_configurations(LAPACK_BLAS)
else()
find_dependency(BLAS)
set(LAPACK_LIBRARY_RELEASE ${BLAS_LIBRARIES})
set(LAPACK_LIBRARY_DEBUG ${BLAS_LIBRARIES})
endif()
set(LAPACK_BLAS_LIBRARY_DEBUG ${_loc})
select_library_configurations(LAPACK_BLAS)
list(APPEND LAPACK_LIBRARY_RELEASE ${LAPACK_BLAS_LIBRARY_RELEASE})
list(APPEND LAPACK_LIBRARY_DEBUG ${LAPACK_BLAS_LIBRARY_DEBUG})

select_library_configurations(oLAPACK)
select_library_configurations(LAPACK)
list(APPEND LAPACK_LIBRARY Threads::Threads)
endif()

if(NOT F2C_INCLUDE_DIR)
Expand All @@ -128,6 +131,7 @@ if(NOT LAPACK_INCLUDE_DIR)
endif()

list(APPEND LAPACK_INCLUDE_DIR ${F2C_INCLUDE_DIR})
set(LAPACK_INCLUDE_DIR "${LAPACK_INCLUDE_DIR}" CACHE PATH "" FORCE)
set(LAPACK_INCLUDE_DIRS "${LAPACK_INCLUDE_DIR}" CACHE PATH "" FORCE)
set(CLAPACK_INCLUDE_DIR "${LAPACK_INCLUDE_DIR}" CACHE PATH "" FORCE)
set(CLAPACK_INCLUDE_DIRS "${LAPACK_INCLUDE_DIR}" CACHE PATH "" FORCE)
Expand Down Expand Up @@ -169,9 +173,9 @@ if(CLAPACK_FOUND AND NOT TARGET clapack::clapack)
add_library(clapack::clapack SHARED IMPORTED)
set_target_properties(clapack::clapack PROPERTIES
IMPORTED_LOCATION_RELEASE "${LAPACK_LIBRARY_RELEASE_DLL}"
IMPORTED_IMPLIB "${oLAPACK_LIBRARY_RELEASE}"
IMPORTED_IMPLIB_RELEASE "${oLAPACK_LIBRARY_RELEASE}"
INTERFACE_INCLUDE_DIRECTORIES "${LAPACK_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${oLAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oLAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:m>;$<LINK_ONLY:pthread>"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${LAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${LAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:${ADDITIONAL_LAPACK_LIBRARY}>;$<LINK_ONLY:${PTHREAD_LINK_NAME}>"
IMPORTED_CONFIGURATIONS Release
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
if(EXISTS "${LAPACK_LIBRARY_DEBUG_DLL}")
Expand All @@ -185,7 +189,7 @@ if(CLAPACK_FOUND AND NOT TARGET clapack::clapack)
set_target_properties(clapack::clapack PROPERTIES
IMPORTED_LOCATION_RELEASE "${oLAPACK_LIBRARY_RELEASE}"
INTERFACE_INCLUDE_DIRECTORIES "${LAPACK_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${oLAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oLAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:m>;$<LINK_ONLY:pthread>"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${LAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${LAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:${ADDITIONAL_LAPACK_LIBRARY}>;$<LINK_ONLY:${PTHREAD_LINK_NAME}>"
IMPORTED_CONFIGURATIONS Release
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
if(EXISTS "${LAPACK_LIBRARY_DEBUG}")
Expand All @@ -201,9 +205,9 @@ if(CLAPACK_FOUND AND NOT TARGET lapack)
add_library(lapack SHARED IMPORTED)
set_target_properties(lapack PROPERTIES
IMPORTED_LOCATION_RELEASE "${LAPACK_LIBRARY_RELEASE_DLL}"
IMPORTED_IMPLIB "${oLAPACK_LIBRARY_RELEASE}"
IMPORTED_IMPLIB_RELEASE "${oLAPACK_LIBRARY_RELEASE}"
INTERFACE_INCLUDE_DIRECTORIES "${LAPACK_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${oLAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oLAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:m>;$<LINK_ONLY:pthread>"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${LAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${LAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:${ADDITIONAL_LAPACK_LIBRARY}>;$<LINK_ONLY:${PTHREAD_LINK_NAME}>"
IMPORTED_CONFIGURATIONS Release
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
if(EXISTS "${LAPACK_LIBRARY_DEBUG_DLL}")
Expand All @@ -218,7 +222,7 @@ if(CLAPACK_FOUND AND NOT TARGET lapack)
IMPORTED_LOCATION_RELEASE "${oLAPACK_LIBRARY_RELEASE}"
INTERFACE_INCLUDE_DIRECTORIES "${LAPACK_INCLUDE_DIR}"
IMPORTED_CONFIGURATIONS Release
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${oLAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oLAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:m>;$<LINK_ONLY:pthread>"
INTERFACE_LINK_LIBRARIES "$<$<NOT:$<CONFIG:DEBUG>>:${oF2C_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${oF2C_LIBRARY_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${LAPACK_BLAS_LIBRARY_RELEASE}>;$<$<CONFIG:DEBUG>:${LAPACK_BLAS_LIBRARY_DEBUG}>;$<LINK_ONLY:${ADDITIONAL_LAPACK_LIBRARY}>;$<LINK_ONLY:${PTHREAD_LINK_NAME}>"
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
if(EXISTS "${LAPACK_LIBRARY_DEBUG}")
set_property(TARGET lapack APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug)
Expand Down
12 changes: 10 additions & 2 deletions ports/openblas/vcpkg-cmake-wrapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ list(REMOVE_ITEM ARGS "NO_MODULE")
list(REMOVE_ITEM ARGS "CONFIG")
list(REMOVE_ITEM ARGS "MODULE")
if(NOT BLAS_LIBRARY OR BLAS_LIBRARIES OR OpenBLAS_LIBRARY OR OpenBLAS_LIBRARIES OR BLAS_LIB OR BLAS_LIBS)
include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)

_find_package(OpenBLAS CONFIG ${ARGS})

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
_find_package(Threads)

get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set(BLAS_INCLUDE_DIR ${_loc})
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_RELEASE)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY IMPORTED_IMPLIB_RELEASE)
if(NOT _loc)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_RELEASE)
endif()
set(BLAS_LIBRARY_RELEASE ${_loc})
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_DEBUG)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY IMPORTED_IMPLIB_DEBUG)
if(NOT _loc)
get_property(_loc TARGET OpenBLAS::OpenBLAS PROPERTY LOCATION_DEBUG)
endif()
set(BLAS_LIBRARY_DEBUG ${_loc})
list(APPEND BLAS_LIBRARY_RELEASE Threads::Threads)
list(APPEND BLAS_LIBRARY_DEBUG Threads::Threads)
Expand Down

0 comments on commit a646a7b

Please sign in to comment.