2026-08-11 17:40:36 +03:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
|
|
|
|
|
|
|
|
|
project(
|
|
|
|
|
modern_cpp_course
|
|
|
|
|
VERSION 1.0.0
|
|
|
|
|
DESCRIPTION "Modern C++ course from basics to C++26"
|
|
|
|
|
LANGUAGES CXX
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 26)
|
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
2026-08-12 13:47:50 +03:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"GCC 16+ is required (found ${CMAKE_CXX_COMPILER_VERSION}). "
|
|
|
|
|
"Use the 'default' CMake preset or cmake/toolchains/gcc-16.cmake."
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
message(
|
|
|
|
|
FATAL_ERROR
|
|
|
|
|
"This project requires GCC 16+. Found compiler: ${CMAKE_CXX_COMPILER_ID}. "
|
|
|
|
|
"Select the GCC 16 toolchain / default CMake preset in CLion."
|
|
|
|
|
)
|
|
|
|
|
endif()
|
|
|
|
|
|
2026-08-11 17:40:36 +03:00
|
|
|
option(COURSE_BUILD_TESTS "Build Google Test exercise targets" ON)
|
|
|
|
|
option(COURSE_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
|
2026-08-12 13:18:20 +03:00
|
|
|
option(COURSE_ENABLE_CONTRACTS "Enable C++26 contracts on GCC 16+" ON)
|
2026-08-11 17:40:36 +03:00
|
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
|
|
|
|
|
|
|
|
|
include(CourseOptions)
|
|
|
|
|
include(CourseExercise)
|
|
|
|
|
|
2026-08-12 13:18:20 +03:00
|
|
|
add_subdirectory(support)
|
|
|
|
|
|
2026-08-11 17:40:36 +03:00
|
|
|
if(COURSE_BUILD_TESTS)
|
|
|
|
|
include(FetchContent)
|
|
|
|
|
FetchContent_Declare(
|
|
|
|
|
googletest
|
|
|
|
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
|
|
|
|
GIT_TAG v1.15.2
|
|
|
|
|
)
|
|
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
|
FetchContent_MakeAvailable(googletest)
|
|
|
|
|
enable_testing()
|
|
|
|
|
include(GoogleTest)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
add_subdirectory(modules)
|
2026-08-12 13:47:50 +03:00
|
|
|
|
|
|
|
|
include(Cppcheck)
|
|
|
|
|
course_add_cppcheck_targets()
|