Skip to content

Commit 67d81ab

Browse files
authored
Merge pull request #1609 from martin-frbg/issue1529
Create OpenBLASConfig.cmake in cmake builds as well
2 parents 2f95794 + e65f451 commit 67d81ab

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ set(OpenBLAS_VERSION "${OpenBLAS_MAJOR_VERSION}.${OpenBLAS_MINOR_VERSION}.${Open
1212
# Adhere to GNU filesystem layout conventions
1313
include(GNUInstallDirs)
1414

15+
include(CMakePackageConfigHelpers)
16+
17+
1518
set(OpenBLAS_LIBNAME openblas)
1619

1720
#######
@@ -20,6 +23,7 @@ option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON
2023
endif()
2124
option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
2225
option(DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF)
26+
option(DYNAMIC_OLDER "Support older cpus with DYNAMIC_ARCH" OFF)
2327
option(BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF)
2428
#######
2529
if(BUILD_WITHOUT_LAPACK)
@@ -208,6 +212,7 @@ set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
208212

209213
# Install libraries
210214
install(TARGETS ${OpenBLAS_LIBNAME}
215+
EXPORT "OpenBLASTargets"
211216
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
212217
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
213218
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
@@ -267,3 +272,21 @@ if(PKG_CONFIG_FOUND)
267272
configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas.pc @ONLY)
268273
install (FILES ${PROJECT_BINARY_DIR}/openblas.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/)
269274
endif()
275+
276+
277+
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
278+
set(PN OpenBLAS)
279+
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}")
280+
configure_package_config_file(cmake/${PN}Config.cmake.in
281+
"${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake"
282+
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
283+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
284+
VERSION ${${PN}_VERSION}
285+
COMPATIBILITY AnyNewerVersion)
286+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake
287+
${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
288+
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
289+
install(EXPORT "${PN}Targets"
290+
NAMESPACE "${PN}::"
291+
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
292+

cmake/OpenBLASConfig.cmake.in

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# OpenBLASConfig.cmake
2+
# --------------------
3+
#
4+
# OpenBLAS cmake module.
5+
# This module sets the following variables in your project::
6+
#
7+
# OpenBLAS_FOUND - true if OpenBLAS and all required components found on the system
8+
# OpenBLAS_VERSION - OpenBLAS version in format Major.Minor.Release
9+
# OpenBLAS_INCLUDE_DIRS - Directory where OpenBLAS header is located.
10+
# OpenBLAS_INCLUDE_DIR - same as DIRS
11+
# OpenBLAS_LIBRARIES - OpenBLAS library to link against.
12+
# OpenBLAS_LIBRARY - same as LIBRARIES
13+
#
14+
#
15+
# Available components::
16+
#
17+
## shared - search for only shared library
18+
## static - search for only static library
19+
# serial - search for unthreaded library
20+
# pthread - search for native pthread threaded library
21+
# openmp - search for OpenMP threaded library
22+
#
23+
#
24+
# Exported targets::
25+
#
26+
# If OpenBLAS is found, this module defines the following :prop_tgt:`IMPORTED`
27+
## target. Target is shared _or_ static, so, for both, use separate, not
28+
## overlapping, installations. ::
29+
#
30+
# OpenBLAS::OpenBLAS - the main OpenBLAS library #with header & defs attached.
31+
#
32+
#
33+
# Suggested usage::
34+
#
35+
# find_package(OpenBLAS)
36+
# find_package(OpenBLAS 0.2.20 EXACT CONFIG REQUIRED COMPONENTS pthread)
37+
#
38+
#
39+
# The following variables can be set to guide the search for this package::
40+
#
41+
# OpenBLAS_DIR - CMake variable, set to directory containing this Config file
42+
# CMAKE_PREFIX_PATH - CMake variable, set to root directory of this package
43+
# PATH - environment variable, set to bin directory of this package
44+
# CMAKE_DISABLE_FIND_PACKAGE_OpenBLAS - CMake variable, disables
45+
# find_package(OpenBLAS) when not REQUIRED, perhaps to force internal build
46+
47+
@PACKAGE_INIT@
48+
49+
set(PN OpenBLAS)
50+
51+
# need to check that the @USE_*@ evaluate to something cmake can perform boolean logic upon
52+
if(@USE_OPENMP@)
53+
set(${PN}_openmp_FOUND 1)
54+
elseif(@USE_THREAD@)
55+
set(${PN}_pthread_FOUND 1)
56+
else()
57+
set(${PN}_serial_FOUND 1)
58+
endif()
59+
60+
check_required_components(${PN})
61+
62+
#-----------------------------------------------------------------------------
63+
# Don't include targets if this file is being picked up by another
64+
# project which has already built this as a subproject
65+
#-----------------------------------------------------------------------------
66+
if(NOT TARGET ${PN}::OpenBLAS)
67+
include("${CMAKE_CURRENT_LIST_DIR}/${PN}Targets.cmake")
68+
69+
get_property(_loc TARGET ${PN}::OpenBLAS PROPERTY LOCATION)
70+
set(${PN}_LIBRARY ${_loc})
71+
get_property(_ill TARGET ${PN}::OpenBLAS PROPERTY INTERFACE_LINK_LIBRARIES)
72+
set(${PN}_LIBRARIES ${_ill})
73+
74+
get_property(_id TARGET ${PN}::OpenBLAS PROPERTY INCLUDE_DIRECTORIES)
75+
set(${PN}_INCLUDE_DIR ${_id})
76+
get_property(_iid TARGET ${PN}::OpenBLAS PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
77+
set(${PN}_INCLUDE_DIRS ${_iid})
78+
endif()
79+

0 commit comments

Comments
 (0)