Skip to content

Commit 3d38c45

Browse files
committed
Test version using fortuno
WIP Note: The ctester intentionally has a fail, but the status does not propagate to ctest correctly.
1 parent c6ca532 commit 3d38c45

26 files changed

+687
-103
lines changed

CMakeLists.txt

Lines changed: 158 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,175 @@
1-
cmake_minimum_required(VERSION 3.16)
1+
#[=============================================================================[
2+
# Basic project definition #
3+
]=============================================================================]
24

5+
cmake_minimum_required(VERSION 3.22...3.29)
6+
7+
list(APPEND CMAKE_MESSAGE_CONTEXT scalapackfx)
8+
9+
project(
10+
scalapackfx
11+
VERSION 1.3.0
12+
DESCRIPTION "Modern Fortran Interface for ScaLAPACK"
13+
LANGUAGES Fortran
14+
)
15+
16+
#[=============================================================================[
17+
# Options #
18+
]=============================================================================]
19+
20+
option(
21+
SCALAPACKFX_BUILD_SHARED_LIBS
22+
"scalapackfx: Build as shared library"
23+
OFF
24+
)
25+
26+
option(
27+
SCALAPACKFX_BUILD_EXAMPLES
28+
"scalapackfx: Whether to build the examples"
29+
${PROJECT_IS_TOP_LEVEL}
30+
)
31+
option(
32+
SCALAPACKFX_BUILD_TESTS
33+
"scalapackfx: Whether to build the tests"
34+
${PROJECT_IS_TOP_LEVEL}
35+
)
36+
option(
37+
SCALAPACKFX_INSTALL
38+
"scalapackfx: Install project"
39+
${PROJECT_IS_TOP_LEVEL}
40+
)
41+
set(
42+
SCALAPACKFX_INSTALL_MODULEDIR
43+
"modules"
44+
CACHE STRING
45+
"scalapackfx: Sub-directory for installed Fortran module files (relative to CMAKE_INSTALL_LIBDIR)"
46+
)
47+
48+
option(
49+
SCALAPACKFX_SUBPROJECT_REQUIRE_FIND
50+
"scalapackfx: Require find_package for all subprojects"
51+
OFF
52+
)
53+
option(
54+
SCALAPACKFX_SUBPROJECT_DISABLE_FIND
55+
"scalapackfx: Disable find_package for all subprojects"
56+
OFF
57+
)
58+
59+
#[=============================================================================[
60+
# Project configuration #
61+
]=============================================================================]
62+
63+
include(FetchContent)
364
include(CMakePackageConfigHelpers)
65+
include(GNUInstallDirs)
466

5-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake
67+
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake
668
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
69+
include(scalapackfxHelpers)
770
include(ScalapackFxUtils)
871

9-
include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
72+
set(BUILD_SHARED_LIBS ${SCALAPACKFX_BUILD_SHARED_LIBS})
73+
scalapackfx_setup_build_type("RelWithDebInfo")
1074

11-
project(ScalapackFx VERSION 1.2.0 LANGUAGES Fortran)
12-
13-
setup_build_type()
75+
find_package(MPI REQUIRED)
1476

1577
#
1678
# Prerequisites
1779
#
1880
find_package(CustomScalapack REQUIRED QUIET)
1981
find_package(CustomLapack REQUIRED)
20-
find_program(FYPP fypp)
21-
if(NOT FYPP)
22-
message(FATAL_ERROR "Preprocessor fypp could not be found")
23-
endif()
2482

25-
#
26-
# Build instructions
27-
#
28-
include(GNUInstallDirs)
83+
include(subprojects/fypp.cmake)
84+
85+
# Extra flags from cmake options and compiler capabilities
86+
scalapackfx_add_fypp_defines(FYPP_FLAGS)
2987

30-
add_subdirectory(lib)
31-
if(NOT BUILD_EXPORTED_TARGETS_ONLY)
88+
set(FYPP_FLAGS "${FYPP_FLAGS}")
89+
90+
set(FYPP_CONFIG_FLAGS "${FYPP_FLAGS}")
91+
# Make sure, the line-marker option is not set
92+
list(REMOVE_ITEM FYPP_CONFIG_FLAGS "-n")
93+
set(FYPP_BUILD_FLAGS "${FYPP_FLAGS}" "--file-var-root=${CMAKE_SOURCE_DIR}"
94+
"$<IF:$<CONFIG:Debug>,-DDEBUG=1,-DDEBUG=0>")
95+
96+
set(PYTHON_INTERPRETER "python3" CACHE STRING
97+
"Python interpreter to use for preprocessor")
98+
99+
set(fypp_flags ${FYPP_BUILD_FLAGS})
100+
list(APPEND
101+
fypp_flags -I${CMAKE_CURRENT_SOURCE_DIR}/include -DRELEASE="'${VERSION}'"
102+
)
103+
104+
#[=============================================================================[
105+
# Main definition #
106+
]=============================================================================]
107+
108+
add_subdirectory(src)
109+
110+
if (SCALAPACKFX_BUILD_EXAMPLES)
111+
add_subdirectory(example)
112+
endif ()
113+
if (SCALAPACKFX_BUILD_TESTS)
114+
include(subprojects/Fortuno.cmake)
115+
enable_testing()
32116
add_subdirectory(test)
33-
endif()
117+
endif ()
34118

