From f6b3a42a1da0414470a9d50f7992b15eeb529059 Mon Sep 17 00:00:00 2001 From: julie Date: Thu, 26 Apr 2012 13:22:53 +0000 Subject: [PATCH] =?utf8?q?Commit=20patch=20sent=20by=20S=C3=A9bastien=20Fa?= =?utf8?q?bbro=20to=20enable=20LAPACKE=20built=20without=20LAPACK.=20The?= =?utf8?q?=20patch=20has=20been=20modified=20a=20little=20by=20Julie=20as?= =?utf8?q?=20there=20were=20some=20minors=20problems.=20This=20also=20fix?= =?utf8?q?=20the=20BUILD=5FTESTING=3DOFF=20option=20problem=20reported=20b?= =?utf8?q?y=20Marcin=20on=20lapack=20mailing=20list.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit From Sébastien: Here is a patch to compile lapacke with CMake using an already existing optimized lapack library instead of forcing the build of the included one in the tar ball. It applies to the latest lapack svn trunk. --- CMakeLists.txt | 84 ++++++++++++++++++++++++++-------- TESTING/EIG/CMakeLists.txt | 2 +- TESTING/LIN/CMakeLists.txt | 2 +- TESTING/MATGEN/CMakeLists.txt | 6 +-- lapacke/CMakeLists.txt | 6 +-- lapacke/example/CMakeLists.txt | 4 +- 6 files changed, 76 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c4f7a8b..9fec6354 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,10 +94,6 @@ set(PKG_CONFIG_DIR ${libdir}/pkgconfig) # Precision to build # By default all precisions are generated -option(BUILD_SINGLE "Build LAPACK Single Precision" ON) -option(BUILD_DOUBLE "Build LAPACK Double Precision" ON) -option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON) -option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON) # -------------------------------------------------- # Subdirectories that need to be processed @@ -147,7 +143,51 @@ if (USE_XBLAS) find_library(XBLAS_LIBRARY NAMES xblas) endif(USE_XBLAS) -add_subdirectory(SRC) +option(USE_OPTIMIZED_LAPACK "Whether or not to use an optimized LAPACK library instead of included netlib LAPACK" OFF) + +# User did not provide a LAPACK Library but specified to search for one +if( USE_OPTIMIZED_LAPACK ) + find_package( LAPACK ) +endif (USE_OPTIMIZED_LAPACK) + +# Check the usage of the user provided or automatically found LAPACK libraries +if(LAPACK_LIBRARIES) + include(CheckFortranFunctionExists) + set(CMAKE_REQUIRED_LIBRARIES ${LAPACK_LIBRARIES}) + # Check if new routine of 3.4.0 is in LAPACK_LIBRARIES + CHECK_FORTRAN_FUNCTION_EXISTS("dgeqrt" LATESTLAPACK_FOUND) + unset( CMAKE_REQUIRED_LIBRARIES ) + if(LATESTLAPACK_FOUND) + message(STATUS "--> LAPACK supplied by user is WORKING, will use ${LAPACK_LIBRARIES}.") + else(LAPACK_FOUND) + message(ERROR "--> LAPACK supplied by user is not WORKING or is older than LAPACK 3.4.0, CANNOT USE ${LAPACK_LIBRARIES}.") + message(ERROR "--> Will use REFERENCE LAPACK (by default)") + message(ERROR "--> Or Correct your LAPACK_LIBRARIES entry ") + message(ERROR "--> Or Consider checking USE_OPTIMIZED_LAPACK") + endif(LATESTLAPACK_FOUND) +endif (LAPACK_LIBRARIES) + +# Neither user specified or optimized LAPACK libraries can be used +if(NOT LATESTLAPACK_FOUND) + message(STATUS "Using supplied NETLIB LAPACK implementation") + set( LAPACK_LIBRARIES lapack ) + option(BUILD_SINGLE "Build LAPACK Single Precision" ON) + option(BUILD_DOUBLE "Build LAPACK Double Precision" ON) + option(BUILD_COMPLEX "Build LAPACK Complex Precision" ON) + option(BUILD_COMPLEX16 "Build LAPACK Double Complex Precision" ON) + add_subdirectory(SRC) +else() + set( CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" + CACHE STRING "Linker flags for executables" FORCE) + set( CMAKE_MODULE_LINKER_FLAGS + "${CMAKE_MODULE_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" + CACHE STRING "Linker flags for modules" FORCE) + set( CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} ${LAPACK_LINKER_FLAGS}" + CACHE STRING "Linker flags for shared libs" FORCE) +endif( NOT LATESTLAPACK_FOUND ) + if(BUILD_TESTING) add_subdirectory(TESTING) endif(BUILD_TESTING) @@ -155,11 +195,15 @@ endif(BUILD_TESTING) # -------------------------------------------------- # LAPACKE option(LAPACKE "Build LAPACKE" OFF) + # LAPACKE has also the interface to some routines from tmglib, # if LAPACKE_WITH_TMG is selected, we need to add those routines to LAPACKE option(LAPACKE_WITH_TMG "Build LAPACKE with tmglib routines" OFF) if (LAPACKE_WITH_TMG) option(LAPACKE "Build LAPACKE" ON) + if(NOT BUILD_TESTING) + add_subdirectory(TESTING/MATGEN) + endif(NOT BUILD_TESTING) endif(LAPACKE_WITH_TMG) if(LAPACKE) @@ -202,19 +246,23 @@ OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF ) OPTION(BUILD_STATIC_LIBS "Build static libraries" ON ) #OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON ) -if( NOT BLAS_FOUND ) - if(LAPACKE) - export(TARGETS blas lapack tmglib lapacke FILE lapack-targets.cmake) - else (LAPACKE) - export(TARGETS blas lapack tmglib FILE lapack-targets.cmake) - endif(LAPACKE) -else( NOT BLAS_FOUND ) - if(LAPACKE) - export(TARGETS lapack tmglib lapacke FILE lapack-targets.cmake) - else (LAPACKE) - export(TARGETS lapack tmglib FILE lapack-targets.cmake) - endif(LAPACKE) -endif( NOT BLAS_FOUND ) +if(NOT BLAS_FOUND) + set(ALL_TARGETS ${ALL_TARGETS} blas) +endif(NOT BLAS_FOUND) + +if(NOT LATESTLAPACK_FOUND) + set(ALL_TARGETS ${ALL_TARGETS} lapack) +endif(NOT LATESTLAPACK_FOUND) + +if(BUILD_TESTING OR LAPACKE_WITH_TMG) + set(ALL_TARGETS ${ALL_TARGETS} tmglib) +endif(BUILD_TESTING OR LAPACKE_WITH_TMG) + +if(LAPACKE) + set(ALL_TARGETS ${ALL_TARGETS} lapacke) +endif(LAPACKE) + +export(TARGETS ${ALL_TARGETS} FILE lapack-targets.cmake) configure_file(${LAPACK_SOURCE_DIR}/CMAKE/lapack-config-version.cmake.in ${LAPACK_BINARY_DIR}/lapack-config-version.cmake @ONLY) diff --git a/TESTING/EIG/CMakeLists.txt b/TESTING/EIG/CMakeLists.txt index 9ef205fc..05b11fb6 100644 --- a/TESTING/EIG/CMakeLists.txt +++ b/TESTING/EIG/CMakeLists.txt @@ -119,7 +119,7 @@ set(ZEIGTST zchkee.f macro(add_eig_executable name ) add_executable(${name} ${ARGN}) - target_link_libraries(${name} tmglib lapack ) + target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES}) endmacro(add_eig_executable) if (BUILD_SINGLE) diff --git a/TESTING/LIN/CMakeLists.txt b/TESTING/LIN/CMakeLists.txt index af4947a6..085dd086 100644 --- a/TESTING/LIN/CMakeLists.txt +++ b/TESTING/LIN/CMakeLists.txt @@ -193,7 +193,7 @@ set(ZLINTSTRFP zchkrfp.f zdrvrfp.f zdrvrf1.f zdrvrf2.f zdrvrf3.f zdrvrf4.f zerr macro(add_lin_executable name ) add_executable(${name} ${ARGN}) - target_link_libraries(${name} tmglib lapack) + target_link_libraries(${name} tmglib ${LAPACK_LIBRARIES}) endmacro(add_lin_executable) IF(BUILD_SINGLE) diff --git a/TESTING/MATGEN/CMakeLists.txt b/TESTING/MATGEN/CMakeLists.txt index 4cbaf468..55258ddd 100644 --- a/TESTING/MATGEN/CMakeLists.txt +++ b/TESTING/MATGEN/CMakeLists.txt @@ -64,12 +64,12 @@ if(BUILD_COMPLEX16) set(ALLOBJ ${ALLOBJ} ${ZMATGEN} ${DZATGEN}) endif() -list(REMOVE_DUPLICATES ALLOBJ) - if (NOT ALLOBJ) set(ALLOBJ ${SMATGEN} ${CMATGEN} ${SCATGEN} ${DMATGEN} ${ZMATGEN} ${DZATGEN}) +else() + list(REMOVE_DUPLICATES ALLOBJ) endif() add_library(tmglib ${ALLOBJ} ) -target_link_libraries(tmglib lapack) +target_link_libraries(tmglib ${LAPACK_LIBRARIES}) lapack_install_library(tmglib) diff --git a/lapacke/CMakeLists.txt b/lapacke/CMakeLists.txt index 0e436389..fc702758 100644 --- a/lapacke/CMakeLists.txt +++ b/lapacke/CMakeLists.txt @@ -45,14 +45,14 @@ append_subdir_files(UTILS_OBJ "utils") if (USE_XBLAS) add_library(lapacke ${SRC_OBJ} ${SRCX_OBJ} ${UTILS_OBJ}) - target_link_libraries(lapacke lapack ${BLAS_LIBRARIES} ${XBLAS_LIBRARY}) + target_link_libraries(lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${XBLAS_LIBRARY}) else (USE_XBLAS) if (LAPACKE_WITH_TMG) add_library(lapacke ${SRC_OBJ} ${MATGEN_OBJ} ${UTILS_OBJ}) - target_link_libraries(lapacke tmglib lapack ${BLAS_LIBRARIES} ) + target_link_libraries(lapacke tmglib ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) else (LAPACKE_WITH_TMG) add_library(lapacke ${SRC_OBJ} ${UTILS_OBJ}) - target_link_libraries(lapacke lapack ${BLAS_LIBRARIES} ) + target_link_libraries(lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) endif(LAPACKE_WITH_TMG) endif(USE_XBLAS) diff --git a/lapacke/example/CMakeLists.txt b/lapacke/example/CMakeLists.txt index 4e1a4c9e..9e00c94e 100644 --- a/lapacke/example/CMakeLists.txt +++ b/lapacke/example/CMakeLists.txt @@ -1,8 +1,8 @@ add_executable(xexample_DGESV_rowmajor example_DGESV_rowmajor.c) add_executable(xexample_ZGESV_rowmajor example_ZGESV_rowmajor.c) -target_link_libraries(xexample_DGESV_rowmajor lapacke lapack ${BLAS_LIBRARIES}) -target_link_libraries(xexample_ZGESV_rowmajor lapacke lapack ${BLAS_LIBRARIES}) +target_link_libraries(xexample_DGESV_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) +target_link_libraries(xexample_ZGESV_rowmajor lapacke ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) add_test(example_DGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_DGESV_rowmajor) add_test(example_ZGESV_rowmajor ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/xexample_ZGESV_rowmajor) -- 2.34.1