changed: gcc8 base update
[opensg.git] / CMake / OSGUpdateCompiler.cmake
blobaab0b56020a0af28d9ecc64ad9d053a8e3bf8333
2 MESSAGE(STATUS "Update Compiler Settings")
4 IF(CMAKE_COMPILER_IS_GNUCC)
6     IF(LINUX OR APPLE)
8         IF(NOT APPLE)
9           SET(OSG_GCC_FPMATHOPT "-mfpmath=sse")
10         ELSE()
11           SET(OSG_GCC_FPMATHOPT "")
12         ENDIF(NOT APPLE)
14         IF(OSG_ENABLE_SSE2 AND NOT OSG_ENABLE_SSE4)
16             MESSAGE(STATUS "Apply sse2 settings")
18             IF(CMAKE_CXX_FLAGS)
19                 STRING(REGEX MATCH "-msse2 ${OSG_GCC_FPMATHOPT}" 
20                              SSE2_CXX_RES ${CMAKE_CXX_FLAGS})
21             ENDIF(CMAKE_CXX_FLAGS)
23             IF(CMAKE_C_FLAGS)
24                 STRING(REGEX MATCH "-msse2 ${OSG_GCC_FPMATHOPT}" 
25                              SSE2_C_RES ${CMAKE_C_FLAGS})
26             ENDIF(CMAKE_C_FLAGS)
28             IF(NOT SSE2_CXX_RES)
29                 SET(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 ${OSG_GCC_FPMATHOPT}")
32                 SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
33                                     CACHE STRING "OpenSG defaults" FORCE )
34             ENDIF(NOT SSE2_CXX_RES)
36             IF(NOT SSE2_C_RES)
37                 SET(TMP_C_FLAGS "${CMAKE_C_FLAGS} -msse2 ${OSG_GCC_FPMATHOPT}")
40                 SET(CMAKE_C_FLAGS ${TMP_C_FLAGS} 
41                                   CACHE STRING "OpenSG defaults" FORCE )
42             ENDIF(NOT SSE2_C_RES)
43             
45         ELSE(OSG_ENABLE_SSE2 AND NOT OSG_ENABLE_SSE4)
47             MESSAGE(STATUS "Remove sse2 settings")
49             IF(CMAKE_CXX_FLAGS)
50                 STRING(REPLACE " -msse2 ${OSG_GCC_FPMATHOPT}" "" 
51                        TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS})
52             ENDIF(CMAKE_CXX_FLAGS)
54             IF(CMAKE_C_FLAGS)
55                 STRING(REPLACE " -msse2 ${OSG_GCC_FPMATHOPT}" "" 
56                        TMP_C_FLAGS ${CMAKE_C_FLAGS})
57             ENDIF(CMAKE_C_FLAGS)
59             SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
60                                 CACHE STRING "OpenSG defaults" FORCE )
61             SET(CMAKE_C_FLAGS   ${TMP_C_FLAGS} 
62                                 CACHE STRING "OpenSG defaults" FORCE )
63            
64         ENDIF(OSG_ENABLE_SSE2 AND NOT OSG_ENABLE_SSE4)
66         IF(OSG_ENABLE_SSE4)
68             MESSAGE(STATUS "Apply sse4 settings")
70             IF(NOT OSG_SSE4_VARIANT)
71               SET(OSG_SSE4_VARIANT "4.1" CACHE STRING "")
72             ENDIF()
74             IF(CMAKE_CXX_FLAGS)
75                 STRING(REGEX MATCH 
76                          "-msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}" 
77                          SSE4_CXX_RES ${CMAKE_CXX_FLAGS}               )
78             ENDIF(CMAKE_CXX_FLAGS)
80             IF(CMAKE_C_FLAGS)
81                 STRING(REGEX MATCH 
82                          "-msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}" 
83                          SSE4_C_RES ${CMAKE_C_FLAGS}                   )
84             ENDIF(CMAKE_C_FLAGS)
86             IF(NOT SSE4_CXX_RES)
87                 SET(TMP_CXX_FLAGS 
88                       "${CMAKE_CXX_FLAGS} -msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}")
91                 SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
92                                     CACHE STRING "OpenSG defaults" FORCE )
93             ENDIF(NOT SSE4_CXX_RES)
95             IF(NOT SSE4_C_RES)
96                 SET(TMP_C_FLAGS 
97                       "${CMAKE_C_FLAGS} -msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}")
100                 SET(CMAKE_C_FLAGS ${TMP_C_FLAGS} 
101                                   CACHE STRING "OpenSG defaults" FORCE )
102             ENDIF(NOT SSE4_C_RES)
103             
105         ELSE(OSG_ENABLE_SSE4)
107             MESSAGE(STATUS "Remove sse4 settings")
109             IF(CMAKE_CXX_FLAGS)
110                 STRING(REPLACE 
111                          "-msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}" "" 
112                          TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS}                 )
113             ENDIF(CMAKE_CXX_FLAGS)
115             IF(CMAKE_C_FLAGS)
116                 STRING(REPLACE 
117                          "-msse${OSG_SSE4_VARIANT} ${OSG_GCC_FPMATHOPT}" "" 
118                          TMP_C_FLAGS ${CMAKE_C_FLAGS}                     )
119             ENDIF(CMAKE_C_FLAGS)
121             SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
122                                 CACHE STRING "OpenSG defaults" FORCE )
123             SET(CMAKE_C_FLAGS   ${TMP_C_FLAGS} 
124                                 CACHE STRING "OpenSG defaults" FORCE )
125            
126         ENDIF(OSG_ENABLE_SSE4)
128         IF(OSG_ENABLE_AVX)
130             MESSAGE(STATUS "Apply avx settings")
132             IF(NOT OSG_AVX_VARIANT)
133               SET(OSG_AVX_VARIANT "" CACHE STRING "")
134             ENDIF()
136             IF(CMAKE_CXX_FLAGS)
137                 STRING(REGEX MATCH "-mavx${OSG_AVX_VARIANT}" 
138                                    AVX_CXX_RES ${CMAKE_CXX_FLAGS})
139             ENDIF(CMAKE_CXX_FLAGS)
141             IF(CMAKE_C_FLAGS)
142                 STRING(REGEX MATCH "-mavx${OSG_AVX_VARIANT}" 
143                                    AVX_C_RES ${CMAKE_C_FLAGS}    )
144             ENDIF(CMAKE_C_FLAGS)
146             IF(NOT AVX_CXX_RES)
147                 SET(TMP_CXX_FLAGS 
148                       "${CMAKE_CXX_FLAGS} -mavx${OSG_AVX_VARIANT}")
151                 SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
152                                     CACHE STRING "OpenSG defaults" FORCE )
153             ENDIF(NOT AVX_CXX_RES)
155             IF(NOT AVX_C_RES)
156                 SET(TMP_C_FLAGS 
157                     "${CMAKE_C_FLAGS} -mavx${OSG_AVX_VARIANT}")
160                 SET(CMAKE_C_FLAGS ${TMP_C_FLAGS} 
161                                   CACHE STRING "OpenSG defaults" FORCE )
162             ENDIF(NOT AVX_C_RES)
163             
165         ELSE(OSG_ENABLE_AVX)
167             MESSAGE(STATUS "Remove avx settings")
169             IF(CMAKE_CXX_FLAGS)
170                 STRING(REPLACE " -mavx${OSG_AVX_VARIANT}" "" 
171                        TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS})
172             ENDIF(CMAKE_CXX_FLAGS)
174             IF(CMAKE_C_FLAGS)
175                 STRING(REPLACE " -mavx${OSG_AVX_VARIANT}" "" 
176                        TMP_C_FLAGS ${CMAKE_C_FLAGS})
177             ENDIF(CMAKE_C_FLAGS)
179             SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
180                                 CACHE STRING "OpenSG defaults" FORCE )
181             SET(CMAKE_C_FLAGS   ${TMP_C_FLAGS} 
182                                 CACHE STRING "OpenSG defaults" FORCE )
183            
184         ENDIF(OSG_ENABLE_AVX)
186         IF(OSG_ENABLE_FMA)
188             MESSAGE(STATUS "Apply fma settings")
190             IF(CMAKE_CXX_FLAGS)
191                 STRING(REGEX MATCH "-mfma" 
192                                    FMA_CXX_RES ${CMAKE_CXX_FLAGS})
193             ENDIF(CMAKE_CXX_FLAGS)
195             IF(CMAKE_C_FLAGS)
196                 STRING(REGEX MATCH "-mfma" 
197                                    FMA_C_RES ${CMAKE_C_FLAGS}    )
198             ENDIF(CMAKE_C_FLAGS)
200             IF(NOT FMA_CXX_RES)
201                 SET(TMP_CXX_FLAGS 
202                       "${CMAKE_CXX_FLAGS} -mfma")
205                 SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
206                                     CACHE STRING "OpenSG defaults" FORCE )
207             ENDIF(NOT FMA_CXX_RES)
209             IF(NOT FMA_C_RES)
210                 SET(TMP_C_FLAGS 
211                     "${CMAKE_C_FLAGS} -mfma")
214                 SET(CMAKE_C_FLAGS ${TMP_C_FLAGS} 
215                                   CACHE STRING "OpenSG defaults" FORCE )
216             ENDIF(NOT FMA_C_RES)
217             
219         ELSE(OSG_ENABLE_FMA)
221             MESSAGE(STATUS "Remove fma settings")
223             IF(CMAKE_CXX_FLAGS)
224                 STRING(REPLACE " -mfma" "" 
225                        TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS})
226             ENDIF(CMAKE_CXX_FLAGS)
228             IF(CMAKE_C_FLAGS)
229                 STRING(REPLACE " -mfma" "" 
230                        TMP_C_FLAGS ${CMAKE_C_FLAGS})
231             ENDIF(CMAKE_C_FLAGS)
233             SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
234                                 CACHE STRING "OpenSG defaults" FORCE )
235             SET(CMAKE_C_FLAGS   ${TMP_C_FLAGS} 
236                                 CACHE STRING "OpenSG defaults" FORCE )
237            
238         ENDIF(OSG_ENABLE_FMA)
240         IF(OSG_ENABLE_ABI6)
242             MESSAGE(STATUS "Apply abi6 settings")
244             IF(CMAKE_CXX_FLAGS)
245                 STRING(REGEX MATCH "-fabi-version=6" 
246                                    ABI6_CXX_RES ${CMAKE_CXX_FLAGS})
247             ENDIF(CMAKE_CXX_FLAGS)
249             IF(CMAKE_C_FLAGS)
250                 STRING(REGEX MATCH "-fabi-version=6" 
251                                    ABI6_C_RES ${CMAKE_C_FLAGS})
252             ENDIF(CMAKE_C_FLAGS)
254             IF(NOT ABI6_CXX_RES)
255                 SET(TMP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fabi-version=6")
258                 SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
259                                     CACHE STRING "OpenSG defaults" FORCE )
260             ENDIF(NOT ABI6_CXX_RES)
262             IF(NOT ABI6_C_RES)
263                 SET(TMP_C_FLAGS "${CMAKE_C_FLAGS} -fabi-version=6")
266                 SET(CMAKE_C_FLAGS ${TMP_C_FLAGS} 
267                                   CACHE STRING "OpenSG defaults" FORCE )
268             ENDIF(NOT ABI6_C_RES)
269             
271         ELSE(OSG_ENABLE_ABI6)
273             MESSAGE(STATUS "Remove abi6 settings")
275             IF(CMAKE_CXX_FLAGS)
276                 STRING(REPLACE " -fabi-version=6" "" 
277                        TMP_CXX_FLAGS ${CMAKE_CXX_FLAGS})
278             ENDIF(CMAKE_CXX_FLAGS)
280             IF(CMAKE_C_FLAGS)
281                 STRING(REPLACE " -fabi-version=6" "" 
282                        TMP_C_FLAGS ${CMAKE_C_FLAGS})
283             ENDIF(CMAKE_C_FLAGS)
285             SET(CMAKE_CXX_FLAGS ${TMP_CXX_FLAGS} 
286                                 CACHE STRING "OpenSG defaults" FORCE )
287             SET(CMAKE_C_FLAGS   ${TMP_C_FLAGS} 
288                                 CACHE STRING "OpenSG defaults" FORCE )
289            
290         ENDIF(OSG_ENABLE_ABI6)
292     ENDIF(LINUX OR APPLE)
294     IF(CMAKE_CXX_FLAGS)
295        STRING(REGEX MATCH "__STDC_FORMAT_MACROS" 
296        STDFORMAT_CXX_RES ${CMAKE_CXX_FLAGS})
297     ENDIF(CMAKE_CXX_FLAGS)
299     IF(CMAKE_C_FLAGS)
300         STRING(REGEX MATCH "__STDC_FORMAT_MACROS" 
301                STDFORMAT_C_RES ${CMAKE_C_FLAGS})
302     ENDIF(CMAKE_C_FLAGS)
304     IF(NOT STDFORMAT_CXX_RES)
305       SET(CMAKE_CXX_FLAGS   "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS"
306           CACHE STRING "OpenSG defaults" FORCE )
307     ENDIF(NOT STDFORMAT_CXX_RES)
309     IF(NOT STDFORMAT_C_RES)
310       SET(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -D__STDC_FORMAT_MACROS"
311           CACHE STRING "OpenSG defaults" FORCE )
312     ENDIF(NOT STDFORMAT_C_RES)
314     ###########
315     # GV stuff
316     ###########
318     IF(CMAKE_BUILD_TYPE STREQUAL "DebugGV" OR CMAKE_BUILD_TYPE STREQUAL "ReleaseGV")
319       SET(OSG_ADD_CXX_FLAGS " -Wall -Wextra -Wno-unused-parameter")
320       SET(OSG_ADD_C_FLAGS " -Wall -Wextra -Wno-unused-parameter")
322       IF(CMAKE_BUILD_TYPE STREQUAL "ReleaseGV")
323       SET(OSG_ADD_CXX_FLAGS " ${OSG_ADD_CXX_FLAGS} -Wno-strict-aliasing")
324       ENDIF(CMAKE_BUILD_TYPE STREQUAL "ReleaseGV")
325     ELSE()
326       SET(OSG_ADD_CXX_FLAGS )
327       SET(OSG_ADD_C_FLAGS )
328     ENDIF()
330 ENDIF(CMAKE_COMPILER_IS_GNUCC)
332 IF(MSVC)
333   IF(OSG_DISABLE_MICROSOFT_SECURE_CXXX)
334     ADD_DEFINITIONS("-D_CRT_SECURE_NO_DEPRECATE")
335     ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
336     ADD_DEFINITIONS("-D_CRT_NONSTDC_NO_DEPRECATE")
337     ADD_DEFINITIONS("-D_SECURE_SCL=0")
338     ADD_DEFINITIONS("-D_SCL_SECURE_NO_WARNINGS")
339     ADD_DEFINITIONS("-D_SCL_SECURE_NO_DEPRECATE")
340   ELSE()
341     IF(OSG_DISABLE_MICROSOFT_SECURE_CXXX_DEBUG)
342     ENDIF()
343     IF(OSG_DISABLE_MICROSOFT_SECURE_CXXX_RELEASE)
344     ENDIF()
345   ENDIF()
347   IF(OSG_DISABLE_MS_ITERATOR_DEBUGGING)
348     ADD_DEFINITIONS("-D_HAS_ITERATOR_DEBUGGING=0")
349   ENDIF(OSG_DISABLE_MS_ITERATOR_DEBUGGING)
350 ENDIF(MSVC)