mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
build: scope
parameter added to set_warnings()
This commit is contained in:
@ -38,7 +38,7 @@ add_subdirectory(src)
|
|||||||
|
|
||||||
# set restrictive compilation warnings
|
# set restrictive compilation warnings
|
||||||
include(warnings)
|
include(warnings)
|
||||||
set_warnings(mp-units)
|
set_warnings(mp-units INTERFACE)
|
||||||
|
|
||||||
# add usage example
|
# add usage example
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
|
@ -25,13 +25,17 @@
|
|||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
# Configure compiler warning level
|
# Configure compiler warning level
|
||||||
function(set_warnings target)
|
function(set_warnings target scope)
|
||||||
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
|
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
|
||||||
|
|
||||||
if(NOT TARGET ${target})
|
if(NOT TARGET ${target})
|
||||||
message(FATAL_ERROR "'${target}' is not a CMake target")
|
message(FATAL_ERROR "'${target}' is not a CMake target")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT (scope STREQUAL "PRIVATE" OR scope STREQUAL "PUBLIC" OR scope STREQUAL "INTERFACE"))
|
||||||
|
message(FATAL_ERROR "'${scope}' is not one of (PRIVATE, PUBLIC, INTERFACE)")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(MSVC_WARNINGS
|
set(MSVC_WARNINGS
|
||||||
/W4 # Baseline reasonable warnings
|
/W4 # Baseline reasonable warnings
|
||||||
/w14062 # enumerator 'identifier' in a switch of enum 'enumeration' is not handled
|
/w14062 # enumerator 'identifier' in a switch of enum 'enumeration' is not handled
|
||||||
@ -101,11 +105,11 @@ function(set_warnings target)
|
|||||||
if(MSVC)
|
if(MSVC)
|
||||||
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
|
||||||
target_compile_options(${target} INTERFACE ${MSVC_WARNINGS})
|
target_compile_options(${target} ${scope} ${MSVC_WARNINGS})
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
target_compile_options(${target} INTERFACE ${CLANG_WARNINGS})
|
target_compile_options(${target} ${scope} ${CLANG_WARNINGS})
|
||||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
target_compile_options(${target} INTERFACE ${GCC_WARNINGS})
|
target_compile_options(${target} ${scope} ${GCC_WARNINGS})
|
||||||
else()
|
else()
|
||||||
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
|
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
|
||||||
endif()
|
endif()
|
||||||
|
Reference in New Issue
Block a user