Skip to content

Emit warnings or errors if GCC version < 13 or Clang version < 16 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ project(bounded_integer LANGUAGES CXX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type" FORCE)
endif()
endif()

project(bounded_integer LANGUAGES CXX)
if(NOT DEFINED REQUIRED_GCC_VER )
set(REQUIRED_GCC_VER 13)
endif()

if(NOT DEFINED REQUIRED_CLANG_VER )
set(REQUIRED_CLANG_VER 16)
endif()

enable_testing()

Expand Down Expand Up @@ -40,7 +49,39 @@ if (NOT has_parent)
endif()
endif()

add_library(bounded STATIC)

if(DEFINED FATAL_ERR)
set(MFLAG_FETAL FATAL_ERROR)
else()
set(MFLAG_FETAL WARNING)
endif()

function(EMIT_VER_WARNINGS REQUIRED_VER)
cmake_parse_arguments(FLAG "Else" "IF" "FAIL" ${ARGN})
string(REPLACE "." ";" __VLIST ${CMAKE_CXX_COMPILER_VERSION})
list(GET __VLIST 0 CXX_CMP_V_1)
if(NOT DEFINED FLAG_FAIL)
set(FLAG_FAIL FALSE)
endif()
if(FLAG_FAIL)
set(MFLAG_FATAL FATAL_ERROR)
else()
set(MFLAG_FATAL WARNING)
endif()
if(${CXX_CMP_V_1} LESS ${REQUIRED_VER})
message(${MFLAG_FATAL} "${CMAKE_CXX_COMPILER_ID}: detected version ${CXX_CMP_V_1}(${CMAKE_CXX_COMPILER_VERSION}); you must use version ${REQUIRED_VER}+")
endif()
endfunction()

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
EMIT_VER_WARNINGS(${REQUIRED_CLANG_VER} FAIL TRUE)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
EMIT_VER_WARNINGS(${REQUIRED_GCC_VER} FAIL TRUE)
else()
message(WARNING "UNKNOWN Compiler")
endif()

add_library(bounded INTERFACE)

target_link_libraries(bounded
PUBLIC
Expand Down