From 3425a4986d413060c1ab483884de5403a0a72aa7 Mon Sep 17 00:00:00 2001 From: scivision Date: Mon, 27 May 2024 17:33:14 -0400 Subject: [PATCH] scalapack: submodule if needed --- .github/workflows/ci_build.yml | 7 ++- .gitmodules | 3 ++ cmake/GitSubmodule.cmake | 94 ++++++++++++++++++++++++++++++++++ cmake/libraries.json | 4 -- cmake/scalapack.cmake | 63 ++--------------------- scalapack | 1 + 6 files changed, 106 insertions(+), 66 deletions(-) create mode 100644 .gitmodules create mode 100644 cmake/GitSubmodule.cmake create mode 160000 scalapack diff --git a/.github/workflows/ci_build.yml b/.github/workflows/ci_build.yml index fa755ee..9d7a6e1 100644 --- a/.github/workflows/ci_build.yml +++ b/.github/workflows/ci_build.yml @@ -16,7 +16,10 @@ on: jobs: linux: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + env: + CC: gcc-13 + FC: gfortran-13 steps: - uses: actions/checkout@v4 @@ -24,7 +27,7 @@ jobs: - name: Install prereqs run: | sudo apt update - sudo apt install --no-install-recommends libopenmpi-dev openmpi-bin + sudo apt install --no-install-recommends libopenmpi-dev openmpi-bin liblapack-dev - name: configure run: cmake --preset default diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9e991ff --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "scalapack"] + path = scalapack + url = https://github.com/scivision/scalapack.git diff --git a/cmake/GitSubmodule.cmake b/cmake/GitSubmodule.cmake new file mode 100644 index 0000000..10cdfde --- /dev/null +++ b/cmake/GitSubmodule.cmake @@ -0,0 +1,94 @@ +# else it's an offline archive +if(IS_DIRECTORY ${PROJECT_SOURCE_DIR}/.git) + find_package(Git REQUIRED) +endif() + +function(git_submodule submod_dir) +# get/update Git submodule directory to CMake, assuming the +# Git submodule directory is a CMake project. + +# EXISTS, do not use IS_DIRECTORY as in submodule .git is a file not a directory +if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git) + message(DEBUG "${PROJECT_SOURCE_DIR} is not a Git repository, skipping submodule ${submod_dir}") + return() +endif() + +if(EXISTS ${submod_dir}/CMakeLists.txt) + return() +endif() + +execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${submod_dir} +WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} +RESULT_VARIABLE err) + +if(NOT err EQUAL 0) + message(FATAL_ERROR "${submod_dir} Git submodule failed to retrieve.") +endif() + +endfunction() + + +function(report_submodule submod_dir) + # get the following information for the Git submodule + # git remote -v + # git status --porcelain + # git commit hash + + if(NOT EXISTS ${submod_dir}/.git) + message(VERBOSE "${submod_dir} is not a Git submodule, skipping}") + return() + endif() + + set(git_remote "origin") + # Git default remote name + + execute_process(COMMAND ${GIT_EXECUTABLE} -C ${submod_dir} remote get-url ${git_remote} + OUTPUT_VARIABLE r + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL 0) + message(STATUS "Git remote failed for ${submod_dir}") + return() + endif() + + if(r MATCHES "@") + # remove token from remote URL + string(REGEX REPLACE "://[^@]+@" "://" r "${r}") + endif() + + execute_process(COMMAND ${GIT_EXECUTABLE} -C ${submod_dir} status --porcelain + OUTPUT_VARIABLE p + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL 0) + message(STATUS "Git status failed for ${submod_dir}") + return() + endif() + + string(LENGTH "${p}" p_len) + if(p_len EQUAL 0) + set(porcelain "clean") + else() + set(porcelain "dirty") + endif() + + execute_process(COMMAND ${GIT_EXECUTABLE} -C ${submod_dir} rev-parse --short HEAD + OUTPUT_VARIABLE h + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE ret + ) + + if(NOT ret EQUAL 0) + message(STATUS "Git rev-parse failed for ${submod_dir}") + return() + endif() + + get_filename_component(name ${submod_dir} NAME) + + message(STATUS "${name} remote: ${r} ${porcelain} ${h}") + +endfunction() diff --git a/cmake/libraries.json b/cmake/libraries.json index ecd001b..e5ae7fb 100644 --- a/cmake/libraries.json +++ b/cmake/libraries.json @@ -2,10 +2,6 @@ "lapack": { "git": "https://github.com/Reference-LAPACK/lapack/archive/refs/tags/v3.12.0.tar.gz" }, - "scalapack": { - "git": "https://github.com/scivision/scalapack.git", - "tag": "7d2a199b91187f92c553179e22f76f42bc813728" - }, "metis": { "git": "https://github.com/scivision/METIS.git", "tag": "v5.1.0.3" diff --git a/cmake/scalapack.cmake b/cmake/scalapack.cmake index f4d1a70..5d45b53 100644 --- a/cmake/scalapack.cmake +++ b/cmake/scalapack.cmake @@ -1,6 +1,3 @@ -include(ExternalProject) -include(GNUInstallDirs) - if(find) if(NOT DEFINED SCALAPACK_VENDOR) @@ -31,60 +28,6 @@ if(SCALAPACK_FOUND) return() endif() -set(scalapack_cmake_args --DBUILD_SINGLE:BOOL=${BUILD_SINGLE} --DBUILD_DOUBLE:BOOL=${BUILD_DOUBLE} --DBUILD_COMPLEX:BOOL=${BUILD_COMPLEX} --DBUILD_COMPLEX16:BOOL=${BUILD_COMPLEX16} --DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} --DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX} --DCMAKE_C_COMPILER:PATH=${CMAKE_C_COMPILER} --DCMAKE_Fortran_COMPILER:PATH=${CMAKE_Fortran_COMPILER} --DBUILD_TESTING:BOOL=off --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_TLS_VERIFY:BOOL=${CMAKE_TLS_VERIFY} -) - -file(READ ${CMAKE_CURRENT_LIST_DIR}/libraries.json json) - -string(JSON scalapack_url GET ${json} scalapack git) -string(JSON scalapack_tag GET ${json} scalapack tag) - -set(SCALAPACK_INCLUDE_DIRS ${CMAKE_INSTALL_FULL_INCLUDEDIR}) -file(MAKE_DIRECTORY ${SCALAPACK_INCLUDE_DIRS}) -if(NOT IS_DIRECTORY ${SCALAPACK_INCLUDE_DIRS}) - message(FATAL_ERROR "Could not create directory: ${SCALAPACK_INCLUDE_DIRS}") -endif() - -if(BUILD_SHARED_LIBS) - set(SCALAPACK_LIBRARIES ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}scalapack${CMAKE_SHARED_LIBRARY_SUFFIX} - ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}blacs${CMAKE_SHARED_LIBRARY_SUFFIX} - ) -else() - set(SCALAPACK_LIBRARIES ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}scalapack${CMAKE_STATIC_LIBRARY_SUFFIX} - ${CMAKE_INSTALL_FULL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}blacs${CMAKE_STATIC_LIBRARY_SUFFIX} - ) -endif() - -ExternalProject_Add(scalapack -GIT_REPOSITORY ${scalapack_url} -GIT_TAG ${scalapack_tag} -GIT_SHALLOW true -CMAKE_ARGS ${scalapack_cmake_args} -TEST_COMMAND "" -BUILD_BYPRODUCTS ${SCALAPACK_LIBRARIES} -CONFIGURE_HANDLED_BY_BUILD true -USES_TERMINAL_DOWNLOAD true -USES_TERMINAL_UPDATE true -USES_TERMINAL_PATCH true -USES_TERMINAL_CONFIGURE true -USES_TERMINAL_BUILD true -USES_TERMINAL_INSTALL true -USES_TERMINAL_TEST true -) - -add_library(SCALAPACK::SCALAPACK INTERFACE IMPORTED GLOBAL) -target_include_directories(SCALAPACK::SCALAPACK INTERFACE ${SCALAPACK_INCLUDE_DIRS}) -target_link_libraries(SCALAPACK::SCALAPACK INTERFACE ${SCALAPACK_LIBRARIES}) - -add_dependencies(SCALAPACK::SCALAPACK scalapack) +include(${CMAKE_CURRENT_LIST_DIR}/GitSubmodule.cmake) +git_submodule(${PROJECT_SOURCE_DIR}/scalapack) +add_subdirectory(${PROJECT_SOURCE_DIR}/scalapack) diff --git a/scalapack b/scalapack new file mode 160000 index 0000000..acf286b --- /dev/null +++ b/scalapack @@ -0,0 +1 @@ +Subproject commit acf286b783d53f73a42ec219ead74357e0b34501