Skip to content

Commit

Permalink
test: simplify error flags
Browse files Browse the repository at this point in the history
Aggregate Jamfile error flags per compiler and update CI compiler versions with warnings-as-errors based on new cpp-actions entry flags.
  • Loading branch information
alandefreitas committed Jan 19, 2024
1 parent 8b566c1 commit fcb5f58
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 54 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ option(BOOST_URL_BUILD_TESTS "Build boost::url tests even if BUILD_TESTING is OF
option(BOOST_URL_BUILD_FUZZERS "Build boost::url fuzzers" OFF)
option(BOOST_URL_BUILD_EXAMPLES "Build boost::url examples" ${BOOST_URL_IS_ROOT})
option(BOOST_URL_DISABLE_THREADS "Disable threads" OFF)
option(BOOST_URL_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
set(BOOST_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../.." CACHE STRING "Boost source dir to use when running CMake from this directory")

#-------------------------------------------------
Expand Down Expand Up @@ -138,6 +139,7 @@ function(boost_url_setup_properties target)
target_link_libraries(${target} PUBLIC ${BOOST_URL_DEPENDENCIES})
target_compile_definitions(${target} PUBLIC $<IF:$<BOOL:${BUILD_SHARED_LIBS}>,BOOST_URL_DYN_LINK=1,BOOST_URL_STATIC_LINK=1>)
target_compile_definitions(${target} PRIVATE BOOST_URL_SOURCE)
target_compile_options(${target} PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/EHsc>)
endfunction()
add_library(boost_url ${BOOST_URL_HEADERS} ${BOOST_URL_SOURCES})
add_library(Boost::url ALIAS boost_url)
Expand Down
8 changes: 1 addition & 7 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ project boost/url
<define>BOOST_URL_SOURCE
<toolset>msvc-14.0:<build>no
# Warnings in dependencies
<toolset>gcc-7:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-8:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-9:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-11:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-12:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-13:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc,<target-os>windows:<cxxflags>"-Wno-error=array-bounds"
: common-requirements
<link>shared:<define>BOOST_URL_DYN_LINK=1
Expand Down
52 changes: 27 additions & 25 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,39 @@ if(NOT TARGET tests)
endif()

# Replicate error flags from Jamfile
set(BOOST_URL_TEST_FLAGS " ")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
else()
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(BOOST_URL_TEST_FLAGS "-Wall -Werror")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
else()
if (BOOST_URL_WARNINGS_AS_ERRORS)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7)
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
else()
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(BOOST_URL_TEST_FLAGS "-Wall -Werror")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
set(BOOST_URL_TEST_FLAGS "-Wall -Werror -Wno-unused-but-set-variable")
else()
set(BOOST_URL_TEST_FLAGS "-Wall -Werror")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
set(BOOST_URL_TEST_FLAGS "/W4 /WX")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "MSVC")
set(BOOST_URL_TEST_FLAGS "/W4 /WX")
endif()

# Print test configuration if running in CI
# This is useful for debugging CI failures related to warnings which might be false positives
if (DEFINED ENV{CI})
message(STATUS "Boost.URL Tests - Compiler ID: ${CMAKE_CXX_COMPILER_ID} / ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
message(STATUS "Boost.URL Tests - Compiler Frontend: ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
# Print test configuration if running in CI
# This is useful for debugging CI failures related to warnings which might be false positives
if (DEFINED ENV{CI})
message(STATUS "Boost.URL Tests - Compiler ID: ${CMAKE_CXX_COMPILER_ID} / ${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
message(STATUS "Boost.URL Tests - Compiler Frontend: ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
endif()
message(STATUS "Boost.URL Tests - Platform: ${CMAKE_SYSTEM_NAME} / ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Boost.URL Tests - C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Boost.URL Tests - Test error flags: ${BOOST_URL_TEST_FLAGS}")
endif()
message(STATUS "Boost.URL Tests - Platform: ${CMAKE_SYSTEM_NAME} / ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Boost.URL Tests - C++ standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Boost.URL Tests - Test error flags: ${BOOST_URL_TEST_FLAGS}")
endif()


set(SUITE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/../extra/test_main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../extra/test_suite.hpp)
Expand Down
25 changes: 5 additions & 20 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,16 @@ project

: requirements

<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
# Extra errors that are disabled by default
<toolset>msvc:<cxxflags>"/we4265"

# Warnings in dependencies
<toolset>gcc:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>gcc-7:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-8:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-9:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-11:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-12:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>gcc-13:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>clang-4:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>clang-5:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>clang-6:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>clang-13:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>clang-14:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>clang-15:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>gcc:<cxxflags>"-Wno-maybe-uninitialized"
<toolset>clang:<cxxflags>"-Wno-unused-but-set-variable"
<toolset>gcc,<target-os>windows:<cxxflags>"-Wno-error=array-bounds"
# different typeinfos confuse ubsan

# Different typeinfos confuse ubsan
<undefined-sanitizer>norecover:<link>static
<undefined-sanitizer>norecover:<visibility>global
;
Expand All @@ -47,9 +35,6 @@ project

: requirements

<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
<toolset>gcc:<cxxflags>"-Wno-unused-but-set-variable" # Warnings in dependencies
<toolset>clang:<cxxflags>"-Wno-unknown-warning-option"
<toolset>clang-13:<cxxflags>"-Wno-unused-but-set-variable" # Warnings in dependencies
Expand Down
5 changes: 4 additions & 1 deletion test/limits/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ target_compile_definitions(boost_url_small_limits PUBLIC BOOST_URL_MAX_SIZE=16 B
add_executable(boost_url_limits limits.cpp Jamfile ${SUITE_FILES})
target_include_directories(boost_url_limits PRIVATE ../../include ../../extra ../../..)
target_link_libraries(boost_url_limits PRIVATE boost_url_small_limits)
set_source_files_properties(limits.cpp PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
if (DEFINED BOOST_URL_TEST_FLAGS AND NOT BOOST_URL_TEST_FLAGS STREQUAL "")
set_source_files_properties(limits.cpp PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
set_target_properties(boost_url_small_limits PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
endif ()

# Folders
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES limits.cpp Jamfile)
Expand Down
5 changes: 4 additions & 1 deletion test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

# Files
file(GLOB_RECURSE BOOST_URL_TESTS_FILES CONFIGURE_DEPENDS *.cpp *.hpp)
set_source_files_properties(${BOOST_URL_TESTS_FILES} PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
if (DEFINED BOOST_URL_TEST_FLAGS AND NOT BOOST_URL_TEST_FLAGS STREQUAL "")
set_source_files_properties(${BOOST_URL_TESTS_FILES} PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
set_target_properties(boost_url PROPERTIES COMPILE_FLAGS ${BOOST_URL_TEST_FLAGS})
endif()
set_property(SOURCE doc_grammar.cpp PROPERTY COMPILE_FLAGS "")
set_property(SOURCE doc_3_urls.cpp PROPERTY COMPILE_FLAGS "")
list(APPEND BOOST_URL_TESTS_FILES CMakeLists.txt Jamfile)
Expand Down

0 comments on commit fcb5f58

Please sign in to comment.