@@ -6,22 +6,24 @@ include(ProcessorCount)
6
6
include (CheckCXXCompilerFlag)
7
7
8
8
#
9
- # disable_deprecated_warnings ()
9
+ # ov_disable_deprecated_warnings ()
10
10
#
11
11
# Disables deprecated warnings generation in current scope (directory, function)
12
12
# Defines ie_c_cxx_deprecated varaible which contains C / C++ compiler flags
13
13
#
14
- macro (disable_deprecated_warnings )
14
+ macro (ov_disable_deprecated_warnings )
15
15
if (WIN32 )
16
16
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
17
17
set (ie_c_cxx_deprecated "/Qdiag-disable:1478,1786" )
18
18
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
19
19
set (ie_c_cxx_deprecated "/wd4996" )
20
+ elseif (OV_COMPILER_IS_CLANG)
21
+ set (ie_c_cxx_deprecated "-Wno-deprecated-declarations" )
20
22
endif ()
21
23
else ()
22
24
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
23
25
set (ie_c_cxx_deprecated "-diag-disable=1478,1786" )
24
- else ( )
26
+ elseif (OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX )
25
27
set (ie_c_cxx_deprecated "-Wno-deprecated-declarations" )
26
28
endif ()
27
29
endif ()
@@ -36,30 +38,36 @@ macro(disable_deprecated_warnings)
36
38
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated} " )
37
39
endmacro ()
38
40
41
+ macro (disable_deprecated_warnings)
42
+ ov_disable_deprecated_warnings()
43
+ endmacro ()
44
+
39
45
#
40
- # ie_deprecated_no_errors ()
46
+ # ov_deprecated_no_errors ()
41
47
#
42
48
# Don't threat deprecated warnings as errors in current scope (directory, function)
43
49
# Defines ie_c_cxx_deprecated_no_errors varaible which contains C / C++ compiler flags
44
50
#
45
- macro (ie_deprecated_no_errors )
51
+ macro (ov_deprecated_no_errors )
46
52
if (WIN32 )
47
53
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
48
54
set (ie_c_cxx_deprecated_no_errors "/Qdiag-warning:1478,1786" )
49
55
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
50
56
# show 4996 only for /w4
51
57
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" )
52
60
endif ()
53
61
else ()
54
62
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
55
63
set (ie_c_cxx_deprecated_no_errors "-diag-warning=1478,1786" )
56
- else ( )
64
+ elseif (OV_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCXX )
57
65
set (ie_c_cxx_deprecated_no_errors "-Wno-error=deprecated-declarations" )
58
66
endif ()
67
+ endif ()
59
68
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} " )
63
71
endif ()
64
72
65
73
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${ie_c_cxx_deprecated_no_errors} " )
@@ -68,6 +76,25 @@ macro(ie_deprecated_no_errors)
68
76
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ie_c_cxx_deprecated_no_errors} " )
69
77
endmacro ()
70
78
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
+
71
98
#
72
99
# ie_sse42_optimization_flags(<output flags>)
73
100
#
@@ -238,6 +265,21 @@ function(ov_force_include target scope header_file)
238
265
endif ()
239
266
endfunction ()
240
267
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
+
241
283
#
242
284
# Compilation and linker flags
243
285
#
@@ -262,34 +304,53 @@ if(ENABLE_COVERAGE)
262
304
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" )
263
305
endif ()
264
306
265
- if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
266
- ie_add_compiler_flags(-fsigned-char)
267
- endif ()
268
-
269
307
# Honor visibility properties for all target types
270
308
set (CMAKE_POLICY_DEFAULT_CMP0063 NEW)
271
309
set (CMAKE_CXX_VISIBILITY_PRESET hidden)
272
310
set (CMAKE_C_VISIBILITY_PRESET hidden)
273
311
set (CMAKE_VISIBILITY_INLINES_HIDDEN ON )
274
312
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 ()
284
319
285
320
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
289
346
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE" )
290
347
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)
293
354
ie_add_compiler_flags(/WX)
294
355
endif ()
295
356
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /WX" )
@@ -300,26 +361,16 @@ if(WIN32)
300
361
endif ()
301
362
endif ()
302
363
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
+ #
313
365
# Disable noisy warnings
366
+ #
314
367
315
368
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
316
369
# C4251 needs to have dll-interface to be used by clients of class
317
370
ie_add_compiler_flags(/wd4251)
318
371
# C4275 non dll-interface class used as base for dll-interface class
319
372
ie_add_compiler_flags(/wd4275)
320
- endif ()
321
-
322
- if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
373
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
323
374
# 161: unrecognized pragma
324
375
# 177: variable was declared but never referenced
325
376
# 556: not matched type of assigned function pointer
@@ -342,42 +393,50 @@ if(WIN32)
342
393
string (REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} " )
343
394
string (REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} " )
344
395
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
350
401
ie_add_compiler_flags(-ffunction-sections -fdata-sections)
402
+ # emits text showing the command-line option controlling a diagnostic
351
403
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.
352
408
ie_add_compiler_flags(-Wundef)
353
- ie_add_compiler_flags(-Wreturn-type )
354
- ie_add_compiler_flags(-Wunused-variable )
355
409
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)
371
413
endif ()
372
414
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
+ #
373
429
# Disable noisy warnings
430
+ #
374
431
375
432
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" )
376
433
# 177: function "XXX" was declared but never referenced
377
434
ie_add_compiler_flags(-diag-disable=remark,177,2196)
378
435
endif ()
379
436
437
+ #
380
438
# Linker flags
439
+ #
381
440
382
441
if (APPLE )
383
442
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-dead_strip" )
@@ -401,6 +460,10 @@ else()
401
460
endif ()
402
461
endif ()
403
462
463
+ # if(OV_COMPILER_IS_CLANG)
464
+ # ie_add_compiler_flags(-Wshorten-64-to-32)
465
+ # endif()
466
+
404
467
#
405
468
# link_system_libraries(target <PUBLIC | PRIVATE | INTERFACE> <lib1 [lib2 lib3 ...]>)
406
469
#
0 commit comments