Skip to content

Commit

Permalink
Separate core library from serial interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi authored Mar 20, 2024
1 parent 6a921b9 commit 2492949
Show file tree
Hide file tree
Showing 41 changed files with 422 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Build Fortuno
run: |
cmake -B ${BUILD_DIR} -G Ninja -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -B ${BUILD_DIR} -G Ninja
cmake --build ${BUILD_DIR}
cmake --install ${BUILD_DIR}
rm -rf ${BUILD_DIR}
Expand Down
50 changes: 43 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
cmake_minimum_required(VERSION 3.22...3.28)

list(APPEND CMAKE_MESSAGE_CONTEXT Fortuno)

project(
Fortuno
VERSION 0.1.0
Expand All @@ -24,17 +25,41 @@ project(
# Options #
]=================================================================================================]

include(CMakeDependentOption)

option(FORTUNO_BUILD_SHARED_LIBS "Fortuno: Build as shared library" ${PROJECT_IS_TOP_LEVEL})

option(FORTUNO_BUILD_TESTS "Fortuno: Build test suite" ${PROJECT_IS_TOP_LEVEL})
option(
FORTUNO_BUILD_SERIAL_INTERFACE
"Fortuno: whether serial interface should be built (or only core library)"
ON
)

option(FORTUNO_BUILD_EXAMPLES "Fortuno: Build example apps" ${PROJECT_IS_TOP_LEVEL})
cmake_dependent_option(
FORTUNO_BUILD_TESTS "Fortuno: Build test suite" ${PROJECT_IS_TOP_LEVEL}
"FORTUNO_BUILD_SERIAL_INTERFACE" OFF
)

cmake_dependent_option(
FORTUNO_BUILD_EXAMPLES "Fortuno: Build example apps" ${PROJECT_IS_TOP_LEVEL}
"FORTUNO_BUILD_SERIAL_INTERFACE" OFF
)

option(FORTUNO_INSTALL "Fortuno: Install project" ${PROJECT_IS_TOP_LEVEL})

set(
FORTUNO_INSTALL_MODULEDIR "modules" CACHE STRING
"Sub-directory to install the Fortran module files into (relative to CMAKE_INSTALL_LIBDIR)"
"Fortuno: Sub-directory for installed Fortran module files (relative to CMAKE_INSTALL_LIBDIR)"
)

set(
FORTUNO_THREAD_SAFE_FLAGS "" CACHE STRING
"Fortuno: Flags needed to enforce thread-safe build during compilation"
)

set(
FORTUNO_THREAD_SAFE_LINK_FLAGS "" CACHE STRING
"Fortuno: Flags neeeded to enforce thread-safe build durink linkage"
)

#[=================================================================================================[
Expand All @@ -49,8 +74,9 @@ if (FORTUNO_INSTALL)
include(GNUInstallDirs)
endif ()

fortuno_setup_build_type("RelWithDebInfo")
set(BUILD_SHARED_LIBS ${FORTUNO_BUILD_SHARED_LIBS})
fortuno_setup_build_type("RelWithDebInfo")
fortuno_def_thread_safe_build_target()

#[=================================================================================================[
# Main definition #
Expand All @@ -75,11 +101,20 @@ if (FORTUNO_INSTALL)
COMPONENT Fortuno_development
)

if (FORTUNO_BUILD_SERIAL_INTERFACE)
configure_file(cmake/fortuno-serial.pc.in fortuno-serial.pc @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/fortuno-serial.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Fortuno_development
)
endif ()

# cmake export files
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/FortunoConfigVersion.cmake
VERSION ${PROJECT_VERSION}
# COMPATIBILITY SameMajorVersion
# TODO: Switch to SameMajorVersion as soon as project version reaches 1.0.
COMPATIBILITY SameMinorVersion
)
configure_package_config_file(
Expand All @@ -88,8 +123,9 @@ if (FORTUNO_INSTALL)
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Fortuno
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/FortunoConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/FortunoConfig.cmake
FILES
${CMAKE_CURRENT_BINARY_DIR}/FortunoConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/FortunoConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Fortuno
COMPONENT Fortuno_development
)
Expand Down
57 changes: 29 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ The development can be followed and joined at the `Fortuno project
Quickstart
==========

The following instructions demonstrate how to add unit testing via Fortuno to an
existing project, which uses fpm, CMake or Meson as build system. If you are not
familiar with any of these build systems, visit the `Fortuno documentation
<https://fortuno.readthedocs.io>`_ for a step-by-step guide starting from
scratch.
The following instructions demonstrate how to add unit tests testing serial code
via Fortuno to an existing project, which uses fpm, CMake or Meson as build
system. If you are not familiar with any of these build systems, visit the
`Fortuno documentation <https://fortuno.readthedocs.io>`_ for a step-by-step
guide starting from scratch.

In the examples below, we will assume that your library has a module ``mylib``,
which provides a function ``factorial()`` for calculating the factorial of
Expand Down Expand Up @@ -81,8 +81,7 @@ project's build process. The actual steps depend on your build system:
Register Fortuno as a subproject by adding the following to your main
``meson.build`` file::

fortuno_subproject = subproject('fortuno')
fortuno_dep = fortuno_subproject.get_variable('fortuno_dep')
fortuno_serial_dep = dependency('fortuno-serial', fallback: ['fortuno', 'fortuno_serial_dep'])


Writing unit tests
Expand All @@ -102,8 +101,8 @@ could look as follows::
!> Test app driving Fortuno unit tests.
program testapp
use mylib, only : factorial
use fortuno, only : execute_serial_cmd_app, is_equal, test => serial_case_item,&
check => serial_check
use fortuno_serial, only : execute_serial_cmd_app, is_equal, test => serial_case_item,&
& check => serial_check
implicit none

!> Register tests by providing name and subroutine to run for each test.
Expand Down Expand Up @@ -135,8 +134,8 @@ could look as follows::
Bulding the test-driver app
---------------------------

In order to run the unit tests, you must build the test driver app with your
build system:
In order to run the unit tests, you must first build the test driver app with
your build system:

* **fpm:** If you stored the test-driver app source ``testapp.f90`` in the
``test/`` folder, fpm will automatically compile it and link it with the
Expand All @@ -145,13 +144,13 @@ build system:
fpm build

* **CMake:** Declare an executable ``testapp`` with ``testapp.f90`` as source
and target ``Fortuno::Fortuno`` as dependency in the ``CMakeLists.txt`` file.
Add also the target name of your library (e.g. ``mylib``) as dependency.
and target ``Fortuno::fortuno_serial`` as dependency in the ``CMakeLists.txt``
file. Add also the target name of your library (e.g. ``mylib``) as dependency.
Additionally, register the executable as a test, so that it can be executed
via ``ctest``::

add_executable(testapp testapp.f90)
target_link_libraries(testapp PRIVATE mylib Fortuno::Fortuno)
target_link_libraries(testapp PRIVATE mylib Fortuno::fortuno_serial)
add_test(NAME factorial COMMAND testapp)

Make also sure to call ``enable_testing()`` in your main ``CMakeLists.txt``
Expand All @@ -164,13 +163,13 @@ build system:
cmake --build _build

* **Meson:** Declare an executable ``testapp`` with ``testapp.f90`` as source
and ``fortuno_dep`` as dependency in the ``meson.build`` file. Add also your
library (e.g. ``mylib_dep``) as dependency::
and ``fortuno_serial_dep`` as dependency in the ``meson.build`` file. Add also
your library (e.g. ``mylib_dep``) as dependency::

testapp_exe = executable(
'testapp',
sources: ['testapp.f90'],
dependencies: [mylib_dep, fortuno_dep],
dependencies: [mylib_dep, fortuno_serial_dep],
)
test('factorial', testapp_exe)

Expand Down Expand Up @@ -221,31 +220,33 @@ Check out the `Fortuno documentation <https://fortuno.readthedocs.io>`_ for more
detailed explanations, further features and use cases.


