Skip to content

Commit 474f7e9

Browse files
authored
Add SYMBOLPREFIX and -SUFFIX options and improve help output
1 parent 28aa94b commit 474f7e9

File tree

1 file changed

+96
-18
lines changed

1 file changed

+96
-18
lines changed

CMakeLists.txt

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ include(GNUInstallDirs)
1515
include(CMakePackageConfigHelpers)
1616

1717

18-
set(OpenBLAS_LIBNAME openblas)
19-
2018
#######
2119
if(MSVC)
22-
option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
20+
option(BUILD_WITHOUT_LAPACK "Do not build LAPACK and LAPACKE (Only BLAS or CBLAS)" ON)
2321
endif()
24-
option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF)
25-
option(DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF)
26-
option(DYNAMIC_OLDER "Support older cpus with DYNAMIC_ARCH" OFF)
27-
option(BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF)
22+
option(BUILD_WITHOUT_CBLAS "Do not build the C interface (CBLAS) to the BLAS functions" OFF)
23+
option(DYNAMIC_ARCH "Include support for multiple CPU targets, with automatic selection at runtime (x86/x86_64 only)" OFF)
24+
option(DYNAMIC_OLDER "Include specific support for older cpu models (Penryn,Dunnington,Atom,Nano,Opteron) with DYNAMIC_ARCH" OFF)
25+
option(BUILD_RELAPACK "Build with ReLAPACK (recursive implementation of several LAPACK functions on top of standard LAPACK)" OFF)
26+
27+
# Add a prefix or suffix to all exported symbol names in the shared library.
28+
# Avoids conflicts with other BLAS libraries, especially when using
29+
# 64 bit integer interfaces in OpenBLAS.
30+
31+
set(SYMBOLPREFIX "" CACHE STRING "Add a prefix to all exported symbol names in the shared library to avoid conflicts with other BLAS libraries" )
32+
set(SYMBOLSUFFIX "" CACHE STRING "Add a suffix to all exported symbol names in the shared library, e.g. _64 for INTERFACE64 builds" )
2833
#######
2934
if(BUILD_WITHOUT_LAPACK)
3035
set(NO_LAPACK 1)
@@ -38,11 +43,13 @@ endif()
3843
#######
3944

4045

41-
message(WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available.")
46+
message(WARNING "CMake support is experimental. It does not yet support all build options and may not produce the same Makefiles that OpenBLAS ships with.")
4247

4348
include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake")
4449
include("${PROJECT_SOURCE_DIR}/cmake/system.cmake")
4550

51+
set(OpenBLAS_LIBNAME openblas${SUFFIX64_UNDERSCORE})
52+
4653
set(BLASDIRS interface driver/level2 driver/level3 driver/others)
4754

4855
if (NOT DYNAMIC_ARCH)
@@ -210,15 +217,84 @@ set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES
210217
SOVERSION ${OpenBLAS_MAJOR_VERSION}
211218
)
212219

