add missing header to cmake files (else some IDE's wont index it)
[blender.git] / build_files / cmake / macros.cmake
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # $Id$
3
4
5 # foo_bar.spam --> foo_barMySuffix.spam
6 macro(file_suffix
7         file_name_new file_name file_suffix
8         )
9
10         get_filename_component(_file_name_PATH ${file_name} PATH)
11         get_filename_component(_file_name_NAME_WE ${file_name} NAME_WE)
12         get_filename_component(_file_name_EXT ${file_name} EXT)
13         set(${file_name_new} "${_file_name_PATH}/${_file_name_NAME_WE}${file_suffix}${_file_name_EXT}")
14
15         unset(_file_name_PATH)
16         unset(_file_name_NAME_WE)
17         unset(_file_name_EXT)
18 endmacro()
19
20 # usefil for adding debug suffix to library lists:
21 # /somepath/foo.lib --> /somepath/foo_d.lib
22 macro(file_list_suffix
23         fp_list_new fp_list fn_suffix
24         )
25
26         # incase of empty list
27         set(_fp)
28         set(_fp_suffixed)
29
30         set(fp_list_new)
31
32         foreach(_fp ${fp_list})
33                 file_suffix(_fp_suffixed "${_fp}" "${fn_suffix}")
34                 list(APPEND "${fp_list_new}" "${_fp_suffixed}")
35         endforeach()
36
37         unset(_fp)
38         unset(_fp_suffixed)
39
40 endmacro()
41
42
43 macro(target_link_libraries_optimized TARGET LIBS)
44         foreach(_LIB ${LIBS})
45                 target_link_libraries(${TARGET} optimized "${_LIB}")
46         endforeach()
47         unset(_LIB)
48 endmacro()
49
50 macro(target_link_libraries_debug TARGET LIBS)
51         foreach(_LIB ${LIBS})
52                 target_link_libraries(${TARGET} debug "${_LIB}")
53         endforeach()
54         unset(_LIB)
55 endmacro()
56
57 # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
58 # use it instead of include_directories()
59 macro(blender_include_dirs
60         includes)
61         set(_ALL_INCS "")
62         foreach(_INC ${ARGV})
63                 get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
64                 list(APPEND _ALL_INCS ${_ABS_INC})
65                 # for checking for invalid includes, disable for regular use
66                 ##if(NOT EXISTS "${_ABS_INC}/")
67                 ##      message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
68                 ##endif()
69         endforeach()
70         include_directories(${_ALL_INCS})
71         unset(_INC)
72         unset(_ABS_INC)
73         unset(_ALL_INCS)
74 endmacro()
75
76 macro(blender_include_dirs_sys
77         includes)
78         set(_ALL_INCS "")
79         foreach(_INC ${ARGV})
80                 get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
81                 list(APPEND _ALL_INCS ${_ABS_INC})
82                 ##if(NOT EXISTS "${_ABS_INC}/")
83                 ##      message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
84                 ##endif()
85         endforeach()
86         include_directories(SYSTEM ${_ALL_INCS})
87         unset(_INC)
88         unset(_ABS_INC)
89         unset(_ALL_INCS)
90 endmacro()
91
92 macro(blender_source_group
93         sources)
94
95         # Group by location on disk
96         source_group("Source Files" FILES CMakeLists.txt)
97
98         foreach(_SRC ${sources})
99                 get_filename_component(_SRC_EXT ${_SRC} EXT)
100                 if((${_SRC_EXT} MATCHES ".h") OR (${_SRC_EXT} MATCHES ".hpp"))
101                         source_group("Header Files" FILES ${_SRC})
102                 else()
103                         source_group("Source Files" FILES ${_SRC})
104                 endif()
105         endforeach()
106
107         unset(_SRC)
108         unset(_SRC_EXT)
109 endmacro()
110
111
112 # only MSVC uses SOURCE_GROUP
113 macro(blender_add_lib_nolist
114         name
115         sources
116         includes
117         includes_sys)
118
119         # message(STATUS "Configuring library ${name}")
120
121         # include_directories(${includes})
122         # include_directories(SYSTEM ${includes_sys})
123         blender_include_dirs("${includes}")
124         blender_include_dirs_sys("${includes_sys}")
125
126         add_library(${name} ${sources})
127
128         # works fine without having the includes
129         # listed is helpful for IDE's (QtCreator/MSVC)
130         blender_source_group("${sources}")
131
132 endmacro()
133
134
135 macro(blender_add_lib
136         name
137         sources
138         includes
139         includes_sys)
140
141         blender_add_lib_nolist(${name} "${sources}" "${includes}" "${includes_sys}")
142
143         set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
144 endmacro()
145
146
147 macro(SETUP_LIBDIRS)
148         # see "cmake --help-policy CMP0003"
149         if(COMMAND cmake_policy)
150                 cmake_policy(SET CMP0003 NEW)
151         endif()
152
153         link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
154
155         if(WITH_PYTHON)  #  AND NOT WITH_PYTHON_MODULE  # WIN32 needs
156                 link_directories(${PYTHON_LIBPATH})
157         endif()
158         if(WITH_INTERNATIONAL)
159                 link_directories(${ICONV_LIBPATH})
160                 link_directories(${GETTEXT_LIBPATH})
161         endif()
162         if(WITH_SDL)
163                 link_directories(${SDL_LIBPATH})
164         endif()
165         if(WITH_CODEC_FFMPEG)
166                 link_directories(${FFMPEG_LIBPATH})
167         endif()
168         if(WITH_IMAGE_OPENEXR)
169                 link_directories(${OPENEXR_LIBPATH})
170         endif()
171         if(WITH_IMAGE_TIFF)
172                 link_directories(${TIFF_LIBPATH})
173         endif()
174         if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
175                 link_directories(${OPENJPEG_LIBPATH})
176         endif()
177         if(WITH_CODEC_QUICKTIME)
178                 link_directories(${QUICKTIME_LIBPATH})
179         endif()
180         if(WITH_OPENAL)
181                 link_directories(${OPENAL_LIBPATH})
182         endif()
183         if(WITH_JACK)
184                 link_directories(${JACK_LIBPATH})
185         endif()
186         if(WITH_CODEC_SNDFILE)
187                 link_directories(${SNDFILE_LIBPATH})
188         endif()
189         if(WITH_SAMPLERATE)
190                 link_directories(${SAMPLERATE_LIBPATH})
191         endif()
192         if(WITH_FFTW3)
193                 link_directories(${FFTW3_LIBPATH})
194         endif()
195         if(WITH_OPENCOLLADA)
196                 link_directories(${OPENCOLLADA_LIBPATH})
197                 link_directories(${PCRE_LIBPATH})
198                 link_directories(${EXPAT_LIBPATH})
199         endif()
200         if(WITH_MEM_JEMALLOC)
201                 link_directories(${JEMALLOC_LIBPATH})
202         endif()
203
204         if(WIN32 AND NOT UNIX)
205                 link_directories(${PTHREADS_LIBPATH})
206         endif()
207 endmacro()
208
209 macro(setup_liblinks
210         target)
211
212         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
213         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
214
215         target_link_libraries(${target}
216                         ${OPENGL_gl_LIBRARY}
217                         ${OPENGL_glu_LIBRARY}
218                         ${JPEG_LIBRARIES}
219                         ${PNG_LIBRARIES}
220                         ${ZLIB_LIBRARIES}
221                         ${PLATFORM_LINKLIBS})
222
223         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
224         if(WITH_PYTHON)  # AND NOT WITH_PYTHON_MODULE  # WIN32 needs
225                 target_link_libraries(${target} ${PYTHON_LINKFLAGS})
226
227                 if(WIN32 AND NOT UNIX)
228                         file_list_suffix(PYTHON_LIBRARIES_DEBUG "${PYTHON_LIBRARIES}" "_d")
229                         target_link_libraries_debug(${target} "${PYTHON_LIBRARIES_DEBUG}")
230                         target_link_libraries_optimized(${target} "${PYTHON_LIBRARIES}")
231                         unset(PYTHON_LIBRARIES_DEBUG)
232                 else()
233                         target_link_libraries(${target} ${PYTHON_LIBRARIES})
234                 endif()
235         endif()
236
237         if(NOT WITH_BUILTIN_GLEW)
238                 target_link_libraries(${target} ${GLEW_LIBRARY})
239         endif()
240
241         target_link_libraries(${target}
242                         ${OPENGL_glu_LIBRARY}
243                         ${JPEG_LIBRARIES}
244                         ${PNG_LIBRARIES}
245                         ${ZLIB_LIBRARIES}
246                         ${FREETYPE_LIBRARY})
247
248         if(WITH_INTERNATIONAL)
249                 target_link_libraries(${target} ${GETTEXT_LIB})
250
251                 if(WIN32 AND NOT UNIX)
252                         target_link_libraries(${target} ${ICONV_LIBRARIES})
253                 endif()
254         endif()
255
256         if(WITH_OPENAL)
257                 target_link_libraries(${target} ${OPENAL_LIBRARY})
258         endif()
259         if(WITH_FFTW3)
260                 target_link_libraries(${target} ${FFTW3_LIBRARIES})
261         endif()
262         if(WITH_JACK)
263                 target_link_libraries(${target} ${JACK_LIBRARIES})
264         endif()
265         if(WITH_CODEC_SNDFILE)
266                 target_link_libraries(${target} ${SNDFILE_LIBRARIES})
267         endif()
268         if(WITH_SAMPLERATE)
269                 target_link_libraries(${target} ${SAMPLERATE_LIBRARIES})
270         endif()
271         if(WITH_SDL)
272                 target_link_libraries(${target} ${SDL_LIBRARY})
273         endif()
274         if(WITH_CODEC_QUICKTIME)
275                 target_link_libraries(${target} ${QUICKTIME_LIBRARIES})
276         endif()
277         if(WITH_IMAGE_TIFF)
278                 target_link_libraries(${target} ${TIFF_LIBRARY})
279         endif()
280         if(WITH_IMAGE_OPENEXR)
281                 if(WIN32 AND NOT UNIX)
282                         file_list_suffix(OPENEXR_LIBRARIES_DEBUG "${OPENEXR_LIBRARIES}" "_d")
283                         target_link_libraries_debug(${target} "${OPENEXR_LIBRARIES_DEBUG}")
284                         target_link_libraries_optimized(${target} "${OPENEXR_LIBRARIES}")
285                         unset(OPENEXR_LIBRARIES_DEBUG)
286                 else()
287                         target_link_libraries(${target} ${OPENEXR_LIBRARIES})
288                 endif()
289         endif()
290         if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
291                 target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
292         endif()
293         if(WITH_CODEC_FFMPEG)
294                 target_link_libraries(${target} ${FFMPEG_LIBRARIES})
295         endif()
296         if(WITH_OPENCOLLADA)
297                 if(WIN32 AND NOT UNIX)
298                         file_list_suffix(OPENCOLLADA_LIBRARIES_DEBUG "${OPENCOLLADA_LIBRARIES}" "_d")
299                         target_link_libraries_debug(${target} "${OPENCOLLADA_LIBRARIES_DEBUG}")
300                         target_link_libraries_optimized(${target} "${OPENCOLLADA_LIBRARIES}")
301                         unset(OPENCOLLADA_LIBRARIES_DEBUG)
302
303                         file_list_suffix(PCRE_LIB_DEBUG "${PCRE_LIB}" "_d")
304                         target_link_libraries_debug(${target} "${PCRE_LIB_DEBUG}")
305                         target_link_libraries_optimized(${target} "${PCRE_LIB}")
306                         unset(PCRE_LIB_DEBUG)
307
308                         if(EXPAT_LIB)
309                                 file_list_suffix(EXPAT_LIB_DEBUG "${EXPAT_LIB}" "_d")
310                                 target_link_libraries_debug(${target} "${EXPAT_LIB_DEBUG}")
311                                 target_link_libraries_optimized(${target} "${EXPAT_LIB}")
312                                 unset(EXPAT_LIB_DEBUG)
313                         endif()
314                 else()
315                         target_link_libraries(${target}
316                                         ${OPENCOLLADA_LIBRARIES}
317                                         ${PCRE_LIB}
318                                         ${EXPAT_LIB})
319                 endif()
320         endif()
321         if(WITH_MEM_JEMALLOC)
322                 target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
323         endif()
324         if(WITH_INPUT_NDOF)
325                 target_link_libraries(${target} ${NDOF_LIBRARIES})
326         endif()
327
328         if(WIN32 AND NOT UNIX)
329                 target_link_libraries(${target} ${PTHREADS_LIBRARIES})
330         endif()
331 endmacro()
332
333 macro(TEST_SSE_SUPPORT)
334         include(CheckCSourceRuns)
335
336         # message(STATUS "Detecting SSE support")
337         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
338                 set(CMAKE_REQUIRED_FLAGS "-msse -msse2")
339         elseif(MSVC)
340                 set(CMAKE_REQUIRED_FLAGS "/arch:SSE2") # TODO, SSE 1 ?
341         endif()
342
343         if(NOT DEFINED ${SUPPORT_SSE_BUILD})
344                 check_c_source_runs("
345                         #include <xmmintrin.h>
346                         int main() { __m128 v = _mm_setzero_ps(); return 0; }"
347                 SUPPORT_SSE_BUILD)
348                 
349                 if(SUPPORT_SSE_BUILD)
350                         message(STATUS "SSE Support: detected.")
351                 else()
352                         message(STATUS "SSE Support: missing.")
353                 endif()
354                 set(${SUPPORT_SSE_BUILD} ${SUPPORT_SSE_BUILD} CACHE INTERNAL "SSE Test")
355         endif() 
356
357         if(NOT DEFINED ${SUPPORT_SSE2_BUILD})
358                 check_c_source_runs("
359                         #include <emmintrin.h>
360                         int main() { __m128d v = _mm_setzero_pd(); return 0; }"
361                 SUPPORT_SSE2_BUILD)
362
363                 if(SUPPORT_SSE2_BUILD)
364                         message(STATUS "SSE2 Support: detected.")
365                 else()
366                         message(STATUS "SSE2 Support: missing.")
367                 endif() 
368                 set(${SUPPORT_SSE2_BUILD} ${SUPPORT_SSE2_BUILD} CACHE INTERNAL "SSE2 Test")
369         endif()
370
371 endmacro()
372
373 # when we have warnings as errors applied globally this
374 # needs to be removed for some external libs which we dont maintain.
375
376 # utility macro
377 macro(remove_flag
378         flag)
379
380         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
381         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
382         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
383         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
384         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
385
386         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
387         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
388         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
389         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
390         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
391
392 endmacro()
393
394 macro(remove_strict_flags)
395
396         if(CMAKE_COMPILER_IS_GNUCC)
397                 remove_flag("-Wstrict-prototypes")
398                 remove_flag("-Wunused-parameter")
399                 remove_flag("-Wwrite-strings")
400                 remove_flag("-Wshadow")
401                 remove_flag("-Werror=[^ ]+")
402                 remove_flag("-Werror")
403         endif()
404
405         if(MSVC)
406                 # TODO
407         endif()
408
409 endmacro()
410
411 macro(ADD_CHECK_C_COMPILER_FLAG
412         _CFLAGS
413         _CACHE_VAR
414         _FLAG)
415
416         include(CheckCCompilerFlag)
417
418         CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
419         if(${_CACHE_VAR})
420                 # message(STATUS "Using CFLAG: ${_FLAG}")
421                 set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
422         else()
423                 message(STATUS "Unsupported CFLAG: ${_FLAG}")
424         endif()
425 endmacro()
426
427 macro(ADD_CHECK_CXX_COMPILER_FLAG
428         _CXXFLAGS
429         _CACHE_VAR
430         _FLAG)
431
432         include(CheckCXXCompilerFlag)
433
434         CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
435         if(${_CACHE_VAR})
436                 # message(STATUS "Using CXXFLAG: ${_FLAG}")
437                 set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
438         else()
439                 message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
440         endif()
441 endmacro()
442
443 macro(get_blender_version)
444         # So cmake depends on BKE_blender.h, beware of inf-loops!
445         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
446
447         file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
448
449         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
450         string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
451         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
452         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
453
454         if(NOT ${_out_version} MATCHES "[0-9]+")
455                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
456         endif()
457
458         if(NOT ${_out_subversion} MATCHES "[0-9]+")
459                 message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
460         endif()
461
462         # clumsy regex, only single char are ok but it could be unset
463
464         string(LENGTH "${_out_version_char}" _out_version_char_len)
465         if(NOT _out_version_char_len EQUAL 1)
466                 set(_out_version_char "")
467         elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
468                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
469         endif()
470
471         if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
472                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
473         endif()
474
475         math(EXPR BLENDER_VERSION_MAJOR "${_out_version} / 100")
476         math(EXPR BLENDER_VERSION_MINOR "${_out_version} % 100")
477         set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
478
479         set(BLENDER_SUBVERSION ${_out_subversion})
480         set(BLENDER_VERSION_CHAR ${_out_version_char})
481         set(BLENDER_VERSION_CYCLE ${_out_version_cycle})
482
483         # for packaging, alpha to numbers
484         string(COMPARE EQUAL "${BLENDER_VERSION_CHAR}" "" _out_version_char_empty)
485         if(${_out_version_char_empty})
486                 set(BLENDER_VERSION_CHAR_INDEX "0")
487         else()
488                 set(_char_ls a b c d e f g h i j k l m n o p q r s t u v w q y z)
489                 list(FIND _char_ls ${BLENDER_VERSION_CHAR} _out_version_char_index)
490                 math(EXPR BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index} + 1")
491                 unset(_char_ls)
492                 unset(_out_version_char_index)
493         endif()
494
495         unset(_out_subversion)
496         unset(_out_version_char)
497         unset(_out_version_char_empty)
498         unset(_out_version_cycle)
499
500         # message(STATUS "Version (Internal): ${BLENDER_VERSION}.${BLENDER_SUBVERSION}, Version (external): ${BLENDER_VERSION}${BLENDER_VERSION_CHAR}-${BLENDER_VERSION_CYCLE}")
501 endmacro()
502
503
504 # hacks to override initial project settings
505 # these macros must be called directly before/after project(Blender) 
506 macro(blender_project_hack_pre)
507         # ----------------
508         # MINGW HACK START
509         # ignore system set flag, use our own
510         # must be before project(...)
511         # if the user wants to add their own its ok after first run.
512         if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
513                 set(_reset_standard_libraries OFF)
514         else()
515                 set(_reset_standard_libraries ON)
516         endif()
517
518         # ------------------
519         # GCC -O3 HACK START
520         # needed because O3 can cause problems but
521         # allow the builder to set O3 manually after.
522         if(DEFINED CMAKE_C_FLAGS_RELEASE)
523                 set(_reset_standard_cflags_rel OFF)
524         else()
525                 set(_reset_standard_cflags_rel ON)
526         endif()
527         if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
528                 set(_reset_standard_cxxflags_rel OFF)
529         else()
530                 set(_reset_standard_cxxflags_rel ON)
531         endif()
532 endmacro()
533
534
535 macro(blender_project_hack_post)
536         # --------------
537         # MINGW HACK END
538         if (_reset_standard_libraries)
539                 # Must come after project(...)
540                 #
541                 # MINGW workaround for -ladvapi32 being included which surprisingly causes
542                 # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
543                 # with a meaningless stack trace. by overriding this flag we ensure we only
544                 # have libs we define and that cmake & scons builds match.
545                 set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
546                 set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
547                 mark_as_advanced(CMAKE_C_STANDARD_LIBRARIES)
548                 mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES)
549         endif()
550         unset(_reset_standard_libraries)
551
552
553         # ----------------
554         # GCC -O3 HACK END
555         if(_reset_standard_cflags_rel)
556                 string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
557                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
558                 mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
559         endif()
560
561         if(_reset_standard_cxxflags_rel)
562                 string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
563                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
564                 mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
565         endif()
566
567         unset(_reset_standard_cflags_rel)
568         unset(_reset_standard_cxxflags_rel)
569
570         # ------------------------------------------------------------------
571         # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
572         if(CMAKE_COMPILER_IS_GNUCC)
573                 if(NOT DARWIN)
574                         set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
575                 endif()
576         endif()
577
578 endmacro()