Skip to content

Commit

Permalink
Test install cmake (#350)
Browse files Browse the repository at this point in the history
Test CMake find_package (*.cmake files).
  • Loading branch information
fghoussen authored Apr 23, 2022
1 parent 1f4c1e0 commit 3ba4dbf
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 58 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ jobs:
make all
make test
make package_source
ubuntu_latest_cmake_install:
runs-on: ubuntu-latest
steps:
- name: Clone and check out repository code
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}} # Branch where changes are implemented.
repository: ${{github.event.pull_request.head.repo.full_name}} # Repo where changes are implemented.
- name: Check commit
run: |
git log -1
- name: Update OS
run: sudo apt-get update
- name: Install apt-get dependencies
run: sudo apt-get install -y gfortran gcc g++ openmpi-bin libopenmpi-dev libblas-dev liblapack-dev cmake
- name: Run job
run: |
mkdir build
cd build
cmake ..
bash ./tstCMakeInstall.sh
ubuntu_latest_autotools:
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 3 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ arpack-ng - 3.9.0
* Support for NAG's nagfor Fortran compiler

[ Franck Houssen ]
* Test CMake find_package (*.cmake files).
* [BUG FIX] autotools: ICB must be checked first (MPI changes compilers).
* [BUG FIX] BLAS/LAPACK: allow suffixes in case BLAS/LAPACK can not provide ICB.
* [BUG FIX] Compile C programs with ICB.
* arpackmm: command line bug fix.
* arpackmm: restart bug fix.

[ Haoyang Liu ]
* CMake: minimum required version changed to 3.0
Expand All @@ -24,10 +27,6 @@ arpack-ng - 3.9.0
[ Robert Schütz ]
* use CMAKE_INSTALL_FULL_<dir> in arpack.pc

[ Franck Houssen ]
* arpackmm: command line bug fix.
* arpackmm: restart bug fix.

-- Sylvestre Ledru <[email protected]> Mon, 07 Dec 2020 11:37:40 +0100

arpack-ng - 3.8.0
Expand Down
44 changes: 23 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function(examples list_name)
foreach(l ${${list_name}})
get_filename_component(lwe ${l} NAME_WE)
add_executable(${lwe} ${arpackexample_DIR}/${l} ${examples_EXTRA_SRCS})
target_link_libraries(${lwe} arpack BLAS::BLAS LAPACK::LAPACK ${EXTRA_LDFLAGS})
target_link_libraries(${lwe} arpack BLAS::BLAS LAPACK::LAPACK ${EXTRA_LDFLAGS})
add_test(NAME "${lwe}_ex" COMMAND ${lwe} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endforeach()
endfunction(examples)
Expand Down Expand Up @@ -730,7 +730,7 @@ include(GNUInstallDirs)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix \${prefix})
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_VERSION ${arpack_ng_VERSION})
set(PACKAGE_URL "https://github.com/opencollab/arpack-ng/")
Expand Down Expand Up @@ -775,43 +775,45 @@ if (MPI)
endif ()

