diff --git a/CMakeLists.txt b/CMakeLists.txt index ae9096a24abce26812746277549f76bf9361a18f..4e0be43567e0054943e0eaf262bf4d0f94297fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,13 +156,15 @@ endif() message("Checking Armadillo dependencies") find_package(LAPACK) find_package(BLAS) + set(ARMA_LIBS "") if(NOT LAPACK_FOUND AND NOT BLAS_FOUND) find_package(OpenBLAS) if(NOT OpenBLAS_FOUND AND ALLOW_DEPENDENCIES_DOWNLOAD) # Download and build OpenBLAS locally - message("LAPACK nor BLAS were found - OpenBLAS will be downloaded and built.") + message("Nor LAPACK nor BLAS were found - OpenBLAS will be downloaded and built.") include(DownloadOpenBLAS) + find_package(OpenBLAS) endif() endif() set(ARMA_LIBS "${OpenBLAS_LIBRARIES}") @@ -173,14 +175,14 @@ if(NOT ARMADILLO_FOUND AND ALLOW_DEPENDENCIES_DOWNLOAD) message("Armadillo will be downloaded and compiled locally in 'external_dependencies folder.") include(DownloadArmadillo) - if(NOT LAPACK_FOUND AND NOT BLAS_FOUND) - target_link_libraries( - armadillo - - PUBLIC - openblas - ) - endif() +# if(NOT LAPACK_FOUND AND NOT BLAS_FOUND) +# target_link_libraries( +# armadillo +# +# PUBLIC +# openblas +# ) +# endif() endif() #---------------------------------------------------# diff --git a/DownloadOpenBLAS.cmake b/DownloadOpenBLAS.cmake index 75e9bb62ee4fcfe4b7be7666fb6450895586ab27..9a5bae516cd6ef06068001a7519186d80b5d4205 100644 --- a/DownloadOpenBLAS.cmake +++ b/DownloadOpenBLAS.cmake @@ -15,33 +15,36 @@ FetchContent_Declare( set(FETCHCONTENT_QUIET FALSE) -FetchContent_Populate(OpenBLAS) +if(NOT OpenBLAS_POPULATED) + FetchContent_Populate(OpenBLAS) + #add_subdirectory(${OPENBLAS_LOCAL_PATH} ${OPENBLAS_LOCAL_PATH}/build) +endif() ################## # Build OpenBLAS # ################## -#execute_process( -# COMMAND cmake -j ${N_CORES} . -# WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH} -# RESULT_VARIABLE rv -#) -#if(NOT rv STREQUAL "0") -# message("OpenBLAS build: cmake .: ${rv}") -#endif() -# -## Build library -#execute_process( -# COMMAND cmake --build . -j ${N_CORES} --config Release -# WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH} -# RESULT_VARIABLE rv -#) -#if(NOT rv STREQUAL "0") -# message("OpenBLAS build: cmake --build . -j ${N_CORES}: ${rv}") -#endif() +execute_process( + COMMAND cmake -j ${N_CORES} . + WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH} + RESULT_VARIABLE rv +) +if(NOT rv STREQUAL "0") + message("OpenBLAS build: cmake .: ${rv}") +endif() + +# Build library +execute_process( + COMMAND cmake --build . -j ${N_CORES} --config Release + WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH} + RESULT_VARIABLE rv +) +if(NOT rv STREQUAL "0") + message("OpenBLAS build: cmake --build: ${rv}") +endif() find_package(OpenBLAS) -# -#if(NOT OpenBLAS_FOUND) -# message(FATAL_ERROR "OpenBLAS was not downloaded successfully!") -#endif() + +if(NOT OpenBLAS_FOUND) + message(FATAL_ERROR "OpenBLAS was not downloaded successfully!") +endif() diff --git a/FindOpenBLAS.cmake b/FindOpenBLAS.cmake index 7b698e5a80ff0387f69afbc8c9eefb14ae60f014..8e3c4b755e90b90d005a4764e682c1af5b6161af 100644 --- a/FindOpenBLAS.cmake +++ b/FindOpenBLAS.cmake @@ -19,22 +19,18 @@ FIND_PATH( include/x86_64-linux-gnu ) -#option(LOCAL OFF) IF(${OpenBLAS_INCLUDE_DIR} MATCHES "^.*external_dependencies.*$") - message("OpenBLAS is downloaded locally - the library will be built when needed.") - set(LOCAL ON) - set(TMP "") - string(REGEX REPLACE "/include" "" TMP ${OpenBLAS_INCLUDE_DIR}) - add_subdirectory(${TMP} ${TMP}) -endif() - -if(LOCAL) # If OpenBLAS is downloaded locally, the library will be compiled during build-time INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS( OpenBLAS "OpenBLAS was NOT found!" OpenBLAS_INCLUDE_DIR) + + if(OpenBLAS_FOUND) + message(STATUS "OpenBLAS is downloaded locally: ${OpenBLAS_INCLUDE_DIR}") + endif() + else() FIND_LIBRARY( @@ -67,11 +63,17 @@ else() OpenBLAS_INCLUDE_DIR OpenBLAS_LIBRARIES ) + + if(OpenBLAS_FOUND) + MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIBRARIES}") + MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") + endif() + endif() -IF (OpenBLAS_FOUND) - MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIBRARIES}") - MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") -ELSE() - MESSAGE("Could not find OpenBLAS") -ENDIF() +#IF (OpenBLAS_LIBRARIES) +## MESSAGE(STATUS "Found OpenBLAS libraries: ${OpenBLAS_LIBRARIES}") +# MESSAGE(STATUS "Found OpenBLAS include: ${OpenBLAS_INCLUDE_DIR}") +#ELSE() +# MESSAGE("Could not find OpenBLAS") +#ENDIF()