Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/cmake/CompilerChecks.cmake

raw
1 # Compiler feature checks
2 #
3 # Copyright © 2015 Open Microscopy Environment / University of Dundee
4 # Copyright © 2021 Roger Leigh <[email protected]>
5 # Written by Roger Leigh <[email protected]>
6 #
7 # Permission to use, copy, modify, distribute, and sell this software and
8 # its documentation for any purpose is hereby granted without fee, provided
9 # that (i) the above copyright notices and this permission notice appear in
10 # all copies of the software and related documentation, and (ii) the names of
11 # Sam Leffler and Silicon Graphics may not be used in any advertising or
12 # publicity relating to the software without the specific, prior written
13 # permission of Sam Leffler and Silicon Graphics.
14 #
15 # THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 # WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
18 #
19 # IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 # ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 # OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 # WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 # LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 # OF THIS SOFTWARE.
25
26
27 include(CheckCCompilerFlag)
28
29
30 # These are annoyingly verbose, produce false positives or don't work
31 # nicely with all supported compiler versions, so are disabled unless
32 # explicitly enabled.
33 option(extra-warnings "Enable extra compiler warnings" OFF)
34
35 # This will cause the compiler to fail when an error occurs.
36 option(fatal-warnings "Compiler warnings are errors" OFF)
37
38 # Check if the compiler supports each of the following additional
39 # flags, and enable them if supported. This greatly improves the
40 # quality of the build by checking for a number of common problems,
41 # some of which are quite serious.
42 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
43 CMAKE_C_COMPILER_ID MATCHES "Clang")
44 set(test_flags
45 -Wall
46 -Winline
47 -Wformat-security
48 -Wpointer-arith
49 -Wdisabled-optimization
50 -Wno-unknown-pragmas
51 -fstrict-aliasing)
52 if(extra-warnings)
53 list(APPEND test_flags
54 -pedantic
55 -Wextra
56 -Wformat
57 -Wformat-overflow
58 -Wformat-nonliteral
59 -Wformat-signedness
60 -Wformat-truncation
61 -Wdeclaration-after-statement
62 -Wconversion
63 -Wsign-conversion
64 -Wnull-dereference
65 -Wdouble-promotion
66 -Wmisleading-indentation
67 -Wmissing-include-dirs
68 -Wswitch-default
69 -Wswitch-enum
70 -Wunused-local-typedefs
71 -Wunused-parameter
72 -Wuninitialized
73 -Warith-conversion
74 -Wbool-operation
75 -Wduplicated-branches
76 -Wduplicated-cond
77 -Wshadow
78 -Wunused-macros
79 -Wc99-c11-compat
80 -Wcast-qual
81 -Wcast-align
82 -Wwrite-strings
83 -Wdangling-else
84 -Wsizeof-array-div
85 -Wsizeof-pointer-div
86 -Wsizeof-pointer-memaccess
87 -Wlogical-op
88 -Wlogical-not-parentheses
89 -Wstrict-prototypes
90 -Wmissing-declarations
91 -Wredundant-decls
92 -Wno-int-to-pointer-cast
93 -Wfloat-equal
94 -Wfloat-conversion
95 -Wmissing-prototypes
96 -Wunreachable-code)
97 endif()
98 if(fatal-warnings)
99 list(APPEND test_flags
100 -Werror)
101 endif()
102 elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
103 set(test_flags)
104 if(extra-warnings)
105 list(APPEND test_flags
106 /W4)
107 else()
108 list(APPEND test_flags
109 /W3)
110 endif()
111 if (fatal-warnings)
112 list(APPEND test_flags
113 /WX)
114 endif()
115 endif()
116
117 foreach(flag ${test_flags})
118 string(REGEX REPLACE "[^A-Za-z0-9]" "_" flag_var "${flag}")
119 set(test_c_flag "C_FLAG${flag_var}")
120 CHECK_C_COMPILER_FLAG(${flag} "${test_c_flag}")
121 if (${test_c_flag})
122 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
123 endif (${test_c_flag})
124 endforeach(flag ${test_flags})