35-
#
36-
# Installation
37-
#
38-
add_library(ScalapackFx INTERFACE)
39-
target_link_libraries(ScalapackFx INTERFACE scalapackfx)
40-
install(TARGETS ScalapackFx EXPORT scalapackfx-targets)
41-
42-
install(EXPORT scalapackfx-targets
43-
FILE scalapackfx-targets.cmake
44-
NAMESPACE ScalapackFx::
45-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx"
46-
EXPORT_LINK_INTERFACE_LIBRARIES)
47-
48-
configure_package_config_file(
49-
${CMAKE_CURRENT_SOURCE_DIR}/utils/export/scalapackfx-config.cmake.in
50-
${CMAKE_CURRENT_BINARY_DIR}/cmake/scalapackfx-config.cmake
51-
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx)
52-
53-
write_basic_package_version_file(
54-
${CMAKE_CURRENT_BINARY_DIR}/cmake/scalapackfx-config-version.cmake
55-
VERSION ${PROJECT_VERSION}
56-
COMPATIBILITY SameMajorVersion)
57-
58-
install(
59-
FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/scalapackfx-config.cmake
60-
${CMAKE_CURRENT_BINARY_DIR}/cmake/scalapackfx-config-version.cmake
61-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx)
62-
63-
install(
64-
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
65-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx)
66-
67-
get_pkgconfig_params(PKGCONFIG_REQUIRES PKGCONFIG_LIBS PKGCONFIG_LIBS_PRIVATE PKGCONFIG_C_FLAGS)
68-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/utils/export/scalapackfx.pc.in
69-
${CMAKE_CURRENT_BINARY_DIR}/scalapackfx.pc @ONLY)
70-
install(
71-
FILES "${CMAKE_CURRENT_BINARY_DIR}/scalapackfx.pc"
72-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
119+
120+
#[=============================================================================[
121+
# Install or Export #
122+
]=============================================================================]
123+
124+
if (SCALAPACKFX_INSTALL)
125+
126+
# pkg-config files
127+
configure_file(cmake/scalapackfx.pc.in scalapackfx.pc @ONLY)
128+
install(
129+
FILES ${CMAKE_CURRENT_BINARY_DIR}/scalapackfx.pc
130+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
131+
COMPONENT scalapackfx_development
132+
)
133+
134+
# cmake export files
135+
write_basic_package_version_file(
136+
${CMAKE_CURRENT_BINARY_DIR}/scalapackfxConfigVersion.cmake
137+
VERSION ${PROJECT_VERSION}
138+
COMPATIBILITY SameMajorVersion
139+
)
140+
configure_package_config_file(
141+
cmake/scalapackfxConfig.cmake.in
142+
${CMAKE_CURRENT_BINARY_DIR}/scalapackfxConfig.cmake
143+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx
144+
)
145+
install(
146+
FILES
147+
${CMAKE_CURRENT_BINARY_DIR}/scalapackfxConfigVersion.cmake
148+
${CMAKE_CURRENT_BINARY_DIR}/scalapackfxConfig.cmake
149+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx
150+
COMPONENT scalapackfx_development
151+
)
152+
153+
export(
154+
EXPORT scalapackfxTargets
155+
FILE scalapackfxTargets.cmake
156+
NAMESPACE scalapackfx::
157+
)
158+
install(
159+
EXPORT scalapackfxTargets
160+
FILE scalapackfxTargets.cmake
161+
NAMESPACE scalapackfx::
162+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/scalapackfx
163+
COMPONENT scalapackfx_development
164+
)
165+
endif ()
166+
167+
# Make project available for FetchContent
168+
if (NOT PROJECT_IS_TOP_LEVEL)
169+
# Propagate variables
170+
set(scalapackfx_VERSION ${scalapackfx_VERSION} PARENT_SCOPE)
171+
set(scalapackfx_VERSION_MAJOR ${scalapackfx_VERSION_MAJOR} PARENT_SCOPE)
172+
set(scalapackfx_VERSION_MINOR ${scalapackfx_VERSION_MINOR} PARENT_SCOPE)
173+
set(scalapackfx_VERSION_PATCH ${scalapackfx_VERSION_PATCH} PARENT_SCOPE)
174+
set(scalapackfx_VERSION_TWEAK ${scalapackfx_VERSION_TWEAK} PARENT_SCOPE)
175+
endif ()

