Skip to content

Commit 1f3e469

Browse files
Added -Wall for Clang and GCC (openvinotoolkit#15513)
* Added -Wall for Clang and GCC * Fixes * Don't use /J * Fixed warnings * Fixed warnings * More fixes * Fixed for MSVC * Fixed more warnings on Windows * Suppressed some warnings in template plugin * Update src/tests/functional/plugin/shared/include/behavior/plugin/caching_tests.hpp * Added suppression for PT FE * Suppressed warnings in TF FE * Suppressed warnings on Core unit tests * Suppress warnings in python * Suppressed Windows warning for 3rd party modules * Suppresed one more warning
1 parent 6b50309 commit 1f3e469

File tree

312 files changed

+1260
-1289
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+1260
-1289
lines changed

cmake/developer_package/IEDevScriptsConfig.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function(ie_mark_target_as_cc TARGET_NAME)
292292
endif()
293293
target_link_libraries(${TARGET_NAME} PRIVATE ${cc_library})
294294

295-
if(NOT (SELECTIVE_BUILD STREQUAL "ON"))
295+
if(NOT SELECTIVE_BUILD STREQUAL "ON")
296296
return()
297297
endif()
298298

cmake/developer_package/compile_flags/os_flags.cmake

+125-62
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ include(ProcessorCount)
66
include(CheckCXXCompilerFlag)
77

88
#
9-
# disable_deprecated_warnings()
9+
# ov_disable_deprecated_warnings()
1010
#
1111
# Disables deprecated warnings generation in current scope (directory, function)
1212
# Defines ie_c_cxx_deprecated varaible which contains C / C++ compiler flags
1313
#
14-
macro(disable_deprecated_warnings)
14+
macro(ov_disable_deprecated_warnings)
1515
if(WIN32)
1616
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
1717
set(ie_c_cxx_deprecated "/Qdiag-disable:1478,1786")
1818
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
1919
set(ie_c_cxx_deprecated "/wd4996")
20+
elseif(OV_COMPILER_IS_CLANG)
21+
set(ie_c_cxx_deprecated "-Wno-deprecated-declarations")
2022
endif()
2123
else()
2224
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
2325
set(ie_c_cxx_deprecated "-diag-disable=1478,1786")
24-
else()
26+
elseif(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX)
2527
set(ie_c_cxx_deprecated "-Wno-deprecated-declarations")
2628
endif()
2729
endif()
@@ -36,30 +38,36 @@ macro(disable_deprecated_warnings)
3638
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated}")
3739
endmacro()
3840

41+
macro(disable_deprecated_warnings)
42+
ov_disable_deprecated_warnings()
43+
endmacro()
44+
3945
#
40-
# ie_deprecated_no_errors()
46+
# ov_deprecated_no_errors()
4147
#
4248
# Don't threat deprecated warnings as errors in current scope (directory, function)
4349
# Defines ie_c_cxx_deprecated_no_errors varaible which contains C / C++ compiler flags
4450
#
45-
macro(ie_deprecated_no_errors)
51+
macro(ov_deprecated_no_errors)
4652
if(WIN32)
4753
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
4854
set(ie_c_cxx_deprecated_no_errors "/Qdiag-warning:1478,1786")
4955
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
5056
# show 4996 only for /w4
5157
set(ie_c_cxx_deprecated_no_errors "/wd4996")
58+
elseif(OV_COMPILER_IS_CLANG)
59+
set(ie_c_cxx_deprecated_no_errors "-Wno-error=deprecated-declarations")
5260
endif()
5361
else()
5462
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
5563
set(ie_c_cxx_deprecated_no_errors "-diag-warning=1478,1786")
56-
else()
64+
elseif(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX)
5765
set(ie_c_cxx_deprecated_no_errors "-Wno-error=deprecated-declarations")
5866
endif()
67+
endif()
5968

60-
if(NOT ie_c_cxx_deprecated_no_errors)
61-
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}")
62-
endif()
69+
if(NOT ie_c_cxx_deprecated_no_errors)
70+
message(WARNING "Unsupported CXX compiler ${CMAKE_CXX_COMPILER_ID}")
6371
endif()
6472

