cmake_minimum_required(VERSION 3.20)

# Keep the package version in one source-level definition.  CMake reads it
# from source/pimd_release.F90 so the build metadata and runtime banner agree.
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/source/pimd_release.F90"
     _pimd_release_line REGEX "PIMD_VERSION[ \t]*=")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+"
       PIMD_PROJECT_VERSION "${_pimd_release_line}")
if(NOT PIMD_PROJECT_VERSION)
  message(FATAL_ERROR
    "Could not determine PIMD version from source/pimd_release.F90")
endif()

project(PIMD VERSION ${PIMD_PROJECT_VERSION} LANGUAGES CXX C Fortran)
include(CTest)

# CMake support files are the canonical build-system implementation.  The
# top-level file is intentionally a short map of the build configuration.
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(SRC_DIR source)

include(PIMDOptions)
include(PIMDCoreDependencies)
include(PIMDCompilerFlags)
include(PIMDOpenMP)
include(PIMDTargets)
include(PIMDBackends)
include(PIMDLinkLibraries)
include(PIMDManual)
add_subdirectory(tools EXCLUDE_FROM_ALL)

if(BUILD_TESTING)
  add_subdirectory(tests)
endif()