cmake/scalapackfx.pc.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Name: @PROJECT_NAME@
2+
Description: @PROJECT_DESCRIPTION@
3+
Version: @PROJECT_VERSION@
4+
5+
Cflags: -I@CMAKE_INSTALL_FULL_LIBDIR@/@SCALAPACKFX_INSTALL_MODULEDIR@
6+
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lscalapackfx

cmake/scalapackfxConfig.cmake.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
find_dependency(MPI)
5+
6+
include(${CMAKE_CURRENT_LIST_DIR}/scalapackfxTargets.cmake)

cmake/scalapackfxHelpers.cmake

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Sets up the build type.
2+
function (scalapackfx_setup_build_type default_build_type)
3+
4+
get_property(_multiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
5+
if (_multiConfig)
6+
message(STATUS "Build type multi-config (build type selected at the build step)")
7+
else ()
8+
if (NOT CMAKE_BUILD_TYPE)
9+
message(STATUS "Build type ${default_build_type} (default single-config)")
10+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Build type" FORCE)
11+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY HELPSTRING "Choose the type of build")
12+
set_property(
13+
CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo"
14+
)
15+
else ()
16+
message(STATUS "scalapackfx: build type: ${CMAKE_BUILD_TYPE} (manually selected single-config)")
17+
endif ()
18+
endif ()
19+
20+
endfunction ()
21+
22+
# Replaces the extension of a given file
23+
#
24+
# Args:
25+
# oldext [in]: Old extension
26+
# newext [in]: New extension
27+
# fname [in]: File name in which extension should be replaced.
28+
# newfname [out]: File name after extension replacement.
29+
#
30+
function(scalapackfx_replace_extension oldext newext fname newfname)
31+
32+
string(REGEX REPLACE "\\.${oldext}$" ".${newext}" _newfname ${fname})
33+
set(${newfname} ${_newfname} PARENT_SCOPE)
34+
35+
endfunction()
36+
37+
38+
# Registers files for preprocessing
39+
#
40+
# Args:
41+
# preproc [in]: Preprocessor to use
42+
# preprocopts [in]: Preprocessor command line arguments (but not in/out file)
43+
# oldext [in]: Extension of the unpreprocessed files.
44+
# newext [in]: Extension of the preprocessed files.
45+
# oldfiles [in]: List of unpreprocessed file names.
46+
# newfiles [out]: List of preprocessed file names.
47+
#
48+
function(scalapackfx_preprocess preproc preprocopts oldext newext oldfiles newfiles)
49+
50+
set(_newfiles)
51+
foreach(oldfile IN LISTS oldfiles)
52+
# Start with an absolulte path, so that the correct relative path is calculated thereafter
53+
get_filename_component(oldfile ${oldfile} ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR})
54+
file(RELATIVE_PATH oldfile ${CMAKE_CURRENT_SOURCE_DIR} ${oldfile})
55+
scalapackfx_replace_extension(${oldext} ${newext} ${oldfile} newfile)
56+
add_custom_command(
57+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${newfile}
58+
COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${oldfile} ${CMAKE_CURRENT_BINARY_DIR}/${newfile}
59+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${oldfile})
60+
list(APPEND _newfiles ${CMAKE_CURRENT_BINARY_DIR}/${newfile})
61+
endforeach()
62+
set(${newfiles} ${_newfiles} PARENT_SCOPE)
63+
64+
endfunction()
65+
66+
67+
# Build -D command line arguments for Fypp preprocessor based on current configuration
68+
#
69+
# Args:
70+
# fyppflags [inout]: Current Fypp flags on enter, with -D options extended flags on exit.
71+
#
72+
function (scalapackfx_add_fypp_defines fyppflags)
73+
74+
set(_fyppflags "${${fyppflags}}")
75+
set(${fyppflags} ${_fyppflags} PARENT_SCOPE)
76+
77+
endfunction()

example/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Folder for generated mod-files
2+
set(moduledir "${CMAKE_CURRENT_BINARY_DIR}/modules")
3+
4+
add_executable(transpose)
5+
6+
target_sources(transpose PRIVATE transpose.f90 common_module.f90)
7+
set_target_properties(transpose
8+
PROPERTIES Fortran_MODULE_DIRECTORY "${moduledir}"
9+
)
10+
target_link_libraries(transpose PRIVATE scalapackfx)
11+
target_link_libraries(transpose PRIVATE MPI::MPI_Fortran)
12+
target_link_libraries(transpose PRIVATE Scalapack::Scalapack)

0 commit comments

Comments
 (0)