6573
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_deprecated_no_errors}")
@@ -68,6 +76,25 @@ macro(ie_deprecated_no_errors)
6876
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated_no_errors}")
6977
endmacro()
7078

79+
#
80+
# ov_dev_package_no_errors()
81+
#
82+
# Exports flags for 3rdparty modules, but without errors
83+
#
84+
macro(ov_dev_package_no_errors)
85+
if(OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX)
86+
set(ie_c_cxx_dev_no_errors "-Wno-all")
87+
if(SUGGEST_OVERRIDE_SUPPORTED)
88+
set(ie_cxx_dev_no_errors "${ie_c_cxx_dev_no_errors} -Wno-error=suggest-override")
89+
endif()
90+
endif()
91+
92+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_dev_no_errors} ${ie_cxx_dev_no_errors}")
93+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${ie_c_cxx_dev_no_errors}")
94+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ie_c_cxx_dev_no_errors} ${ie_cxx_dev_no_errors}")
95+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_dev_no_errors}")
96+
endmacro()
97+
7198
#
7299
# ie_sse42_optimization_flags(<output flags>)
73100
#
@@ -238,6 +265,21 @@ function(ov_force_include target scope header_file)
238265
endif()
239266
endfunction()
240267

268+
#
269+
# ie_python_minimal_api(<target>)
270+
#
271+
# Set options to use only Python Limited API
272+
#
273+
function(ie_python_minimal_api target)
274+
# pybind11 uses a lot of API which is not a part of minimal python API subset
275+
# Ref 1: https://docs.python.org/3.11/c-api/stable.html
276+
# Ref 2: https://github.com/pybind/pybind11/issues/1755
277+
# target_compile_definitions(${target} PRIVATE Py_LIMITED_API=0x03090000)
278+
# if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
279+
# target_compile_options(${target} PRIVATE "-Wno-unused-variable")
280+
# endif()
281+
endfunction()
282+
241283
#
242284
# Compilation and linker flags
243285
#
@@ -262,34 +304,53 @@ if(ENABLE_COVERAGE)
262304
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
263305
endif()
264306

265-
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
266-
ie_add_compiler_flags(-fsigned-char)
267-
endif()
268-
269307
# Honor visibility properties for all target types
270308
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
271309
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
272310
set(CMAKE_C_VISIBILITY_PRESET hidden)
273311
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
274312

275-
function(ie_python_minimal_api target)
276-
# pybind11 uses a lot of API which is not a part of minimal python API subset
277-
# Ref 1: https://docs.python.org/3.11/c-api/stable.html
278-
# Ref 2: https://github.com/pybind/pybind11/issues/1755
279-
# target_compile_definitions(${target} PRIVATE Py_LIMITED_API=0x03090000)
280-
# if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
281-
# target_compile_options(${target} PRIVATE "-Wno-unused-variable")
282-
# endif()
283-
endfunction()
313+
if(CMAKE_CL_64)
314+
# Default char Type Is unsigned
315+
# ie_add_compiler_flags(/J)
316+
else()
317+
ie_add_compiler_flags(-fsigned-char)
318+
endif()
284319

