From 83c02dc81c20949ffca856210da6a54838a898a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Aradi?= Date: Sat, 24 Feb 2024 21:14:02 +0100 Subject: [PATCH] Extend readme with meson related infos --- README.rst | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index d12ca64..fcc5e3e 100644 --- a/README.rst +++ b/README.rst @@ -24,8 +24,8 @@ special pre-processor. - parallel unit testing for MPI- and coarray-parallel projects, and -- seamless integration with the `fpm `_ and - `CMake `_ build systems. +- integration with the `fpm `_, `CMake + `_ and `Meson `_ build systems. Detailed **documentation** is available on the `Fortuno documentation `_ page. You can also have a look at the @@ -38,6 +38,17 @@ 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 +`_ 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 +integers. Adapt those names to your actual library and routine names. + + Obtaining Fortuno ----------------- @@ -61,6 +72,21 @@ project's build process. The actual steps depend on your build system. ) FetchContent_MakeAvailable(Fortuno) + * **Meson:** Create the file ``fortuno.wrap`` in the ``subprojects/`` folder + of your project (create the folder, if it does not exist yet) with following + content:: + + [wrap-git] + directory=fortuno + url=https://github.com/fortuno-repos/fortuno + revision=main + + Add 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') + Writing unit tests ------------------ @@ -121,11 +147,11 @@ build system: fpm build -* **CMake:** Register ``testapp.f90`` for compilation and add the - ``Fortuno::Fortuno`` target as dependency in the relevant ``CMakeLists.txt`` - file. You would, of course, also have to specify your library (e.g. ``mylib``) - as dependency. Additionally, register the executable as a test, so that it can - be executed via ``ctest``:: +* **CMake:** Create an executable ``testapp`` with ``testapp.f90`` as source and + add ``Fortuno::Fortuno`` target 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) @@ -140,6 +166,22 @@ build system: cmake -B _build cmake --build _build + * **Meson:** Create an executable ``testapp`` with ``testapp.f90`` as source + and ``fortuno_dep`` as dependency in the ``meson.build`` file. Add also the + your library (e.g. ``mylib_dep``) as dependency:: + + testapp_exe = executable( + 'testapp', + sources: ['testapp.f90'] + dependencies: [mylib_dep, fortuno_dep], + ) + test('factorial', testapp_exe) + + Build your project as usual:: + + meson setup _build + ninja -C _build + Running the tests ----------------- @@ -158,6 +200,10 @@ You run the units tests by executing the test app: output of Fortuno. You will only see the final result of the testing procedure then. +* **Meson:** Run the unit tests with :: + + meson test + The result is communicated via the testapp's exit code to the build framework (zero for success, and non-zero for failure). Additionally, Fortuno logs details to the console::