thomasms / toast

Testing Or ASsertion Toolkit - Fortran unit testing library
BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

1 minimal #2

Closed apthorpe closed 4 years ago

apthorpe commented 4 years ago

This PR adds installation and packaging support to TOAST, provides convenience scripts for integrating TOAST with CMake-based projects (FindTOAST.cmake, BuildTOAST.cmake, TOASThelper.cmake), and adds TOAST unit tests and examples to a CTest test plan. make test will run all tests; tests expected to fail (example1, example2) are marked as WILL_FAIL.

make install should install the TOAST library and toast.mod module file in a standard location. CPack will create installers and archives based on the platform and installed packaging tools. A .zip archive is produced for all platforms and illustrates the installation directory tree structure.

None of the original source code has been changed; this should only affect build infrastructure.

It is likely that the project metadata needs to be changed; see CPACK_* variables set at the top of CMakeLists.txt. This info is used for constructing packages and includes version, authorship, and licensing information.

The included version of BuildTOAST.cmake does not take advantage of the new installation support. A revised, simplified version will be suggested if this PR is accepted; see https://gitlab.com/apthorpe/sofire2/-/blob/42-improve-unit-test-integration/cmake/BuildTOAST.cmake for more details

FindTOAST.cmake can be used to detect a previously-installed version of TOAST and set the location of the library and .mod file. Using FindTOAST.cmake and BuildTOAST.cmake, it's possible to use an existing installation if it's detected, then fall back to retrieving and installing a fresh copy without requiring the including project to use git submodules.

Finally, TOASThelper.cmake provides the CMake function add_toast_unit_test() which simplifies compilation and running of TOAST-based unit tests. Example use:

    # Tests thermo.inp and trans.inp using m_material.f90
    add_toast_unit_test(
        TARGET ut_c1_property_data
        SOURCES "${TEST_SRC_BASE}/c1/c1_property_data.f90" "${SOFIRE2_1C_DEP_SOURCES}"
        DEPENDENCIES pretest_setup FLIBS_external
        RUN_DIRECTORY ${SOFIRE2_1C_TEST_DIR}
    )

Full documentation of the function arguments is provided in the body of TOASThelper.cmake

thomasms commented 4 years ago

Wow, thanks for this big contribution - really great work. From the brief look I've had, it looks fine. Just noticed the build is failing though, but I am not sure if it is because of this PR, it might be that the Travis setup is just too old now. Let me have a look at the CI and I'll get back to this after.

thomasms commented 4 years ago

So it seems your comment is pretty accurate:

# Libraries
# This may require CMake 3.14 or later
install(TARGETS ${TOAST_LIB_NAME})

Locally, I have cmake version 3.14 and all works fine, but on the build and other systems with cmake < 3.14 (I tested 3.10 and the build is 3.12 I think) it fails because of that line (120).

I guess my question to you is do you think versions of cmake older than 3.14 are worth supporting?

I know some people who use fortran will have problems updating systems (and cmake) so this requirement may cause issues. Cmake 3.12 is still quite recent (2017) for the fortran community - is there a workaround to support older cmake versions?

apthorpe commented 4 years ago

Let me test against an older version and see if I can reduce the CMake version requirement

apthorpe commented 4 years ago

I tested against a fresh build of CMake 3.10.3 on Linux and resolved a few issues. The first was that prior to CMake 3.13 or 3.14 install(TARGETS ...) must be invoked in the subdirectory where the target is defined. I had the TOAST library install() line in the top-level CMakeLists.txt; moving it to toast/CMakeLists.txt fixed the first issue.

The second issue is that the install() command didn't specify the directories where executables, libraries, etc. should be installed. Those directories are defined by invoking include(GNUInstallDirs) but they are only used by default in later versions of CMake. Explicitly setting RUNTIME DESTINATION, LIBRARY DESTINATION, and ARCHIVE DESTINATION in the install() command solved the second problem. Hopefully those two changes reduce dependencies to something more manageable.

thomasms commented 4 years ago

All looks fine now. Thanks for the effort, really appreciate it.