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