285320
if(WIN32)
286-
ie_add_compiler_flags(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
287-
ie_add_compiler_flags(/EHsc) # no asynchronous structured exception handling
288-
ie_add_compiler_flags(/Gy) # remove unreferenced functions: function level linking
321+
#
322+
# Common options / warnings enabled
323+
#
324+
325+
ie_add_compiler_flags(/D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS)
326+
# no asynchronous structured exception handling
327+
ie_add_compiler_flags(/EHsc)
328+
# Allows the compiler to package individual functions in the form of packaged functions (COMDATs).
329+
ie_add_compiler_flags(/Gy)
330+
# This option helps ensure the fewest possible hard-to-find code defects. Similar to -Wall on GNU / Clang
331+
ie_add_compiler_flags(/W3)
332+
333+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
334+
# Increase Number of Sections in .Obj file
335+
ie_add_compiler_flags(/bigobj)
336+
# Build with multiple processes
337+
ie_add_compiler_flags(/MP)
338+
339+
if(AARCH64 AND NOT MSVC_VERSION LESS 1930)
340+
# otherwise, _ARM64_EXTENDED_INTRINSICS is defined, which defines 'mvn' macro
341+
ie_add_compiler_flags(/D_ARM64_DISTINCT_NEON_TYPES)
342+
endif()
343+
endif()
344+
345+
# Handle Large Addresses
289346
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
290347

291-
if (CMAKE_COMPILE_WARNING_AS_ERROR)
292-
if (CMAKE_VERSION VERSION_LESS 3.24)
348+
#
349+
# Warnings as errors
350+
#
351+
352+
if(CMAKE_COMPILE_WARNING_AS_ERROR)
353+
if(CMAKE_VERSION VERSION_LESS 3.24)
293354
ie_add_compiler_flags(/WX)
294355
endif()
295356
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /WX")
@@ -300,26 +361,16 @@ if(WIN32)
300361
endif()
301362
endif()
302363

303-
if(AARCH64 AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT MSVC_VERSION LESS 1930)
304-
# otherwise, _ARM64_EXTENDED_INTRINSICS is defined, which defines 'mvn' macro
305-
ie_add_compiler_flags(-D_ARM64_DISTINCT_NEON_TYPES)
306-
endif()
307-
308-
# Compiler specific flags
309-
310-
ie_add_compiler_flags(/bigobj)
311-
ie_add_compiler_flags(/MP)
312-
364+
#
313365
# Disable noisy warnings
366+
#
314367

315368
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
316369
# C4251 needs to have dll-interface to be used by clients of class
317370
ie_add_compiler_flags(/wd4251)
318371
# C4275 non dll-interface class used as base for dll-interface class
319372
ie_add_compiler_flags(/wd4275)
320-
endif()
321-
322-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
373+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
323374
# 161: unrecognized pragma
324375
# 177: variable was declared but never referenced
325376
# 556: not matched type of assigned function pointer
@@ -342,42 +393,50 @@ if(WIN32)
342393
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
343394
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
344395
else()
345-
if(CMAKE_COMPILE_WARNING_AS_ERROR AND CMAKE_VERSION VERSION_LESS 3.24)
346-
# TODO: enable for C sources as well
347-
# ie_add_compiler_flags(-Werror)
348-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
349-
endif()
396+
#
397+
# Common enabled warnings
398+
#
399+
400+
# allow linker eliminating the unused code and data from the final executable
350401
ie_add_compiler_flags(-ffunction-sections -fdata-sections)
402+
# emits text showing the command-line option controlling a diagnostic
351403
ie_add_compiler_flags(-fdiagnostics-show-option)
404+
405+
# This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid
406+
ie_add_compiler_flags(-Wall)
407+
# Warn if an undefined identifier is evaluated in an #if directive. Such identifiers are replaced with zero.
352408
ie_add_compiler_flags(-Wundef)
353-
ie_add_compiler_flags(-Wreturn-type)
354-
ie_add_compiler_flags(-Wunused-variable)
355409

356-
if(OV_COMPILER_IS_APPLECLANG)
357-
ie_add_compiler_flags(-Wswitch)
358-
set(CMAKE_CXX_FLAGS "-Woverloaded-virtual ${CMAKE_CXX_FLAGS}")
359-
else()
360-
ie_add_compiler_flags(-Wuninitialized -Winit-self)
361-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
362-
ie_add_compiler_flags(-Winconsistent-missing-override
363-
-Wstring-plus-int)
364-
else()
365-
ie_add_compiler_flags(-Wmaybe-uninitialized)
366-
check_cxx_compiler_flag("-Wsuggest-override" SUGGEST_OVERRIDE_SUPPORTED)
367-
if(SUGGEST_OVERRIDE_SUPPORTED)
368-
set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
369-
endif()
370-
endif()
410+
# TODO
411+
if(OV_COMPILER_IS_CLANG)
412+
ie_add_compiler_flags(-Wno-delete-non-abstract-non-virtual-dtor)
371413
endif()
372414

415+
check_cxx_compiler_flag("-Wsuggest-override" SUGGEST_OVERRIDE_SUPPORTED)
416+
if(SUGGEST_OVERRIDE_SUPPORTED)
417+
set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
418+
endif()
419+
420+
#
421+
# Warnings as errors
422+
#
423+
424+
if(CMAKE_COMPILE_WARNING_AS_ERROR AND CMAKE_VERSION VERSION_LESS 3.24)
425+
ie_add_compiler_flags(-Werror)
426+
endif()
427+
428+
#
373429
# Disable noisy warnings
430+
#
374431

375432
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
376433
# 177: function "XXX" was declared but never referenced
377434
ie_add_compiler_flags(-diag-disable=remark,177,2196)
378435
endif()
379436

437+
#
380438
# Linker flags
439+
#
381440

382441
if(APPLE)
383442
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip")
@@ -401,6 +460,10 @@ else()
401460
endif()
402461
endif()
403462

463+
# if(OV_COMPILER_IS_CLANG)
464+
# ie_add_compiler_flags(-Wshorten-64-to-32)
465+
# endif()
466+
404467
#
405468
# link_system_libraries(target <PUBLIC | PRIVATE | INTERFACE> <lib1 [lib2 lib3 ...]>)
406469
#

cmake/developer_package/target_flags.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ endif()
1818

1919
macro(_ie_process_msvc_generator_platform flag_name)
2020
# if cmake -A <ARM|ARM64> is passed
21-
if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
21+
if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
2222
set(AARCH64 ON)
2323
elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM")
2424
set(ARM ON)
@@ -31,7 +31,7 @@ macro(_ie_process_msvc_generator_platform flag_name)
3131
endif()
3232
endmacro()
3333

34-
if(MSVC64 OR MINGW64)
34+
if(MSVC OR MINGW64)
3535
_ie_process_msvc_generator_platform(X86_64)
3636
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
3737
_ie_process_msvc_generator_platform(X86)
@@ -49,7 +49,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
4949
set(X86_64 ON)
5050
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
5151
set(X86 ON)
52-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64.*|aarch64.*|AARCH64.*)")
52+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64.*|aarch64.*|AARCH64.*|ARM64.*)")
5353
set(AARCH64 ON)
5454
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
5555
set(ARM ON)

