Skip to content

CMake project modernization #2985

@LecrisUT

Description

@LecrisUT

I was looking at the cmake build process and I have a few comments about some common cmake standards that should be adopted, especially since cmake_minimum_required() is set to 3.22:

  • Use FetchContent with FETCHCONTENT_SOURCE_DIR_<uppercaseName> pointing to the submodule if necessary. This allows for a native switch between find_package, FetchContent and submodule sources. FIND_PACKAGE_ARGS was only introduced in 3.24, but it can be easily back-ported.
  • Use [===[ block command and messages instead of multiple message()
  • Avoid bundling FindPackage unless it is a wrapper that checks for find_package(CONFIG) and the cmake bundled FindPackage modules. The bundled modules will always have precedence and it is best to first check with the ones maintained on cmake which can have better support.
  • Fortran module files should be installed in a separate directory. E.g. fortran-std approach
  • Common and useful options like CP2K_TESTS, CP2K_INSTALL and CP2K_SHARED_LIBS, with defaults based on PROJECT_IS_TOP_LEVEL. This will make it more friendly to use with FetchContent
  • Missing namespaced ALIAS libraries/executables, and propagation of variables like cp2k_VERSION. This is to make the project equivalent if it's imported via find_package or via FetchContent.
  • Instead of tests like if(${cp2k_build_options_up} STREQUAL "FULL") bundle cmake presets

Also, feel free to copy the test-suite from spglib to enable github actions across multiple compiler families

Hope these tips are helpful

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions