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  target_link_options(paraviewbuild
33  INTERFACE
34  "$<$<BOOL:${PARAVIEW_LINKER_FATAL_WARNINGS}>:LINKER:--fatal-warnings>")
35  endif ()
36 
37  # Set up the CXX_FLAGS for extra warnings
38  option(PARAVIEW_EXTRA_COMPILER_WARNINGS
39  "Add compiler flags to do stricter checking" OFF)
40  if (PARAVIEW_EXTRA_COMPILER_WARNINGS)
41  if (TARGET paraviewbuild)
42  target_compile_options(paraviewbuild
43  INTERFACE
44  "$<$<COMPILE_LANGUAGE:CXX>:${paraview_extra_warning_flags}>")
45  endif ()
46  endif ()
47 endif ()
48 
49 # Intel OneAPI compilers >= 2021.2.0 turn on "fast math" at any non-zero
50 # optimization level. Suppress this non-standard behavior using the
51 # `-fp-model=precise` flag.
52 set(intel_oneapi_compiler_detections)
53 set(intel_oneapi_compiler_version_min "2021.2.0")
54 foreach (lang IN ITEMS C CXX Fortran)
55  if (CMAKE_VERSION VERSION_LESS "3.14" AND lang STREQUAL "Fortran") # XXX(cmake-3.14): `Fortran_COMPILER_ID` genex
56  continue ()
57  endif ()
58  # Detect the IntelLLVM compiler for the given language.
59  set(is_lang "$<COMPILE_LANGUAGE:${lang}>")
60  set(is_intelllvm "$<${lang}_COMPILER_ID:IntelLLVM>")
61  set(is_intelllvm_fastmath_assuming_version "$<VERSION_GREATER_EQUAL:$<${lang}_COMPILER_VERSION>,${intel_oneapi_compiler_version_min}>")
62  list(APPEND intel_oneapi_compiler_detections
63  "$<AND:${is_lang},${is_intelllvm},${is_intelllvm_fastmath_assuming_version}>")
64 endforeach ()
65 string(REPLACE ";" "," intel_oneapi_compiler_detections "${intel_oneapi_compiler_detections}")
66 if (TARGET paraviewbuild)
67  target_compile_options(paraviewbuild
68  INTERFACE
69  "$<BUILD_INTERFACE:$<$<OR:${intel_oneapi_compiler_detections}>:-fp-model=precise>>")
70 endif ()
string
language
parameter