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