Commit patch sent by Sébastien Fabbro to enable LAPACKE built without LAPACK.
authorjulie <julielangou@users.noreply.github.com>
Thu, 26 Apr 2012 13:22:53 +0000 (13:22 +0000)
committerjulie <julielangou@users.noreply.github.com>
Thu, 26 Apr 2012 13:22:53 +0000 (13:22 +0000)
The patch has been modified a little by Julie as there were some minors problems.
This also fix the BUILD_TESTING=OFF option problem reported by Marcin on lapack mailing list.

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
TESTING/EIG/CMakeLists.txt
TESTING/LIN/CMakeLists.txt
TESTING/MATGEN/CMakeLists.txt
lapacke/CMakeLists.txt
lapacke/example/CMakeLists.txt

index 1c4f7a8b731ef8fe7d4bb536554c00ffab40d799..9fec635412f73dad7eaa6b3b2f969458ccaaf28f 100644 (file)
@@ -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)
index 9ef205fcfe32206ad9aa6a07b19736e2d6af5f0b..05b11fb60e5101c266e792220b5b6915631a8899 100644 (file)
@@ -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)
index af4947a629036dc825401913266a041882259121..085dd08630098d4ca03b2ce5eafbe9c92cc4ae07 100644 (file)
@@ -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)
index 4cbaf4686bed952bbb3c79efb2ac79db084b6b6f..55258ddd0be3ab53506f1a5bb5f225ef612d57b6 100644 (file)
@@ -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)
index 0e43638964cf074723968d5ea8649ff12d02a6b2..fc702758292c8c0bb057a7b09f4b305a109c15ca 100644 (file)
@@ -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)
 
index 4e1a4c9eb817d2c9fbbe0c150a9d1d3b856b3667..9e00c94efc2a84a4512ccba7b13dcd59bfc4b49b 100644 (file)
@@ -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)