Skip to content

cmake: Use upstream helpers for the Config.cmake file #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMAKE/scalapack-config-build.cmake.in

This file was deleted.

2 changes: 0 additions & 2 deletions CMAKE/scalapack-config-install.cmake.in

This file was deleted.

8 changes: 0 additions & 8 deletions CMAKE/scalapack-config-version.cmake.in

This file was deleted.

21 changes: 21 additions & 0 deletions CMAKE/scalapackConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.17...4.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why I set this one. But if anyone sees an issue with it just ping me. It might have been related to add_library(INTERFACE IMPORTED) or something else in the parts below.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean 4.0 is the max? There is already a 4.1 release candiate.

Copy link
Contributor Author

@LecrisUT LecrisUT Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it means use policies up to version 4.0 as NEW. Read it as we have tested this part with "all cmakes" between <min>...<max>. The comment is about why I chose 3.17 as the minimum. For Config.cmake files, the minimum should be as low as possible.


@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/scalapackTargets.cmake)

# Deprecated compatibility shims
if(TARGET scalapack::scalapack)
add_library(scalapack INTERFACE IMPORTED)
target_link_libraries(scalapack INTERFACE scalapack::scalapack)
set_target_properties(scalapack PROPERTIES
DEPRECATION "Target scalapack is deprecated, use scalapack::scalapack instead."
)
endif()
if(TARGET scalapack::scalapack-F)
add_library(scalapack-F INTERFACE IMPORTED)
target_link_libraries(scalapack-F INTERFACE scalapack::scalapack-F)
set_target_properties(scalapack-F PROPERTIES
DEPRECATION "Target scalapack-F is deprecated, use scalapack::scalapack-F instead."
)
endif()
67 changes: 42 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ if (UNIX)
endif ()
endif ()

# TODO: Remove this macro
macro(SCALAPACK_install_library lib)
install(TARGETS ${lib} EXPORT scalapack-targets
RUNTIME DESTINATION Testing
)
install(TARGETS ${lib}
EXPORT scalapackTargets
)
endmacro()

# --------------------------------------------------
Expand Down Expand Up @@ -227,6 +228,7 @@ append_subdir_files(src-C "SRC")
if (NOT MSVC)
set_source_files_properties(TOOLS/SL_gridreshape.c PROPERTIES COMPILE_OPTIONS "-Wno-error=implicit-function-declaration")
add_library(scalapack ${blacs} ${tools} ${tools-C} ${extra_lapack} ${pblas} ${pblas-F} ${ptzblas} ${ptools} ${pbblas} ${redist} ${src} ${src-C})
add_library(scalapack::scalapack ALIAS scalapack)
set_target_properties(scalapack PROPERTIES
VERSION ${SCALAPACK_VERSION}
SOVERSION ${SCALAPACK_VERSION_MAJOR}.${SCALAPACK_VERSION_MINOR})
Expand All @@ -235,11 +237,13 @@ if (NOT MSVC)
else () # Need to separate Fortran and C Code
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON )
add_library(scalapack ${blacs} ${tools-C} ${pblas} ${ptools} ${redist} ${src-C})
add_library(scalapack::scalapack ALIAS scalapack)
set_target_properties(scalapack PROPERTIES
VERSION ${SCALAPACK_VERSION}
SOVERSION ${SCALAPACK_VERSION_MAJOR}.${SCALAPACK_VERSION_MINOR})
target_link_libraries( scalapack ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} MPI::MPI_C)
add_library(scalapack-F ${pblas-F} ${pbblas} ${ptzblas} ${tools} ${src} ${extra_lapack} )
add_library(scalapack::scalapack-F ALIAS scalapack-F)
set_target_properties(scalapack-F PROPERTIES
VERSION ${SCALAPACK_VERSION}
SOVERSION ${SCALAPACK_VERSION_MAJOR}.${SCALAPACK_VERSION_MINOR})
Expand All @@ -255,6 +259,16 @@ endif()
option(SCALAPACK_BUILD_TESTS "Build all tests of the ScaLAPACK library" ON)
if(${SCALAPACK_BUILD_TESTS})
add_subdirectory(TESTING)
# Make sure that the build artifacts are exported for the test-suite
foreach(target IN ITEMS scalapack scalapack-F)
if(TARGET ${target})
export(TARGETS ${target}
FILE scalapackTargets.cmake
NAMESPACE scalapack::
APPEND
)
endif()
endforeach()
endif()

# --------------------------------------------------
Expand Down Expand Up @@ -289,33 +303,36 @@ INCLUDE(CPack)
# --------------------------------------------------


export(TARGETS scalapack FILE scalapack-targets.cmake)