220+
if (BUILD_SHARED_LIBS AND NOT ${SYMBOLPREFIX}${SYMBOLSUFIX} STREQUAL "")
221+
if (NOT DEFINED ARCH)
222+
set(ARCH_IN "x86_64")
223+
else()
224+
set(ARCH_IN ${ARCH})
225+
endif()
226+
227+
if (${CORE} STREQUAL "generic")
228+
set(ARCH_IN "GENERIC")
229+
endif ()
230+
231+
if (NOT DEFINED EXPRECISION)
232+
set(EXPRECISION_IN 0)
233+
else()
234+
set(EXPRECISION_IN ${EXPRECISION})
235+
endif()
236+
237+
if (NOT DEFINED NO_CBLAS)
238+
set(NO_CBLAS_IN 0)
239+
else()
240+
set(NO_CBLAS_IN ${NO_CBLAS})
241+
endif()
242+
243+
if (NOT DEFINED NO_LAPACK)
244+
set(NO_LAPACK_IN 0)
245+
else()
246+
set(NO_LAPACK_IN ${NO_LAPACK})
247+
endif()
248+
249+
if (NOT DEFINED NO_LAPACKE)
250+
set(NO_LAPACKE_IN 0)
251+
else()
252+
set(NO_LAPACKE_IN ${NO_LAPACKE})
253+
endif()
254+
255+
if (NOT DEFINED NEED2UNDERSCORES)
256+
set(NEED2UNDERSCORES_IN 0)
257+
else()
258+
set(NEED2UNDERSCORES_IN ${NEED2UNDERSCORES})
259+
endif()
260+
261+
if (NOT DEFINED ONLY_CBLAS)
262+
set(ONLY_CBLAS_IN 0)
263+
else()
264+
set(ONLY_CBLAS_IN ${ONLY_CBLAS})
265+
endif()
266+
267+
if (NOT DEFINED BU)
268+
set(BU _)
269+
endif()
270+
271+
if (NOT ${SYMBOLPREFIX} STREQUAL "")
272+
message(STATUS "adding prefix ${SYMBOLPREFIX} to names of exported symbols in ${OpenBLAS_LIBNAME}")
273+
endif()
274+
if (NOT ${SYMBOLSUFFIX} STREQUAL "")
275+
message(STATUS "adding suffix ${SYMBOLSUFFIX} to names of exported symbols in ${OpenBLAS_LIBNAME}")
276+
endif()
277+
add_custom_command(TARGET ${OpenBLAS_LIBNAME} POST_BUILD
278+
COMMAND perl ${PROJECT_SOURCE_DIR}/exports/gensymbol "objcopy" "${ARCH}" "${BU}" "${EXPRECISION_IN}" "${NO_CBLAS_IN}" "${NO_LAPACK_IN}" "${NO_LAPACKE_IN}" "${NEED2UNDERSCORES_IN}" "${ONLY_CBLAS_IN}" \"${SYMBOLPREFIX}\" \"${SYMBOLSUFFIX}\" "${BUILD_LAPACK_DEPRECATED}" > ${PROJECT_BINARY_DIR}/objcopy.def
279+
COMMAND objcopy -v --redefine-syms ${PROJECT_BINARY_DIR}/objcopy.def ${PROJECT_BINARY_DIR}/lib/lib${OpenBLAS_LIBNAME}.so
280+
COMMENT "renaming symbols"
281+
)
282+
endif()
283+
284+
213285
# Install project
214286
215287
# Install libraries
216288
install(TARGETS ${OpenBLAS_LIBNAME}
217-
EXPORT "OpenBLASTargets"
289+
EXPORT "OpenBLAS${SUFFIX64}Targets"
218290
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
219291
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
220292
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
221293
294+
# Install headers
295+
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/openblas${SUFFIX64})
296+
set(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
297+
222298
message(STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR}")
223299
224300
set(OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR}/openblas_config.h)
@@ -266,29 +342,31 @@ if(NOT NO_LAPACKE)
266342
ADD_CUSTOM_TARGET(genlapacke
267343
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/lapack-netlib/LAPACKE/include/lapacke_mangling_with_flags.h.in "${CMAKE_BINARY_DIR}/lapacke_mangling.h"
268344
)
269-
install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
345+
install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openblas${SUFFIX64})
270346
endif()
271347

272348
include(FindPkgConfig QUIET)
273349
if(PKG_CONFIG_FOUND)
274-
configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas.pc @ONLY)
275-
install (FILES ${PROJECT_BINARY_DIR}/openblas.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/)
350+
configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas${SUFFIX64}.pc @ONLY)
351+
install (FILES ${PROJECT_BINARY_DIR}/openblas${SUFFIX64}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/)
276352
endif()
277353

278354

279355
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
280356
set(PN OpenBLAS)
281-
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}")
357+
set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}${SUFFIX64}")
282358
configure_package_config_file(cmake/${PN}Config.cmake.in
283-
"${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake"
359+
"${CMAKE_CURRENT_BINARY_DIR}/${PN}${SUFFIX64}Config.cmake"
284360
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
285361
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
286362
VERSION ${${PN}_VERSION}
287363
COMPATIBILITY AnyNewerVersion)
288-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake
289-
${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
364+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}${SUFFIX64}Config.cmake
365+
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
366+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
367+
RENAME ${PN}${SUFFIX64}ConfigVersion.cmake
290368
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
291-
install(EXPORT "${PN}Targets"
292-
NAMESPACE "${PN}::"
369+
install(EXPORT "${PN}${SUFFIX64}Targets"
370+
NAMESPACE "${PN}${SUFFIX64}::"
293371
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
294372

0 commit comments

Comments
 (0)