Known issues
============
Compiler compatibility
======================

In order to offer a simple user interface and to allow for maximal reusability
and extensibility, Fortuno uses object-oriented Fortran constructs extensively.
Unfortunately, this is challenging for some older Fortran compilers. The
following table gives an overview over the compilers which were successfully
tested for building Fortuno. Make sure to use those compilers or any newer
versions of them.
and extensibility, Fortuno uses modern Fortran constructs extensively. Building
Fortuno requires a compiler with Fortran 2018 support. The following table gives
an overview over the compilers which were successfully tested for building
Fortuno. We recommend to use those compilers or any newer versions of them.

+------------------------+-----------------------------------------------------+
| Compiler | Status |
+========================+=====================================================+
| Intel 2024.0 | * serial: OK |
| | * mpi: OK |
| | * coarray: OK |
+------------------------+-----------------------------------------------------+
| NAG 7.1 (build 7145) | * serial: OK |
| NAG 7.2 (build 7202) | * serial: OK |
| | * mpi: OK |
| | * coarray: OK |
+------------------------+-----------------------------------------------------+
| GNU 12.2 | * serial: OK |
| GNU 13.2 | * serial: OK |
| | * mpi: OK |
| | * coarray: not tested yet |
+------------------------+-----------------------------------------------------+

If you are aware of other compilers being able to build Fortuno, open a pull
request, so that we can update the table accordingly.
If you are aware of any other compilers being able to build Fortuno, open a pull
request to update the table.


License
Expand Down
22 changes: 22 additions & 0 deletions cmake/FortunoHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,25 @@ function (fortuno_setup_build_type default_build_type)
endif()

endfunction()


# Defines the ThreadSafeBuild target for the thread-safe parts
function (fortuno_def_thread_safe_build_target)

if (FORTUNO_THREAD_SAFE_FLAGS)
set(_compiler_flags "${FORTUNO_THREAD_SAFE_FLAGS}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
set(_compiler_flags "-thread_safe")
endif ()

if (FORTUNO_THREAD_SAFE_LINK_FLAGS)
set(_linker_flags "${FORTUNO_THREAD_SAFE_LINK_FLAGS}")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
set(_linker_flags "-thread_safe")
endif ()

add_library(ThreadSafeBuild INTERFACE)
target_compile_options(ThreadSafeBuild INTERFACE ${_compiler_flags})
target_link_options(ThreadSafeBuild INTERFACE ${_linker_flags})

endfunction ()
7 changes: 7 additions & 0 deletions cmake/fortuno-serial.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@

Requires: fortuno
Cflags: -I@CMAKE_INSTALL_FULL_LIBDIR@/@FORTUNO_INSTALL_MODULEDIR@
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lfortuno-serial
14 changes: 7 additions & 7 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

list(APPEND CMAKE_MESSAGE_CONTEXT Example)

add_library(Fortuno_example_mylib)
add_library(fortuno_example_mylib)
set_target_properties(
Fortuno_example_mylib PROPERTIES
fortuno_example_mylib PROPERTIES
OUTPUT_NAME mylib
)
target_sources(
Fortuno_example_mylib PRIVATE
fortuno_example_mylib PRIVATE
mylib.f90
)

add_executable(Fortuno_example_testapp)
add_executable(fortuno_example_testapp)
set_target_properties(
Fortuno_example_testapp PROPERTIES
fortuno_example_testapp PROPERTIES
OUTPUT_NAME testapp
)
target_sources(
Fortuno_example_testapp PRIVATE
fortuno_example_testapp PRIVATE
fixtured_tests.f90
simple_tests.f90
testapp.f90
)
target_link_libraries(Fortuno_example_testapp PRIVATE Fortuno_example_mylib Fortuno::Fortuno)
target_link_libraries(fortuno_example_testapp PRIVATE fortuno_example_mylib Fortuno::fortuno_serial)
Loading

0 comments on commit 2492949

Please sign in to comment.