Update: Using C++26 with contracts enabled
This commit is contained in:
@@ -21,7 +21,7 @@ function(add_course_exercise)
|
||||
endif()
|
||||
|
||||
if(NOT EXERCISE_STANDARD)
|
||||
set(EXERCISE_STANDARD 23)
|
||||
set(EXERCISE_STANDARD 26)
|
||||
endif()
|
||||
|
||||
set(target_name "${EXERCISE_MODULE}_${EXERCISE_NAME}")
|
||||
@@ -33,6 +33,11 @@ function(add_course_exercise)
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
)
|
||||
course_set_cxx_standard(${target_name} ${EXERCISE_STANDARD})
|
||||
|
||||
if(EXERCISE_STANDARD GREATER_EQUAL 26)
|
||||
course_enable_contracts(${target_name})
|
||||
endif()
|
||||
|
||||
course_apply_warnings(${target_name})
|
||||
|
||||
if(COURSE_BUILD_TESTS)
|
||||
|
||||
@@ -23,3 +23,22 @@ endfunction()
|
||||
function(course_set_cxx_standard target_name standard)
|
||||
target_compile_features(${target_name} PRIVATE cxx_std_${standard})
|
||||
endfunction()
|
||||
|
||||
function(course_enable_contracts target_name)
|
||||
if(NOT COURSE_ENABLE_CONTRACTS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16))
|
||||
return()
|
||||
endif()
|
||||
|
||||
target_compile_options(
|
||||
${target_name}
|
||||
PRIVATE
|
||||
-fcontracts
|
||||
-fcontract-evaluation-semantic=enforce
|
||||
)
|
||||
target_link_options(${target_name} PRIVATE -fcontracts)
|
||||
target_link_libraries(${target_name} PRIVATE course_contract_support)
|
||||
endfunction()
|
||||
|
||||
Reference in New Issue
Block a user