diff --git a/.gitignore b/.gitignore index ca938c0..d3c6e70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Build directories build/ +build-gcc26/ cmake-build-*/ out/ diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..d1a37a5 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,58 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "displayName": "Default (system compiler)", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "COURSE_ENABLE_CONTRACTS": "ON" + } + }, + { + "name": "gcc26-contracts", + "displayName": "GCC 16 + C++26 contracts (recommended)", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build-gcc26", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_C_COMPILER": "/opt/homebrew/bin/gcc-16", + "CMAKE_CXX_COMPILER": "/opt/homebrew/bin/g++-16", + "COURSE_ENABLE_CONTRACTS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + }, + { + "name": "gcc26-contracts", + "configurePreset": "gcc26-contracts" + } + ], + "testPresets": [ + { + "name": "default", + "configurePreset": "default", + "output": { + "outputOnFailure": true + } + }, + { + "name": "gcc26-contracts", + "configurePreset": "gcc26-contracts", + "output": { + "outputOnFailure": true + } + } + ] +} diff --git a/cmake/toolchains/gcc-16.cmake b/cmake/toolchains/gcc-16.cmake new file mode 100644 index 0000000..2508ee5 --- /dev/null +++ b/cmake/toolchains/gcc-16.cmake @@ -0,0 +1,3 @@ +# Use GCC 16 for C++26 contracts support on macOS (Homebrew). +set(CMAKE_C_COMPILER "/opt/homebrew/bin/gcc-16" CACHE FILEPATH "C compiler") +set(CMAKE_CXX_COMPILER "/opt/homebrew/bin/g++-16" CACHE FILEPATH "C++ compiler") diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt new file mode 100644 index 0000000..8fa3cfe --- /dev/null +++ b/support/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(course_contract_support STATIC contract_handler.cpp) +target_compile_features(course_contract_support PUBLIC cxx_std_26) +set_target_properties(course_contract_support PROPERTIES POSITION_INDEPENDENT_CODE ON) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND COURSE_ENABLE_CONTRACTS) + target_compile_options(course_contract_support PRIVATE -fcontracts) + target_link_options(course_contract_support PRIVATE -fcontracts) +endif() diff --git a/support/contract_handler.cpp b/support/contract_handler.cpp new file mode 100644 index 0000000..d53faff --- /dev/null +++ b/support/contract_handler.cpp @@ -0,0 +1,6 @@ +#include +#include + +void handle_contract_violation(const std::contracts::contract_violation&) { + std::abort(); +}