diff --git a/build-support/custom-modules/ns3-compiler-and-linker-support.cmake b/build-support/custom-modules/ns3-compiler-and-linker-support.cmake index 5a676a760..fe8d44567 100644 --- a/build-support/custom-modules/ns3-compiler-and-linker-support.cmake +++ b/build-support/custom-modules/ns3-compiler-and-linker-support.cmake @@ -54,9 +54,25 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") "GNU ${CMAKE_CXX_COMPILER_VERSION} ${below_minimum_msg} ${GNU_MinVersion}" ) endif() - if((CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0.0")) - set(GCC_PEDANTIC_SEMICOLON TRUE) + + # Check if pedantic throws warning in trailing semicolon after {} scope + # (frequently used to make macros look like functions) + include(CheckCXXSourceCompiles) + set(CMAKE_REQUIRED_FLAGS "-Wall -Wpedantic -Werror") + check_cxx_source_compiles( + " + int test(){ return 0; }; + int main(){ + return test(); + } + " + GCC_WORKING_PEDANTIC_SEMICOLON + ) + unset(CMAKE_REQUIRED_FLAGS) + if("${GCC_WORKING_PEDANTIC_SEMICOLON}" STREQUAL "") + set(GCC_WORKING_PEDANTIC_SEMICOLON 0) endif() + if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "12.2.0")) # PCH causes weird errors on certain versions of GCC when C++20 is enabled # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106799 diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 958f0b06a..71807bb0b 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -221,9 +221,7 @@ macro(process_options) endif() else() add_compile_options(-Wall) # -Wextra - # Pedantic checks in GCC < 10 include extra semicolon, which we use a lot - # to make macros look like function calls - if(NOT (DEFINED GCC_PEDANTIC_SEMICOLON)) + if(${GCC_WORKING_PEDANTIC_SEMICOLON}) add_compile_options(-Wpedantic) endif() if(${NS3_WARNINGS_AS_ERRORS})