Skip to content
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

Update compiler warning levels #4558

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
137 changes: 78 additions & 59 deletions .github/workflows/build_and_test.yml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
-DBUILD_SHARED_LIBS=TRUE \
-DCMAKE_BUILD_TYPE=Debug \
-DOPENDDS_BOOTTIME_TIMERS=TRUE \
-DOPENDDS_COMPILE_WARNINGS=WARNING \
mitza-oci marked this conversation as resolved.
Show resolved Hide resolved
-DOPENDDS_SECURITY=TRUE \
-DOPENDDS_ACE_TAO_SRC=$GITHUB_WORKSPACE/OpenDDS/build/ACE_TAO \
-DOPENDDS_MPC=$GITHUB_WORKSPACE/MPC \
Expand Down Expand Up @@ -132,6 +133,7 @@ jobs:
-DCMAKE_UNITY_BUILD=TRUE \
-DBUILD_SHARED_LIBS=FALSE \
-DCMAKE_BUILD_TYPE=Debug \
-DOPENDDS_COMPILE_WARNINGS=WARNING \
-DOPENDDS_ACE_TAO_SRC=$GITHUB_WORKSPACE/OpenDDS/build/ACE_TAO \
-DOPENDDS_MPC=$GITHUB_WORKSPACE/MPC \
-DOPENDDS_BUILD_TESTS=TRUE \
Expand Down Expand Up @@ -176,6 +178,7 @@ jobs:
-DCMAKE_UNITY_BUILD=TRUE \
-DBUILD_SHARED_LIBS=TRUE \
-DCMAKE_BUILD_TYPE=Debug \
-DOPENDDS_COMPILE_WARNINGS=WARNING \
-DOPENDDS_ACE_TAO_SRC=$GITHUB_WORKSPACE/OpenDDS/build/ACE_TAO \
-DOPENDDS_MPC=$GITHUB_WORKSPACE/MPC \
-DOPENDDS_BUILD_TESTS=TRUE \
Expand Down Expand Up @@ -228,6 +231,7 @@ jobs:
cmake -B build-host \
-G Ninja \
-DBUILD_SHARED_LIBS=FALSE \
-DOPENDDS_COMPILE_WARNINGS=WARNING \
-DOPENDDS_JUST_BUILD_HOST_TOOLS=TRUE
- uses: ammaraskar/gcc-problem-matcher@0.3.0
- name: Build Host Tools
Expand All @@ -242,6 +246,7 @@ jobs:
-DBUILD_SHARED_LIBS=TRUE \
-DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=android-29 \
--toolchain ${{ steps.setup-ndk.outputs.ndk-path }}/build/cmake/android.toolchain.cmake \
-DOPENDDS_COMPILE_WARNINGS=WARNING \
-DOPENDDS_CMAKE_VERBOSE=all \
-DOPENDDS_HOST_TOOLS=$(realpath build-host)
- name: Build Target
Expand Down Expand Up @@ -287,6 +292,7 @@ jobs:
cd OpenDDS
cmake -B build^
-DBUILD_SHARED_LIBS=TRUE^
-DOPENDDS_COMPILE_WARNINGS=WARNING^
-DOPENDDS_ACE_TAO_SRC=${{ github.workspace }}\OpenDDS\build\ACE_TAO^
-DOPENDDS_MPC=${{ github.workspace }}\MPC^
-DOPENDDS_XERCES3=${{ env.VCPKG_INSTALLED_DIR }}/x64-windows^
Expand Down Expand Up @@ -343,6 +349,7 @@ jobs:
cmake -B build^
-DCMAKE_UNITY_BUILD=TRUE^
-DBUILD_SHARED_LIBS=FALSE^
-DOPENDDS_COMPILE_WARNINGS=WARNING^
-DOPENDDS_ACE_TAO_SRC=${{ github.workspace }}\OpenDDS\build\ACE_TAO^
-DOPENDDS_MPC=${{ github.workspace }}\MPC^
-DOPENDDS_XERCES3=${{ env.VCPKG_INSTALLED_DIR }}/x64-windows^
Expand Down Expand Up @@ -400,6 +407,7 @@ jobs:
cmake -B build^
-DCMAKE_UNITY_BUILD=TRUE^
-DBUILD_SHARED_LIBS=TRUE^
-DOPENDDS_COMPILE_WARNINGS=WARNING^
-DOPENDDS_ACE_TAO_SRC=${{ github.workspace }}\OpenDDS\build\ACE_TAO^
-DOPENDDS_MPC=${{ github.workspace }}\MPC^
-DOPENDDS_XERCES3=${{ env.VCPKG_INSTALLED_DIR }}/x64-windows^
Expand Down Expand Up @@ -456,6 +464,7 @@ jobs:
cmake -B build^
-DCMAKE_UNITY_BUILD=TRUE^
-DBUILD_SHARED_LIBS=FALSE^
-DOPENDDS_COMPILE_WARNINGS=WARNING^
-DOPENDDS_ACE_TAO_SRC=${{ github.workspace }}\OpenDDS\build\ACE_TAO^
-DOPENDDS_MPC=${{ github.workspace }}\MPC^
-DOPENDDS_XERCES3=${{ env.VCPKG_INSTALLED_DIR }}/x64-windows^
Expand Down
15 changes: 15 additions & 0 deletions build.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Clang]
warning=-Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef
error=-Werror

[AppleClang]
warning=-Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef
error=-Werror

[GNU]
warning=-Wall -Wpedantic -Wno-unused -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-include-dirs -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wundef
error=-Werror

[MSVC]
warning=/W4
error=/WX
28 changes: 25 additions & 3 deletions cmake/opendds_build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ set(_opendds_exec_perms
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)

function(_opendds_alias target)
# Load in build settings.
file(STRINGS "${OPENDDS_SOURCE_DIR}/build.ini" build_ini)
unset(section)
foreach(line IN LISTS build_ini)
if(line MATCHES "^\\[(.*)\\]$")
set(section "${CMAKE_MATCH_1}")
elseif(section AND line MATCHES "^([^=#]+)=(.*)$")
set(name "${CMAKE_MATCH_1}")
set(value "${CMAKE_MATCH_2}")
set("${section}-${name}" "${value}")
endif()
endforeach()

function(_opendds_target target)
# This is the name the target should be exported from CMake-build OpenDDS as
# or imported in the MPC-built OpenDDS CMake package. For consistency and
# convenience, alias it so we can use it within the OpenDDS CMake build.
Expand All @@ -18,6 +31,15 @@ function(_opendds_alias target)
add_executable("${name}" ALIAS "${target}")
endif()
set_target_properties(${target} PROPERTIES EXPORT_NAME "${name}")

if(OPENDDS_COMPILE_WARNINGS STREQUAL "WARNING" OR OPENDDS_COMPILE_WARNINGS STREQUAL "ERROR")
string(REPLACE " " ";" outvar ${${CMAKE_CXX_COMPILER_ID}-warning})
target_compile_options(${target} PRIVATE ${outvar})
if(OPENDDS_COMPILE_WARNINGS STREQUAL "ERROR")
string(REPLACE " " ";" outvar ${{CMAKE_CXX_COMPILER_ID}-error})
target_compile_options(${target} PRIVATE ${outvar})
endif()
endif()
endfunction()

function(_opendds_library target)
Expand All @@ -27,7 +49,7 @@ function(_opendds_library target)
cmake_parse_arguments(arg
"${no_value_options}" "${single_value_options}" "${multi_value_options}" ${ARGN})

_opendds_alias(${target})
_opendds_target(${target})
_opendds_cxx_std(${target} PUBLIC)
target_link_libraries(${target} PUBLIC OpenDDS_Config)

