| @@ -15,16 +15,21 @@ include(GNUInstallDirs) | |||||
| include(CMakePackageConfigHelpers) | include(CMakePackageConfigHelpers) | ||||
| set(OpenBLAS_LIBNAME openblas) | |||||
| ####### | ####### | ||||
| if(MSVC) | if(MSVC) | ||||
| option(BUILD_WITHOUT_LAPACK "Without LAPACK and LAPACKE (Only BLAS or CBLAS)" ON) | |||||
| option(BUILD_WITHOUT_LAPACK "Do not build LAPACK and LAPACKE (Only BLAS or CBLAS)" ON) | |||||
| endif() | endif() | ||||
| option(BUILD_WITHOUT_CBLAS "Without CBLAS" OFF) | |||||
| option(DYNAMIC_ARCH "Build with DYNAMIC_ARCH" OFF) | |||||
| option(DYNAMIC_OLDER "Support older cpus with DYNAMIC_ARCH" OFF) | |||||
| option(BUILD_RELAPACK "Build with ReLAPACK (recursive LAPACK" OFF) | |||||
| option(BUILD_WITHOUT_CBLAS "Do not build the C interface (CBLAS) to the BLAS functions" OFF) | |||||
| option(DYNAMIC_ARCH "Include support for multiple CPU targets, with automatic selection at runtime (x86/x86_64 only)" OFF) | |||||
| option(DYNAMIC_OLDER "Include specific support for older cpu models (Penryn,Dunnington,Atom,Nano,Opteron) with DYNAMIC_ARCH" OFF) | |||||
| option(BUILD_RELAPACK "Build with ReLAPACK (recursive implementation of several LAPACK functions on top of standard LAPACK)" OFF) | |||||
| # Add a prefix or suffix to all exported symbol names in the shared library. | |||||
| # Avoids conflicts with other BLAS libraries, especially when using | |||||
| # 64 bit integer interfaces in OpenBLAS. | |||||
| set(SYMBOLPREFIX "" CACHE STRING "Add a prefix to all exported symbol names in the shared library to avoid conflicts with other BLAS libraries" ) | |||||
| set(SYMBOLSUFFIX "" CACHE STRING "Add a suffix to all exported symbol names in the shared library, e.g. _64 for INTERFACE64 builds" ) | |||||
| ####### | ####### | ||||
| if(BUILD_WITHOUT_LAPACK) | if(BUILD_WITHOUT_LAPACK) | ||||
| set(NO_LAPACK 1) | set(NO_LAPACK 1) | ||||
| @@ -38,11 +43,13 @@ endif() | |||||
| ####### | ####### | ||||
| message(WARNING "CMake support is experimental. This will not produce the same Makefiles that OpenBLAS ships with. Only x86 support is currently available.") | |||||
| 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.") | |||||
| include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake") | include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake") | ||||
| include("${PROJECT_SOURCE_DIR}/cmake/system.cmake") | include("${PROJECT_SOURCE_DIR}/cmake/system.cmake") | ||||
| set(OpenBLAS_LIBNAME openblas${SUFFIX64_UNDERSCORE}) | |||||
| set(BLASDIRS interface driver/level2 driver/level3 driver/others) | set(BLASDIRS interface driver/level2 driver/level3 driver/others) | ||||
| if (NOT DYNAMIC_ARCH) | if (NOT DYNAMIC_ARCH) | ||||
| @@ -210,15 +217,84 @@ set_target_properties(${OpenBLAS_LIBNAME} PROPERTIES | |||||
| SOVERSION ${OpenBLAS_MAJOR_VERSION} | SOVERSION ${OpenBLAS_MAJOR_VERSION} | ||||
| ) | ) | ||||
| if (BUILD_SHARED_LIBS AND NOT ${SYMBOLPREFIX}${SYMBOLSUFIX} STREQUAL "") | |||||
| if (NOT DEFINED ARCH) | |||||
| set(ARCH_IN "x86_64") | |||||
| else() | |||||
| set(ARCH_IN ${ARCH}) | |||||
| endif() | |||||
| if (${CORE} STREQUAL "generic") | |||||
| set(ARCH_IN "GENERIC") | |||||
| endif () | |||||
| if (NOT DEFINED EXPRECISION) | |||||
| set(EXPRECISION_IN 0) | |||||
| else() | |||||
| set(EXPRECISION_IN ${EXPRECISION}) | |||||
| endif() | |||||
| if (NOT DEFINED NO_CBLAS) | |||||
| set(NO_CBLAS_IN 0) | |||||
| else() | |||||
| set(NO_CBLAS_IN ${NO_CBLAS}) | |||||
| endif() | |||||
| if (NOT DEFINED NO_LAPACK) | |||||
| set(NO_LAPACK_IN 0) | |||||
| else() | |||||
| set(NO_LAPACK_IN ${NO_LAPACK}) | |||||
| endif() | |||||
| if (NOT DEFINED NO_LAPACKE) | |||||
| set(NO_LAPACKE_IN 0) | |||||
| else() | |||||
| set(NO_LAPACKE_IN ${NO_LAPACKE}) | |||||
| endif() | |||||
| if (NOT DEFINED NEED2UNDERSCORES) | |||||
| set(NEED2UNDERSCORES_IN 0) | |||||
| else() | |||||
| set(NEED2UNDERSCORES_IN ${NEED2UNDERSCORES}) | |||||
| endif() | |||||
| if (NOT DEFINED ONLY_CBLAS) | |||||
| set(ONLY_CBLAS_IN 0) | |||||
| else() | |||||
| set(ONLY_CBLAS_IN ${ONLY_CBLAS}) | |||||
| endif() | |||||
| if (NOT DEFINED BU) | |||||
| set(BU _) | |||||
| endif() | |||||
| if (NOT ${SYMBOLPREFIX} STREQUAL "") | |||||
| message(STATUS "adding prefix ${SYMBOLPREFIX} to names of exported symbols in ${OpenBLAS_LIBNAME}") | |||||
| endif() | |||||
| if (NOT ${SYMBOLSUFFIX} STREQUAL "") | |||||
| message(STATUS "adding suffix ${SYMBOLSUFFIX} to names of exported symbols in ${OpenBLAS_LIBNAME}") | |||||
| endif() | |||||
| add_custom_command(TARGET ${OpenBLAS_LIBNAME} POST_BUILD | |||||
| 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 | |||||
| COMMAND objcopy -v --redefine-syms ${PROJECT_BINARY_DIR}/objcopy.def ${PROJECT_BINARY_DIR}/lib/lib${OpenBLAS_LIBNAME}.so | |||||
| COMMENT "renaming symbols" | |||||
| ) | |||||
| endif() | |||||
| # Install project | # Install project | ||||
| # Install libraries | # Install libraries | ||||
| install(TARGETS ${OpenBLAS_LIBNAME} | install(TARGETS ${OpenBLAS_LIBNAME} | ||||
| EXPORT "OpenBLASTargets" | |||||
| EXPORT "OpenBLAS${SUFFIX64}Targets" | |||||
| RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||||
| ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) | ||||
| # Install headers | |||||
| set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/openblas${SUFFIX64}) | |||||
| set(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) | |||||
| message(STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR}") | message(STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR}") | ||||
| set(OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR}/openblas_config.h) | set(OPENBLAS_CONFIG_H ${CMAKE_BINARY_DIR}/openblas_config.h) | ||||
| @@ -266,29 +342,31 @@ if(NOT NO_LAPACKE) | |||||
| ADD_CUSTOM_TARGET(genlapacke | ADD_CUSTOM_TARGET(genlapacke | ||||
| 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" | 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" | ||||
| ) | ) | ||||
| install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | |||||
| install (FILES ${CMAKE_BINARY_DIR}/lapacke_mangling.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openblas${SUFFIX64}) | |||||
| endif() | endif() | ||||
| include(FindPkgConfig QUIET) | include(FindPkgConfig QUIET) | ||||
| if(PKG_CONFIG_FOUND) | if(PKG_CONFIG_FOUND) | ||||
| configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas.pc @ONLY) | |||||
| install (FILES ${PROJECT_BINARY_DIR}/openblas.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) | |||||
| configure_file(${PROJECT_SOURCE_DIR}/cmake/openblas.pc.in ${PROJECT_BINARY_DIR}/openblas${SUFFIX64}.pc @ONLY) | |||||
| install (FILES ${PROJECT_BINARY_DIR}/openblas${SUFFIX64}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/) | |||||
| endif() | endif() | ||||
| # GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share". | # GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share". | ||||
| set(PN OpenBLAS) | set(PN OpenBLAS) | ||||
| set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}") | |||||
| set(CMAKECONFIG_INSTALL_DIR "share/cmake/${PN}${SUFFIX64}") | |||||
| configure_package_config_file(cmake/${PN}Config.cmake.in | configure_package_config_file(cmake/${PN}Config.cmake.in | ||||
| "${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake" | |||||
| "${CMAKE_CURRENT_BINARY_DIR}/${PN}${SUFFIX64}Config.cmake" | |||||
| INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | ||||
| write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake | write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake | ||||
| VERSION ${${PN}_VERSION} | VERSION ${${PN}_VERSION} | ||||
| COMPATIBILITY AnyNewerVersion) | COMPATIBILITY AnyNewerVersion) | ||||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake | |||||
| ${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake | |||||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}${SUFFIX64}Config.cmake | |||||
| DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | |||||
| install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake | |||||
| RENAME ${PN}${SUFFIX64}ConfigVersion.cmake | |||||
| DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | ||||
| install(EXPORT "${PN}Targets" | |||||
| NAMESPACE "${PN}::" | |||||
| install(EXPORT "${PN}${SUFFIX64}Targets" | |||||
| NAMESPACE "${PN}${SUFFIX64}::" | |||||
| DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | DESTINATION ${CMAKECONFIG_INSTALL_DIR}) | ||||