@@ -7,7 +7,7 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
77 set (COMPILER_IS_CLANG ON )
88 endif ()
99
10- set (CMAKE_CXX_FLAGS_DEBUG "-g3 -gstrict-dwarf -O0" )
10+ set (CMAKE_CXX_FLAGS_DEBUG "-g3 -gstrict-dwarf -O0" )
1111
1212 if (CMAKE_GENERATOR MATCHES "Xcode" )
1313 set (CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0" )
@@ -20,17 +20,39 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
2020 endif ()
2121 endif ()
2222
23+
2324 if (COMPILER_IS_GCC OR COMPILER_IS_CLANG)
2425
26+ # This fails under Fedora - MinGW - Gcc 8.3
27+ if (NOT MINGW)
28+ if (COMPILER_IS_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
29+ add_compile_options (-fstack-clash-protection -fcf-protection)
30+ endif ()
31+
32+ if (COMPILER_IS_GCC OR (COMPILER_IS_CLANG AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.7 ))
33+ # is not available for clang 3.4.2. it appears to be present in clang 3.7.
34+ add_compile_options (-fstack-protector-strong)
35+ endif ()
36+ endif ()
37+
38+ add_compile_options (-Wp,-D_GLIBCXX_ASSERTIONS)
39+
40+ if (CMAKE_BUILD_TYPE STREQUAL Release AND NOT APPLE )
41+ add_compile_options (-Wp,-D_FORTIFY_SOURCE=2) # Requires to compile with -O2
42+ endif ()
43+
2544 if (BUILD_WITH_COVERAGE)
26- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g " )
27- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0" )
28- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs" )
29- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftest-coverage" )
45+ add_compile_options (--coverage)
46+ # TODO: From CMake 3.13 we could use add_link_options instead these 2 lines
3047 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" )
48+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" )
3149 endif ()
3250
33- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W" )
51+ add_compile_options (-Wall -Wcast-align -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Woverloaded-virtual -W)
52+
53+ # This seems to be causing issues in the Fedora_MinGW GitLab job
54+ #add_compile_options(-fasynchronous-unwind-tables)
55+
3456
3557 if ( EXIV2_TEAM_USE_SANITIZERS )
3658 # ASAN is available in gcc from 4.8 and UBSAN from 4.9
@@ -61,82 +83,8 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
6183 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} " )
6284 set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS} " )
6385 endif ()
64-
6586 endif ()
66-
67- if ( EXIV2_TEAM_EXTRA_WARNINGS )
68- # Note that this is intended to be used only by Exiv2 developers/contributors.
69-
70- if ( COMPILER_IS_GCC )
71- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0 )
72- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
73- " -Wextra"
74- " -Wlogical-op"
75- " -Wdouble-promotion"
76- " -Wshadow"
77- " -Wuseless-cast"
78- " -Wpointer-arith" # This warning is also enabled by -Wpedantic
79- " -Wformat=2"
80- #" -Wold-style-cast"
81- )
82- endif ()
83-
84- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 )
85- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
86- " -Warray-bounds=2"
87- )
88- endif ()
89-
90- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 )
91- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
92- " -Wduplicated-cond"
93- )
94- endif ()
95-
96- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 )
97- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
98- " -Wduplicated-branches"
99- " -Wrestrict"
100- )
101- endif ()
102- endif ()
103-
104- if ( COMPILER_IS_CLANG )
105- # https://clang.llvm.org/docs/DiagnosticsReference.html
106- # These variables are at least available since clang 3.9.1
107- string (CONCAT EXTRA_COMPILE_FLAGS "-Wextra"
108- " -Wshadow"
109- " -Wassign-enum"
110- " -Wmicrosoft"
111- " -Wcomments"
112- " -Wconditional-uninitialized"
113- " -Wdirect-ivar-access"
114- " -Weffc++"
115- " -Wpointer-arith"
116- " -Wformat=2"
117- #" -Warray-bounds" # Enabled by default
118- # These two raises lot of warnings. Use them wisely
119- #" -Wconversion"
120- #" -Wold-style-cast"
121- )
122- # -Wdouble-promotion flag is not available in clang 3.4.2
123- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4.2 )
124- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
125- " -Wdouble-promotion"
126- )
127- endif ()
128- # -Wcomma flag is not available in clang 3.8.1
129- if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.1 )
130- string (CONCAT EXTRA_COMPILE_FLAGS ${EXTRA_COMPILE_FLAGS}
131- " -Wcomma"
132- )
133- endif ()
134- endif ()
135-
136-
137- endif ()
13887 endif ()
139-
14088endif ()
14189
14290# http://stackoverflow.com/questions/10113017/setting-the-msvc-runtime-in-cmake
@@ -185,8 +133,6 @@ if(MSVC)
185133 endif ()
186134
187135 # Object Level Parallelism
188- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" )
189-
136+ add_compile_options (/MP)
190137 add_definitions (-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
191-
192138endif ()
0 commit comments