Expand Down Expand Up @@ -83,7 +105,7 @@ function(_opendds_executable target)
cmake_parse_arguments(arg
"${no_value_options}" "${single_value_options}" "${multi_value_options}" ${ARGN})

_opendds_alias(${target})
_opendds_target(${target})
_opendds_cxx_std(${target} PRIVATE)
target_link_libraries(${target} PRIVATE OpenDDS_Config)
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${OPENDDS_BIN_DIR}")
Expand Down
19 changes: 19 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ my @specs = # Array of array-refs, each inner array is an option group which
$argIndent . ' asan: Address Sanitizer, gcc/clang only' .
$argIndent . ' tsan: Thread Sanitizer, gcc/clang only' .
$argIndent . ' ubsan: Undefined Behavior Sanitizer, clang only',
'compile-warnings=s', 'Enable additional compiler warnings (empty)' .
$argIndent . 'If set to WARNING, enable additional warnings' .
$argIndent . 'If set to ERROR, enable additional warnings and treated them as errors',
],
['Required dependencies for OpenDDS:',
'ace=s', 'ACE (use ACE_ROOT, ACE_wrappers, or download)',
Expand Down Expand Up @@ -788,6 +791,7 @@ EOF
elsif ($opts{'compiler'} =~ /g\+\+|clang/) {
my $version_string = `$opts{'compiler'} --version`;
print "Compiler version: $version_string\n" if $opts{'verbose'};
$opts{'is apple clang'} = $version_string =~ /^Apple/;
if ($opts{'std'}) {
push(@{$opts{'macros'}}, 'CCFLAGS += -std=' . $opts{'std'});
print "Added platform_macros for -std=$opts{std}\n" if $opts{'verbose'};
Expand Down Expand Up @@ -825,6 +829,21 @@ EOF
}
}

if ($opts{'compile-warnings'} eq 'WARNING' or $opts{'compile-warnings'} eq 'ERROR') {
my ($section_names, $sections) = read_ini_file("$FindBin::RealBin/build.ini");
my %compiler_map = ( 'g++' => 'GNU', 'clang' => 'Clang', 'cl' => 'MSVC', 'cl.exe' => 'MSVC');
my $section = $compiler_map{$opts{'compiler'}};
if ($opts{'is apple clang'}) {
$section = 'AppleClang';
}
my $warning_flags = $sections->{$section}{'warning'};
my $error_flags = $sections->{$section}{'error'};
push(@{$opts{'mpcopts'}}, '-value_template', "compile_flags+=${warning_flags}");
if ($opts{'compile-warnings'} eq 'ERROR') {
push(@{$opts{'mpcopts'}}, '-value_template', "compile_flags+=${error_flags}");
}
}

sub looksRelative {
my $val = shift;
return substr($val, 0, 1) ne $slash && ($slash eq '/' || $val !~ /^[a-z]:/i);
Expand Down
7 changes: 7 additions & 0 deletions docs/devguide/building/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,13 @@ These are all the variables that are exclusive to building OpenDDS with CMake:
Enable this option to use CLOCK_BOOTTIME as the timer base clock instead of CLOCK_MONOTONIC.
Default is ``OFF``.

.. cmake:var:: OPENDDS_COMPILE_WARNINGS
iguessthislldo marked this conversation as resolved.
Show resolved Hide resolved
If set to ``WARNING``, enables additional compiler warnings when compiling OpenDDS.
If set to ``ERROR``, enables additional compiler warnings which are treated as errors when compiling OpenDDS.

.. versionadded:: 3.28

Speeding up the build
---------------------

Expand Down
5 changes: 5 additions & 0 deletions docs/news.d/compiler-warnings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. news-prs: 4558
.. news-start-section: Additions
- Added :cmake:var:`OPENDDS_COMPILE_WARNINGS` and ``configure`` option ``--compile-warnings=[WARNING|ERROR]`` to enable additional compiler warnings and treating them as errors.
.. news-end-section