# The oldest CMake version this file is written for. Older versions refuse
# to run it rather than misreading it.
cmake_minimum_required(VERSION 3.21)
# The project's name, and the one language it uses: C++ (CXX).
project(fines LANGUAGES CXX)

# A library made from fines.cpp. Anything that links to it gets its include
# directory and needs C++20.
# STATIC: the library's code is copied into each program that links it.
add_library(build_fines STATIC fines.cpp)
# Where fines.hpp is: this directory. PUBLIC passes the setting on to every
# target that links build_fines, so main.cpp finds the header too.
target_include_directories(build_fines PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# Compile with C++20, and require it of every user too (PUBLIC).
target_compile_features(build_fines PUBLIC cxx_std_20)
# Warnings on, and every warning an error. PRIVATE: for this target only.
target_compile_options(build_fines PRIVATE -Wall -Wextra -Wpedantic -Werror)

# A program that uses the library.
# A program named build_fines_report, made from main.cpp.
add_executable(build_fines_report main.cpp)
# Link it with the library. This also hands it the library's PUBLIC settings:
# the include directory and C++20.
target_link_libraries(build_fines_report PRIVATE build_fines)
target_compile_options(build_fines_report PRIVATE -Wall -Wextra -Wpedantic -Werror)

# A test, run by `ctest`.
# enable_testing() turns on CTest for this directory. The test is an ordinary
# program; add_test registers it under a name, and it passes if it exits
# with status 0.
enable_testing()
add_executable(build_fines_check check_fines.cpp)
target_link_libraries(build_fines_check PRIVATE build_fines)
target_compile_options(build_fines_check PRIVATE -Wall -Wextra -Wpedantic -Werror)
add_test(NAME build_fines_check COMMAND build_fines_check)