if(ICB)
install(FILES ICB/arpack.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/arpack.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/arpack.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES ICB/arpack.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
if (MPI)
install(FILES ICB/parpack.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/parpack.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/parpack.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES ICB/parpack.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
endif()
if (ICBEXMM)
install(FILES EXAMPLES/MATRIX_MARKET/arpackSolver.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES EXAMPLES/MATRIX_MARKET/arpackSolver.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES "${PROJECT_BINARY_DIR}/EXAMPLES/MATRIX_MARKET/arpackSolver.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
endif()

install(FILES debug.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES debugF90.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES debug.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES debugF90.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
if(ICB)
install(FILES ICB/debug_c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/debug_c.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/debug_c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES ICB/debug_c.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
endif()

install(FILES stat.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES statF90.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES stat.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES statF90.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
if(ICB)
install(FILES ICB/stat_c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/stat_c.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES ICB/stat_c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
install(FILES ICB/stat_c.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)
endif()

configure_file(arpackdef.h.in "${PROJECT_BINARY_DIR}/arpackdef.h" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpackdef.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES "${PROJECT_BINARY_DIR}/arpackdef.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)

configure_file(arpackicb.h.in "${PROJECT_BINARY_DIR}/arpackicb.h" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpackicb.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack)
install(FILES "${PROJECT_BINARY_DIR}/arpackicb.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arpack-ng)

# Provide find_package for arpack-ng to users.
configure_file(arpack-ng-config.cmake.in "${PROJECT_BINARY_DIR}/arpack-ng-config.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpack-ng-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arpack-ng) # find_package(arpack-ng)
configure_file(arpack-ng-config-version.cmake.in "${PROJECT_BINARY_DIR}/arpack-ng-config-version.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpack-ng-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arpack-ng)
configure_file(cmake/arpackng-config.cmake.in "${PROJECT_BINARY_DIR}/arpackng-config.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpackng-config.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arpack-ng) # find_package(arpackng)
configure_file(cmake/arpackng-config-version.cmake.in "${PROJECT_BINARY_DIR}/arpackng-config-version.cmake" @ONLY)
install(FILES "${PROJECT_BINARY_DIR}/arpackng-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arpack-ng)

configure_file(cmake/tstCMakeInstall.sh.in ${PROJECT_BINARY_DIR}/tstCMakeInstall.sh @ONLY)

# Packaging: ease arpack-ng distribution (precompiled binaries and sources tarballs).
set(CPACK_VERSION_MAJOR "${arpack_ng_MAJOR_VERSION}")
Expand Down
3 changes: 0 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ endif

EXTRA_DIST = README.md PARPACK_CHANGES CHANGES DOCUMENTS VISUAL_STUDIO \
detect_arpack_bug.m4 CMakeLists.txt

cmakedir = $(libdir)/cmake/arpack-ng
cmake_DATA = arpack-ng-config.cmake arpack-ng-config-version.cmake
3 changes: 2 additions & 1 deletion PARPACK/SRC/MPI/parpack.pc.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: @PACKAGE_NAME@
Description: Collection of Fortran77 subroutines designed to solve large scale eigenvalue problems
Expand All @@ -9,3 +9,4 @@ URL: @PACKAGE_URL@
Requires.private: arpack@LIBSUFFIX@
Libs: -L${libdir} -lparpack@LIBSUFFIX@
Libs.private: @PARPACK_PC_LIBS_PRIVATE@
Cflags: -I${includedir}
3 changes: 1 addition & 2 deletions SRC/arpack.pc.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Expand All @@ -9,4 +8,4 @@ Version: @PACKAGE_VERSION@
URL: @PACKAGE_URL@
Libs: -L${libdir} -larpack@LIBSUFFIX@
Libs.private: @ARPACK_PC_LIBS_PRIVATE@
Cflags: -I${includedir}/arpack
Cflags: -I${includedir}
25 changes: 0 additions & 25 deletions arpack-ng-config.cmake.in

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions cmake/arpackng-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Config file for the arpack-ng package.
#
# To use arpack from CMake, use ARPACK::ARPACK target:
# find_package(arpackng)
# add_executable(main main.f)
# target_include_directories(main INTERFACE ARPACK::ARPACK)
# target_link_libraries(main ARPACK::ARPACK)
#
# To use parpack from CMake, use PARPACK::PARPACK target:
# find_package(arpackng)
# add_executable(main main.f)
# target_include_directories(main INTERFACE PARPACK::PARPACK)
# target_link_libraries(main PARPACK::PARPACK)

# Create arpack targets.
add_library(ARPACK::ARPACK INTERFACE IMPORTED)
set_target_properties(ARPACK::ARPACK PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/arpack-ng")
set_target_properties(ARPACK::ARPACK PROPERTIES INTERFACE_LINK_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")
set_target_properties(ARPACK::ARPACK PROPERTIES INTERFACE_LINK_LIBRARIES "arpack")

# Create parpack targets.
set(MPI "@MPI@")
if (MPI)
add_library(PARPACK::PARPACK INTERFACE IMPORTED)
set_target_properties(PARPACK::PARPACK PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/arpack-ng")
set_target_properties(PARPACK::PARPACK PROPERTIES INTERFACE_LINK_DIRECTORIES "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")
set_target_properties(PARPACK::PARPACK PROPERTIES INTERFACE_LINK_LIBRARIES "parpack")
endif ()
100 changes: 100 additions & 0 deletions cmake/tstCMakeInstall.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash -eu
# Testing that find_package works.
# Note: this script must not be added to the test suite as it will change cmake options.

# 1. Define temporary directory.

export TMP_DIR="/tmp/tstCMakeInstall"
mkdir -p "${TMP_DIR}"

# 2. Rerun cmake with prefix, install arpack-ng.
# Note: this script must not be added to the test suite as it will change cmake options.

export TMP_PREFIX="${TMP_DIR}/local"
cmake -DCMAKE_INSTALL_PREFIX="${TMP_PREFIX}" -DMPI=ON .
make all install

# 3. Setup environment for find_package to work (what you typically in module-environment files).

cd "${TMP_DIR}"
export ARCH="$(ls ./local/lib/)"
export PKG_CONFIG_PATH="${TMP_PREFIX}/lib/${ARCH}/pkgconfig"
export arpackng_DIR="${TMP_PREFIX}/lib/${ARCH}/cmake/arpack-ng"

# 4. Create new cmake project, in temporary directory, with files from arpack-ng.

mkdir -p tstCMakeInstall
cd tstCMakeInstall

cp "@PROJECT_SOURCE_DIR@/EXAMPLES/BAND/dnband.f" .
cp "@PROJECT_SOURCE_DIR@/EXAMPLES/BAND/dnbdr1.f" .
cp "@PROJECT_SOURCE_DIR@/EXAMPLES/BAND/dnbdr3.f" .
cp "@PROJECT_SOURCE_DIR@/PARPACK/EXAMPLES/MPI/pdndrv1.f" .
cp "@PROJECT_SOURCE_DIR@/PARPACK/EXAMPLES/MPI/pdndrv3.f" .

echo "cmake_minimum_required(VERSION 3.0)" > CMakeLists.txt
echo "" >> CMakeLists.txt
echo "project(tstCMakeInstall Fortran)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "find_package(BLAS REQUIRED)" >> CMakeLists.txt
echo "find_package(LAPACK REQUIRED)" >> CMakeLists.txt
echo "find_package(MPI REQUIRED COMPONENTS Fortran)" >> CMakeLists.txt
echo "find_package(arpackng REQUIRED)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "add_executable(dnbdr1 dnband.f dnbdr1.f)" >> CMakeLists.txt
echo "target_include_directories(dnbdr1 INTERFACE BLAS::BLAS)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr1 BLAS::BLAS)" >> CMakeLists.txt
echo "target_include_directories(dnbdr1 INTERFACE LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr1 LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_include_directories(dnbdr1 INTERFACE ARPACK::ARPACK)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr1 ARPACK::ARPACK)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "add_executable(pdndrv1 dnband.f pdndrv1.f)" >> CMakeLists.txt
echo "target_include_directories(pdndrv1 INTERFACE BLAS::BLAS)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv1 BLAS::BLAS)" >> CMakeLists.txt
echo "target_include_directories(pdndrv1 INTERFACE LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv1 LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_include_directories(pdndrv1 INTERFACE MPI::MPI_Fortran)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv1 MPI::MPI_Fortran)" >> CMakeLists.txt
echo "target_include_directories(pdndrv1 INTERFACE ARPACK::ARPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv1 ARPACK::ARPACK)" >> CMakeLists.txt
echo "target_include_directories(pdndrv1 INTERFACE PARPACK::PARPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv1 PARPACK::PARPACK)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "find_package(PkgConfig REQUIRED)" >> CMakeLists.txt
echo "pkg_check_modules(ARPACK IMPORTED_TARGET REQUIRED arpack)" >> CMakeLists.txt
echo "pkg_check_modules(PARPACK IMPORTED_TARGET REQUIRED parpack)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "add_executable(dnbdr3 dnband.f dnbdr3.f)" >> CMakeLists.txt
echo "target_include_directories(dnbdr3 INTERFACE BLAS::BLAS)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr3 BLAS::BLAS)" >> CMakeLists.txt
echo "target_include_directories(dnbdr3 INTERFACE LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr3 LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_include_directories(dnbdr3 INTERFACE PkgConfig::ARPACK)" >> CMakeLists.txt
echo "target_link_libraries(dnbdr3 PkgConfig::ARPACK)" >> CMakeLists.txt
echo "" >> CMakeLists.txt
echo "add_executable(pdndrv3 dnband.f pdndrv3.f)" >> CMakeLists.txt
echo "target_include_directories(pdndrv3 INTERFACE BLAS::BLAS)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv3 BLAS::BLAS)" >> CMakeLists.txt
echo "target_include_directories(pdndrv3 INTERFACE LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv3 LAPACK::LAPACK)" >> CMakeLists.txt
echo "target_include_directories(pdndrv3 INTERFACE MPI::MPI_Fortran)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv3 MPI::MPI_Fortran)" >> CMakeLists.txt
echo "target_include_directories(pdndrv3 INTERFACE PkgConfig::ARPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv3 PkgConfig::ARPACK)" >> CMakeLists.txt
echo "target_include_directories(pdndrv3 INTERFACE PkgConfig::PARPACK)" >> CMakeLists.txt
echo "target_link_libraries(pdndrv3 PkgConfig::PARPACK)" >> CMakeLists.txt

# 5. Build and test this new project with cmake: for this to be possible, find_package must work.

mkdir -p build
cd build

cmake ..
make all VERBOSE=1

./dnbdr1
mpirun -n 2 ./pdndrv1
./dnbdr3
mpirun -n 2 ./pdndrv3

3 changes: 1 addition & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ AC_CONFIG_FILES([
PARPACK/SRC/MPI/parpack$LIBSUFFIX.pc:PARPACK/SRC/MPI/parpack.pc.in
], [], [LIBSUFFIX="$LIBSUFFIX"])

dnl We do NOT want arpackng*.cmake files to be created: @MPI@ can not be replaced.
AC_CONFIG_FILES([
EXAMPLES/MATRIX_MARKET/arpackSolver.pc
arpackdef.h
arpackicb.h
arpack-ng-config-version.cmake
arpack-ng-config.cmake
Makefile
ICB/Makefile
UTIL/Makefile
Expand Down

0 comments on commit 3ba4dbf

Please sign in to comment.