if( NOT LAPACK_FOUND )
install(FILES
${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif( NOT LAPACK_FOUND )

configure_file(${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-version.cmake.in
${SCALAPACK_BINARY_DIR}/scalapack-config-version.cmake @ONLY)
configure_file(${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-build.cmake.in
${SCALAPACK_BINARY_DIR}/scalapack-config.cmake @ONLY)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scalapack.pc.in ${CMAKE_CURRENT_BINARY_DIR}/scalapack.pc)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/scalapack.pc
DESTINATION ${PKG_CONFIG_DIR}
)

configure_file(${SCALAPACK_SOURCE_DIR}/CMAKE/scalapack-config-install.cmake.in
${SCALAPACK_BINARY_DIR}/CMakeFiles/scalapack-config.cmake @ONLY)
include(CMakePackageConfigHelpers)
configure_package_config_file(
CMAKE/scalapackConfig.cmake.in
scalapackConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapack
)
write_basic_package_version_file(
scalapackConfigVersion.cmake
COMPATIBILITY SameMajorVersion
)

install(EXPORT scalapackTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapack
NAMESPACE scalapack
)

configure_file(scalapack.pc.in scalapack.pc @ONLY)
install(FILES
${SCALAPACK_BINARY_DIR}/CMakeFiles/scalapack-config.cmake
${SCALAPACK_BINARY_DIR}/scalapack-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapack-${SCALAPACK_VERSION}
)

install(EXPORT scalapack-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapack-${SCALAPACK_VERSION})
${CMAKE_CURRENT_BINARY_DIR}/scalapack.pc
DESTINATION ${PKG_CONFIG_DIR}
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/scalapackConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/scalapackConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapack
)
22 changes: 13 additions & 9 deletions TESTING/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
cmake_minimum_required(VERSION 3.26...4.0)

## Old test-suite to be modernized
# include only if this is included via `add_subdirectory`
project(scalapack-tests
LANGUAGES C Fortran
)

if(DEFINED SCALAPACK_SOURCE_DIR)
add_subdirectory(traditional)
if(NOT TARGET scalapack::scalapack)
find_package(scalapack REQUIRED CONFIG)
endif()

## Modern test-suite is an independent project
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(scalapack_tests_helpers)

# TODO: Add the implementations
project(scalapack-tests
LANGUAGES C Fortran
)
enable_testing()

# Old test-suite
add_subdirectory(traditional)

# Packaging tests
add_subdirectory(package)
77 changes: 77 additions & 0 deletions TESTING/cmake/scalapack_tests_helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.26...4.0)
include_guard()

function(scalapack_add_test test)
#[===[.md
# scalapack_add_test

Internal helper for adding functional tests of entire CMake projects

## Synopsis
```cmake
scalapack_add_test(<name>
[TEST_NAME <test_name>]
[CMAKE_ARGS <arg1> ...]
[LABELS <label1> ...]
)
```

## Options

`<name>`
: Test project to be configured

This is a subfolder relative to `${CMAKE_CURRENT_SOURCE_DIR}` containing the
test project with `CMakeLists.txt`

`TEST_NAME` [Default: `<name>`]
: Unique name of the ctest test name being created

`CMAKE_ARGS`
: Additional CMake args passed to the configure step
]===]

set(ARGS_Options)
set(ARGS_OneValue
TEST_NAME
)
set(ARGS_MultiValue
CMAKE_ARGS
LABELS
)
cmake_parse_arguments(PARSE_ARGV 1 ARGS "${ARGS_Options}" "${ARGS_OneValue}" "${ARGS_MultiValue}")
# Check required/optional arguments
if(NOT DEFINED ARGS_TEST_NAME)
set(ARGS_TEST_NAME ${test})
endif()

if(SCALAPACK_SOURCE_DIR)
# If scalapack is built as part of the same project, use the build artifacts
list(APPEND ARGS_CMAKE_ARGS
-Dscalapack_ROOT=${SCALAPACK_BINARY_DIR}
)
else()
# Otherwise use `scalapack_DIR` which is created after the `find_package`
list(APPEND ARGS_CMAKE_ARGS
-Dscalapack_ROOT=${scalapack_DIR}
)
endif()
# Propagate the compilers used
list(APPEND ARGS_CMAKE_ARGS
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER}
)

add_test(NAME ${ARGS_TEST_NAME}
COMMAND ${CMAKE_CTEST_COMMAND} --build-and-test ${CMAKE_CURRENT_SOURCE_DIR}/${test}
${CMAKE_CURRENT_BINARY_DIR}/${test}
# Use the same build environment as the current runner
--build-generator "${CMAKE_GENERATOR}"
--build-options
${ARGS_CMAKE_ARGS}
--test-command ${CMAKE_CTEST_COMMAND}
--test-dir ${CMAKE_CURRENT_BINARY_DIR}/${test}
--no-tests=ignore
--output-on-failure
)
endfunction()
2 changes: 2 additions & 0 deletions TESTING/package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scalapack_add_test(find_package)
scalapack_add_test(deprecated_targets)
14 changes: 14 additions & 0 deletions TESTING/package/deprecated_targets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.26...4.0)

project(test_find_package
LANGUAGES C Fortran
)

find_package(scalapack REQUIRED CONFIG)

# TODO: Add a proper smoke test
if(NOT TARGET scalapack)
message(FATAL_ERROR "scalapack target not present")
endif()

enable_testing()
14 changes: 14 additions & 0 deletions TESTING/package/find_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.26...4.0)

project(test_find_package
LANGUAGES C Fortran
)

find_package(scalapack REQUIRED CONFIG)

# TODO: Add a proper smoke test
if(NOT TARGET scalapack::scalapack)
message(FATAL_ERROR "scalapack::scalapack target not present")
endif()

enable_testing()
2 changes: 1 addition & 1 deletion TESTING/traditional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(genex_gfortran_10
function(setup_test_target)
foreach(target IN LISTS ARGN)
target_link_libraries(${target} PRIVATE
scalapack
scalapack::scalapack
${LAPACK_LIBRARIES}
${BLAS_LIBRARIES}
MPI::MPI_Fortran
Expand Down