ParaViewCompilerExtraFlags.cmake
Go to the documentation of this file.
1 if (CMAKE_COMPILER_IS_GNUCXX)
2 
3  include(CheckCXXCompilerFlag)
4 
5  # Additional warnings for GCC
6  set(paraview_extra_warning_flags
7  -Wnon-virtual-dtor
8  -Wno-long-long
9  -Wcast-align
10  -Wchar-subscripts
11  -Wall
12  -Wextra
13  -Wpointer-arith
14  -Wformat-security
15  -Woverloaded-virtual
16  -Wshadow
17  -Wunused-parameter
18  -fno-check-new
19  -Werror=undef)
20 
21  # This flag is useful as not returning from a non-void function is an error
22  # with MSVC, but it is not supported on all GCC compiler versions
23  check_cxx_compiler_flag(-Werror=return-type HAVE_GCC_ERROR_RETURN_TYPE)
24  if (HAVE_GCC_ERROR_RETURN_TYPE)
25  list(APPEND paraview_extra_warning_flags
26  -Werror=return-type)
27  endif ()
28 
29  # If we are compiling on Linux then set some extra linker flags too
30  if (CMAKE_SYSTEM_NAME MATCHES "Linux")
31  option(PARAVIEW_LINKER_FATAL_WARNINGS "Specify if linker warnings must be considered as errors." OFF)
32  mark_as_advanced(PARAVIEW_LINKER_FATAL_WARNINGS)
33  if (TARGET paraviewbuild)
34  # XXX(cmake-3.13): use `target_link_options`
35  set_property(TARGET paraviewbuild APPEND
36  PROPERTY
37  INTERFACE_LINK_OPTIONS
38  "$<$<BOOL:${PARAVIEW_LINKER_FATAL_WARNINGS}>:LINKER:--fatal-warnings>")
39  endif ()
40  endif ()
41 
42  # Set up the CXX_FLAGS for extra warnings
43  option(PARAVIEW_EXTRA_COMPILER_WARNINGS
44  "Add compiler flags to do stricter checking" OFF)
45  if (PARAVIEW_EXTRA_COMPILER_WARNINGS)
46  if (TARGET paraviewbuild)
47  target_compile_options(paraviewbuild
48  INTERFACE
49  "$<$<COMPILE_LANGUAGE:CXX>:${paraview_extra_warning_flags}>")
50  endif ()
51  endif ()
52 endif ()
53 
54 # Intel OneAPI compilers >= 2021.2.0 turn on "fast math" at any non-zero
55 # optimization level. Suppress this non-standard behavior using the
56 # `-fp-model=precise` flag.
57 set(intel_oneapi_compiler_detections)
58 set(intel_oneapi_compiler_version_min "2021.2.0")
59 foreach (lang IN ITEMS C CXX Fortran)
60  if (CMAKE_VERSION VERSION_LESS "3.14" AND lang STREQUAL "Fortran") # XXX(cmake-3.14): `Fortran_COMPILER_ID` genex
61  continue ()
62  endif ()
63  # Detect the IntelLLVM compiler for the given language.
64  set(is_lang "$<COMPILE_LANGUAGE:${lang}>")
65  set(is_intelllvm "$<${lang}_COMPILER_ID:IntelLLVM>")
66  set(is_intelllvm_fastmath_assuming_version "$<VERSION_GREATER_EQUAL:$<${lang}_COMPILER_VERSION>,${intel_oneapi_compiler_version_min}>")
67  list(APPEND intel_oneapi_compiler_detections
68  "$<AND:${is_lang},${is_intelllvm},${is_intelllvm_fastmath_assuming_version}>")
69 endforeach ()
70 string(REPLACE ";" "," intel_oneapi_compiler_detections "${intel_oneapi_compiler_detections}")
71 if (TARGET paraviewbuild)
72  target_compile_options(paraviewbuild
73  INTERFACE
74  "$<BUILD_INTERFACE:$<$<OR:${intel_oneapi_compiler_detections}>:-fp-model=precise>>")
75 endif ()
string
language
parameter