Skip to content

Commit

Permalink
scalapack: submodule if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 27, 2024
1 parent 8fedcf5 commit 0c45c42
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 63 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ on:
jobs:

linux:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
CC: gcc-13
FC: gfortran-13

steps:
- uses: actions/checkout@v4

- 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
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "scalapack"]
path = scalapack
url = https://github.com/scivision/scalapack.git
94 changes: 94 additions & 0 deletions cmake/GitSubmodule.cmake
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 0 additions & 4 deletions cmake/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
61 changes: 4 additions & 57 deletions cmake/scalapack.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
include(ExternalProject)
include(GNUInstallDirs)

if(find)

if(NOT DEFINED SCALAPACK_VENDOR)
Expand Down Expand Up @@ -31,60 +28,10 @@ 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()
include(${CMAKE_CURRENT_LIST_DIR}/GitSubmodule.cmake)
git_submodule(${PROJECT_SOURCE_DIR}/scalapack)
add_subdirectory(${PROJECT_SOURCE_DIR}/scalapack)

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)
target_link_libraries(SCALAPACK::SCALAPACK INTERFACE scalapack)
1 change: 1 addition & 0 deletions scalapack
Submodule scalapack added at acf286

0 comments on commit 0c45c42

Please sign in to comment.