cmake/extra_modules.cmake

+11-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function(register_extra_modules)
9393
file(REMOVE "${devconfig_file}")
9494

9595
file(WRITE "${devconfig_file}" "\# !! AUTOGENERATED: DON'T EDIT !!\n\n")
96-
file(APPEND "${devconfig_file}" "ie_deprecated_no_errors()\n")
9796

9897
foreach(target IN LISTS ${openvino_export_components})
9998
if(target)
@@ -124,6 +123,17 @@ endif()\n")
124123
endif()
125124
list(APPEND extra_modules "${OpenVINO_SOURCE_DIR}/src/core/template_extension")
126125

126+
# add extra flags for compilation of extra modules:
127+
# since not all extra modules use OpenVINODeveloperPackage, we have to add these function calls here
128+
ov_dev_package_no_errors()
129+
ov_deprecated_no_errors()
130+
131+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
132+
# 'argument': conversion from 'size_t' to 'int', possible loss of data
133+
ie_add_compiler_flags(/wd4267)
134+
ie_add_compiler_flags(/wd4244)
135+
endif()
136+
127137
# add each extra module
128138
foreach(module_path IN LISTS extra_modules)
129139
if(module_path)

cmake/templates/InferenceEngineDeveloperPackageConfig.cmake.in

+3-8
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,8 @@ endif()
151151
# Extra Compile Flags
152152
#
153153

154-
if(CMAKE_COMPILER_IS_GNUCXX)
155-
ie_add_compiler_flags(-Wno-error=unused-variable)
156-
ie_add_compiler_flags(-Wno-error=unused-but-set-variable)
157-
if(SUGGEST_OVERRIDE_SUPPORTED)
158-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-suggest-override")
159-
endif()
160-
endif()
154+
# don't fail on strict compilation options in 3rd party modules
155+
ov_dev_package_no_errors()
161156

162157
# Don't threat deprecated API warnings as errors in 3rd party apps
163-
ie_deprecated_no_errors()
158+
ov_deprecated_no_errors()

0 commit comments

Comments
 (0)