Files

58 lines
1.9 KiB
CMake
Raw Permalink Normal View History

2026-08-11 17:40:36 +03:00
function(course_apply_warnings target_name)
if(MSVC)
target_compile_options(${target_name} PRIVATE /W4 /permissive-)
if(COURSE_WARNINGS_AS_ERRORS)
target_compile_options(${target_name} PRIVATE /WX)
endif()
else()
target_compile_options(
${target_name}
PRIVATE
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wshadow
)
if(COURSE_WARNINGS_AS_ERRORS)
target_compile_options(${target_name} PRIVATE -Werror)
endif()
endif()
endfunction()
function(course_set_cxx_standard target_name standard)
2026-08-12 13:47:50 +03:00
# 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()
2026-08-11 17:40:36 +03:00
endfunction()
2026-08-12 13:18:20 +03:00
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()