Update: Using C++26 with contracts enabled
This commit is contained in:
@@ -21,7 +21,20 @@ function(course_apply_warnings target_name)
|
||||
endfunction()
|
||||
|
||||
function(course_set_cxx_standard target_name standard)
|
||||
target_compile_features(${target_name} PRIVATE cxx_std_${standard})
|
||||
# Use explicit -std flags so older CLion/CMake builds still get C++26.
|
||||
if(standard GREATER_EQUAL 26)
|
||||
target_compile_options(${target_name} PRIVATE -std=c++26)
|
||||
elseif(standard GREATER_EQUAL 23)
|
||||
target_compile_options(${target_name} PRIVATE -std=c++23)
|
||||
elseif(standard GREATER_EQUAL 20)
|
||||
target_compile_options(${target_name} PRIVATE -std=c++20)
|
||||
elseif(standard GREATER_EQUAL 17)
|
||||
target_compile_options(${target_name} PRIVATE -std=c++17)
|
||||
elseif(standard GREATER_EQUAL 14)
|
||||
target_compile_options(${target_name} PRIVATE -std=c++14)
|
||||
else()
|
||||
target_compile_options(${target_name} PRIVATE -std=c++11)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(course_enable_contracts target_name)
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
# 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")
|
||||
# GCC 16 toolchain for C++26 and contracts.
|
||||
find_program(
|
||||
COURSE_GCC16_C
|
||||
NAMES gcc-16
|
||||
HINTS /opt/homebrew/bin /usr/local/bin /opt/local/bin
|
||||
)
|
||||
find_program(
|
||||
COURSE_GCC16_CXX
|
||||
NAMES g++-16
|
||||
HINTS /opt/homebrew/bin /usr/local/bin /opt/local/bin
|
||||
)
|
||||
|
||||
if(NOT COURSE_GCC16_CXX)
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"g++-16 not found. Install GCC 16, e.g. 'brew install gcc@16', "
|
||||
"then ensure g++-16 is on your PATH."
|
||||
)
|
||||
endif()
|
||||
|
||||
set(CMAKE_C_COMPILER "${COURSE_GCC16_C}" CACHE FILEPATH "C compiler" FORCE)
|
||||
set(CMAKE_CXX_COMPILER "${COURSE_GCC16_CXX}" CACHE FILEPATH "C++ compiler" FORCE)
|
||||
|
||||
Reference in New Issue
Block a user