mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-29 18:07:16 +02:00
docs: Compilation warnings handling refactored
This commit is contained in:
@ -26,8 +26,9 @@ project(mp-units
|
|||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
# set paths to Conan packages
|
# set restrictive compilation warnings
|
||||||
include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL)
|
include(warnings)
|
||||||
|
set_warnings()
|
||||||
|
|
||||||
# enable static analysis
|
# enable static analysis
|
||||||
#enable_clang_tidy()
|
#enable_clang_tidy()
|
||||||
@ -36,10 +37,6 @@ include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL)
|
|||||||
# add project code
|
# add project code
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
# set restrictive compilation warnings
|
|
||||||
include(warnings)
|
|
||||||
set_warnings(mp-units INTERFACE)
|
|
||||||
|
|
||||||
# add usage example
|
# add usage example
|
||||||
add_subdirectory(example)
|
add_subdirectory(example)
|
||||||
|
|
||||||
|
@ -25,21 +25,13 @@
|
|||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
# Configure compiler warning level
|
# Configure compiler warning level
|
||||||
function(set_warnings target scope)
|
function(set_warnings)
|
||||||
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
|
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)
|
||||||
|
|
||||||
if(NOT TARGET ${target})
|
|
||||||
message(FATAL_ERROR "'${target}' is not a CMake target")
|
|
||||||
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
|
||||||
# /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
|
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
|
||||||
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
|
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
|
||||||
/w14263 # 'function': member function does not override any base class virtual member function
|
/w14263 # 'function': member function does not override any base class virtual member function
|
||||||
/w14265 # 'classname': class has virtual functions, but destructor is not
|
/w14265 # 'classname': class has virtual functions, but destructor is not
|
||||||
@ -67,7 +59,6 @@ function(set_warnings target scope)
|
|||||||
/w14928 # illegal copy-initialization; more than one user-defined
|
/w14928 # illegal copy-initialization; more than one user-defined
|
||||||
# conversion has been implicitly applied
|
# conversion has been implicitly applied
|
||||||
/permissive- # standards conformance mode for MSVC compiler.
|
/permissive- # standards conformance mode for MSVC compiler.
|
||||||
/wd4244 #
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CLANG_WARNINGS
|
set(CLANG_WARNINGS
|
||||||
@ -83,8 +74,9 @@ function(set_warnings target scope)
|
|||||||
-Wunused # warn on anything being unused
|
-Wunused # warn on anything being unused
|
||||||
-Woverloaded-virtual # warn if you overload (not override) a virtual function
|
-Woverloaded-virtual # warn if you overload (not override) a virtual function
|
||||||
-Wcast-qual # warn on dropping const or volatile qualifiers
|
-Wcast-qual # warn on dropping const or volatile qualifiers
|
||||||
# -Wconversion # warn on type conversions that may lose data
|
-Wconversion # warn on type conversions that may lose data
|
||||||
# -Wsign-conversion # warn on sign conversions
|
# disabled due to the truncating on UDLs
|
||||||
|
# -Wsign-conversion # warn on sign conversions
|
||||||
-Wnull-dereference # warn if a null dereference is detected
|
-Wnull-dereference # warn if a null dereference is detected
|
||||||
-Wdouble-promotion # warn if float is implicit promoted to double
|
-Wdouble-promotion # warn if float is implicit promoted to double
|
||||||
-Wformat=2 # warn on security issues around functions that format output (ie printf)
|
-Wformat=2 # warn on security issues around functions that format output (ie printf)
|
||||||
@ -106,11 +98,11 @@ function(set_warnings target scope)
|
|||||||
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} ${scope} ${MSVC_WARNINGS})
|
add_compile_options(${MSVC_WARNINGS})
|
||||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
target_compile_options(${target} ${scope} ${CLANG_WARNINGS})
|
add_compile_options(${CLANG_WARNINGS})
|
||||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
target_compile_options(${target} ${scope} ${GCC_WARNINGS})
|
add_compile_options(${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()
|
||||||
|
@ -27,6 +27,9 @@ if(NOT UNITS_BUILD_DOCS)
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# set paths to Conan packages (needed for doxygen)
|
||||||
|
include(${CMAKE_BINARY_DIR}/conan_paths.cmake OPTIONAL)
|
||||||
|
|
||||||
# Find all the public headers
|
# Find all the public headers
|
||||||
file(GLOB_RECURSE unitsPublicHeaders "${PROJECT_SOURCE_DIR}/src/*.h")
|
file(GLOB_RECURSE unitsPublicHeaders "${PROJECT_SOURCE_DIR}/src/*.h")
|
||||||
|
|
||||||
|
@ -22,6 +22,20 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
|
add_library(unit_tests_static_truncating
|
||||||
|
quantity_test.cpp
|
||||||
|
quantity_kind_test.cpp
|
||||||
|
quantity_point_kind_test.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(unit_tests_static_truncating
|
||||||
|
PRIVATE
|
||||||
|
mp-units::mp-units
|
||||||
|
)
|
||||||
|
target_compile_options(unit_tests_static_truncating
|
||||||
|
PRIVATE
|
||||||
|
$<IF:$<CXX_COMPILER_ID:MSVC>,/wd4242 /wd4244,-Wno-conversion>
|
||||||
|
)
|
||||||
|
|
||||||
add_library(unit_tests_static
|
add_library(unit_tests_static
|
||||||
cgs_test.cpp
|
cgs_test.cpp
|
||||||
chrono_test.cpp
|
chrono_test.cpp
|
||||||
@ -36,10 +50,7 @@ add_library(unit_tests_static
|
|||||||
fps_test.cpp
|
fps_test.cpp
|
||||||
kind_test.cpp
|
kind_test.cpp
|
||||||
math_test.cpp
|
math_test.cpp
|
||||||
quantity_test.cpp
|
|
||||||
quantity_point_test.cpp
|
quantity_point_test.cpp
|
||||||
quantity_kind_test.cpp
|
|
||||||
quantity_point_kind_test.cpp
|
|
||||||
ratio_test.cpp
|
ratio_test.cpp
|
||||||
si_test.cpp
|
si_test.cpp
|
||||||
si_cgs_test.cpp
|
si_cgs_test.cpp
|
||||||
@ -52,5 +63,6 @@ add_library(unit_tests_static
|
|||||||
)
|
)
|
||||||
target_link_libraries(unit_tests_static
|
target_link_libraries(unit_tests_static
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
unit_tests_static_truncating
|
||||||
mp-units::mp-units
|
mp-units::mp-units
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user