From 3d6151479b21c4de3d65e093a52075cd61dbd4ac Mon Sep 17 00:00:00 2001 From: Nicolas Bock Date: Mon, 13 Mar 2017 13:48:24 -0600 Subject: [PATCH] Add proper pkg-config detection of bml library The bml library is installed with a pkg-config file. This patch searches for this file and uses the settings in it to configure bml library locations. --- CMakeLists.txt | 74 ++++++++++++++++++++++++++++++++++++++ examples/CMakeLists.txt | 2 -- src/CMakeLists.txt | 79 ++++++++++++++++++++--------------------- tests/CMakeLists.txt | 1 - 4 files changed, 113 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c03d33b..26365577 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,80 @@ if(CMAKE_Fortran_FLAGS STRGREATER "") message(STATUS "Using user supplied Fortran compiler flags ${CMAKE_Fortran_FLAGS}") endif() +pkg_check_modules(BML bml REQUIRED) +list(APPEND LINK_LIBRARIES ${BML_LDFLAGS}) + +set(BLAS_VENDOR "" + CACHE STRING "If set, the preferred BLAS/LAPACK vendor. Possible choices: {Intel,MKL,ACML}") + +if(BLAS_VENDOR STREQUAL "Intel" OR BLAS_VENDOR STREQUAL "MKL") + message(STATUS "Attempting to use Intel's BLAS/LAPACK (MKL)") + if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + if(BML_OPENMP) + set(BLAS_LIBRARIES "-L${MKLROOT}/lib/intel64" + -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -lm) + else() + set(BLAS_LIBRARIES "-L${MKLROOT}/lib/intel64" + -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -lpthread -lm) + endif() + else() + if(BML_OPENMP) + set(BLAS_LIBRARIES -Wl,--no-as-needed "-L${MKLROOT}/lib/intel64" + -lmkl_lapack95_lp64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lmkl_gnu_thread -lmkl_core -ldl -lpthread -lm) + else() + set(BLAS_LIBRARIES -Wl,--no-as-needed "-L${MKLROOT}/lib/intel64" + -lmkl_lapack95_lp64 -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lmkl_sequential -lmkl_core -lpthread -lm) + endif() + endif() + set(BLAS_FOUND TRUE) + set(LAPACK_FOUND TRUE) +elseif(BLAS_VENDOR STREQUAL "ACML") + if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") + if(BML_OPENMP) + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/ifort64_mp/lib" -lacml_mp) + else() + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/ifort64/lib" -lacml) + endif() + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" + OR CMAKE_Fortran_COMPILER_ID STREQUAL "PathScale") + if(BML_OPENMP) + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/gfortran64_mp/lib" -lacml_mp) + else() + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/gfortran64/lib" -lacml) + endif() + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI") + if(OPENMP) + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/pgi64_mp/lib" -lacml_mp) + else() + set(BLAS_LIBRARIES "-L$ENV{ACML_DIR}/pgi64/lib" -lacml) + endif() + endif() + set(BLAS_FOUND TRUE) + set(LAPACK_FOUND TRUE) +elseif(BLAS_VENDOR STREQUAL "GNU") + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + set(BLAS_LIBRARIES -llapack -lblas) + endif() + set(BLAS_FOUND TRUE) + set(LAPACK_FOUND TRUE) +endif() + +if(NOT (BLAS_LIBRARIES OR BLAS_FOUND)) + include(FindBLAS) + if(NOT BLAS_FOUND) + message(FATAL_ERROR "Can not find suitable BLAS library") + endif() +endif() + +if(NOT (LAPACK_LIBRARIES OR LAPACK_FOUND)) + include(FindLAPACK) + if(NOT LAPACK_FOUND) + message(FATAL_ERROR "Can not find suitable LAPACK library") + endif() +endif() + +list(APPEND LINK_LIBRARIES ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES}) + set(PROGRESS_OPENMP TRUE CACHE BOOL "Whether to compile with OpenMP support") if(PROGRESS_OPENMP) include(FindOpenMP) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0787de34..8496c71b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,8 +3,6 @@ include_directories(${CMAKE_SOURCE_DIR}/tests/src) include_directories(${CMAKE_SOURCE_DIR}/build/src) include_directories(${BML_INCLUDEDIR}) -list(APPEND LINK_LIBRARIES "-L${BML_LIBDIR} -l${BML_LIBRARIES}") - function(progress_example myexample path_to_example) add_executable(${myexample} ${path_to_example}) target_link_libraries(${myexample} progress ${LINK_LIBRARIES}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3eaaea7c..b1ebc182 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,44 +57,43 @@ install(TARGETS progress LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES - charges_mod.mod - densitymatrix_mod.mod - dos_mod.mod - extras_mod.mod - genz_mod.mod - graph_mod.mod - graph_sp2parser_mod.mod - homolumo_mod.mod - initmatrices_mod.mod - kernelparser_mod.mod - nonortho_mod.mod - normalize_mod.mod - openfiles_mod.mod - parallel_mod.mod - partition_mod.mod - progress_mod.mod - ptable_mod.mod - pulaycomponent_mod.mod - pulaymixer_mod.mod - response_mod.mod - sp2_fermi_mod.mod - sp2_mod.mod - sp2parser_mod.mod - subgraphloop_mod.mod - system_mod.mod - timer_mod.mod - xlbo_mod.mod - # LATTE modes - coulomb_latte_mod.mod - latteparser_latte_mod.mod - ham_latte_mod.mod - hsderivative_latte_mod.mod - huckel_latte_mod.mod - md_latte_mod.mod - neighborlist_latte_mod.mod - nonorthocoulombforces_latte_mod.mod - slaterkosterforce_latte_mod.mod - physmathconst_latte_mod.mod - ppot_latte_mod.mod - tbparams_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/charges_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/densitymatrix_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/dos_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/extras_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/genz_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/graph_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/graph_sp2parser_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/homolumo_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/initmatrices_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/kernelparser_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/nonortho_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/normalize_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/openfiles_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/parallel_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/partition_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/progress_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/ptable_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/pulaycomponent_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/pulaymixer_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/response_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/sp2_fermi_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/sp2_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/sp2parser_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/subgraphloop_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/system_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/timer_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/xlbo_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/coulomb_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/latteparser_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/ham_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/hsderivative_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/huckel_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/md_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/neighborlist_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/nonorthocoulombforces_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/slaterkosterforce_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/physmathconst_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/ppot_latte_mod.mod + ${CMAKE_CURRENT_BINARY_DIR}/tbparams_latte_mod.mod DESTINATION include) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db198d22..ab73638a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable(main src/main.F90 src/test_subgraphloop.F90) -list(APPEND LINK_LIBRARIES "-L${BML_LIBDIR} -l${BML_LIBRARIES}") target_link_libraries(main progress ${LINK_LIBRARIES}) set_target_properties(main