cmake: sse flags were being defined in 2 different places
[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         link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
149
150         if(WITH_PYTHON)  #  AND NOT WITH_PYTHON_MODULE  # WIN32 needs
151                 link_directories(${PYTHON_LIBPATH})
152         endif()
153         if(WITH_INTERNATIONAL)
154                 link_directories(${ICONV_LIBPATH})
155                 link_directories(${GETTEXT_LIBPATH})
156         endif()
157         if(WITH_SDL)
158                 link_directories(${SDL_LIBPATH})
159         endif()
160         if(WITH_CODEC_FFMPEG)
161                 link_directories(${FFMPEG_LIBPATH})
162         endif()
163         if(WITH_IMAGE_OPENEXR)
164                 link_directories(${OPENEXR_LIBPATH})
165         endif()
166         if(WITH_IMAGE_TIFF)
167                 link_directories(${TIFF_LIBPATH})
168         endif()
169         if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
170                 link_directories(${OPENJPEG_LIBPATH})
171         endif()
172         if(WITH_CODEC_QUICKTIME)
173                 link_directories(${QUICKTIME_LIBPATH})
174         endif()
175         if(WITH_OPENAL)
176                 link_directories(${OPENAL_LIBPATH})
177         endif()
178         if(WITH_JACK)
179                 link_directories(${JACK_LIBPATH})
180         endif()
181         if(WITH_CODEC_SNDFILE)
182                 link_directories(${SNDFILE_LIBPATH})
183         endif()
184         if(WITH_SAMPLERATE)
185                 link_directories(${SAMPLERATE_LIBPATH})
186         endif()
187         if(WITH_FFTW3)
188                 link_directories(${FFTW3_LIBPATH})
189         endif()
190         if(WITH_OPENCOLLADA)
191                 link_directories(${OPENCOLLADA_LIBPATH})
192                 link_directories(${PCRE_LIBPATH})
193                 link_directories(${EXPAT_LIBPATH})
194         endif()
195         if(WITH_MEM_JEMALLOC)
196                 link_directories(${JEMALLOC_LIBPATH})
197         endif()
198
199         if(WIN32 AND NOT UNIX)
200                 link_directories(${PTHREADS_LIBPATH})
201         endif()
202 endmacro()
203
204 macro(setup_liblinks
205         target)
206
207         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}")
208         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}")
209
210         target_link_libraries(${target}
211                         ${OPENGL_gl_LIBRARY}
212                         ${OPENGL_glu_LIBRARY}
213                         ${JPEG_LIBRARIES}
214                         ${PNG_LIBRARIES}
215                         ${ZLIB_LIBRARIES}
216                         ${FREETYPE_LIBRARY}
217                         ${PLATFORM_LINKLIBS})
218
219         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
220         if(WITH_PYTHON)  # AND NOT WITH_PYTHON_MODULE  # WIN32 needs
221                 target_link_libraries(${target} ${PYTHON_LINKFLAGS})
222
223                 if(WIN32 AND NOT UNIX)
224                         file_list_suffix(PYTHON_LIBRARIES_DEBUG "${PYTHON_LIBRARIES}" "_d")
225                         target_link_libraries_debug(${target} "${PYTHON_LIBRARIES_DEBUG}")
226                         target_link_libraries_optimized(${target} "${PYTHON_LIBRARIES}")
227                         unset(PYTHON_LIBRARIES_DEBUG)
228                 else()
229                         target_link_libraries(${target} ${PYTHON_LIBRARIES})
230                 endif()
231         endif()
232
233         if(NOT WITH_BUILTIN_GLEW)
234                 target_link_libraries(${target} ${GLEW_LIBRARY})
235         endif()
236
237         if(WITH_INTERNATIONAL)
238                 target_link_libraries(${target} ${GETTEXT_LIB})
239
240                 if(WIN32 AND NOT UNIX)
241                         target_link_libraries(${target} ${ICONV_LIBRARIES})
242                 endif()
243         endif()
244
245         if(WITH_OPENAL)
246                 target_link_libraries(${target} ${OPENAL_LIBRARY})
247         endif()
248         if(WITH_FFTW3)
249                 target_link_libraries(${target} ${FFTW3_LIBRARIES})
250         endif()
251         if(WITH_JACK)
252                 target_link_libraries(${target} ${JACK_LIBRARIES})
253         endif()
254         if(WITH_CODEC_SNDFILE)
255                 target_link_libraries(${target} ${SNDFILE_LIBRARIES})
256         endif()
257         if(WITH_SAMPLERATE)
258                 target_link_libraries(${target} ${SAMPLERATE_LIBRARIES})
259         endif()
260         if(WITH_SDL)
261                 target_link_libraries(${target} ${SDL_LIBRARY})
262         endif()
263         if(WITH_CODEC_QUICKTIME)
264                 target_link_libraries(${target} ${QUICKTIME_LIBRARIES})
265         endif()
266         if(WITH_IMAGE_TIFF)
267                 target_link_libraries(${target} ${TIFF_LIBRARY})
268         endif()
269         if(WITH_IMAGE_OPENEXR)
270                 if(WIN32 AND NOT UNIX)
271                         file_list_suffix(OPENEXR_LIBRARIES_DEBUG "${OPENEXR_LIBRARIES}" "_d")
272                         target_link_libraries_debug(${target} "${OPENEXR_LIBRARIES_DEBUG}")
273                         target_link_libraries_optimized(${target} "${OPENEXR_LIBRARIES}")
274                         unset(OPENEXR_LIBRARIES_DEBUG)
275                 else()
276                         target_link_libraries(${target} ${OPENEXR_LIBRARIES})
277                 endif()
278         endif()
279         if(WITH_IMAGE_OPENJPEG AND UNIX AND NOT APPLE)
280                 target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
281         endif()
282         if(WITH_CODEC_FFMPEG)
283
284                 # Strange!, without this ffmpeg gives linking errors (on linux)
285                 # even though its linked above
286                 target_link_libraries(${target} ${OPENGL_glu_LIBRARY})
287
288                 target_link_libraries(${target} ${FFMPEG_LIBRARIES})
289         endif()
290         if(WITH_OPENCOLLADA)
291                 if(WIN32 AND NOT UNIX)
292                         file_list_suffix(OPENCOLLADA_LIBRARIES_DEBUG "${OPENCOLLADA_LIBRARIES}" "_d")
293                         target_link_libraries_debug(${target} "${OPENCOLLADA_LIBRARIES_DEBUG}")
294                         target_link_libraries_optimized(${target} "${OPENCOLLADA_LIBRARIES}")
295                         unset(OPENCOLLADA_LIBRARIES_DEBUG)
296
297                         file_list_suffix(PCRE_LIBRARIES_DEBUG "${PCRE_LIBRARIES}" "_d")
298                         target_link_libraries_debug(${target} "${PCRE_LIBRARIES_DEBUG}")
299                         target_link_libraries_optimized(${target} "${PCRE_LIBRARIES}")
300                         unset(PCRE_LIBRARIES_DEBUG)
301
302                         if(EXPAT_LIB)
303                                 file_list_suffix(EXPAT_LIB_DEBUG "${EXPAT_LIB}" "_d")
304                                 target_link_libraries_debug(${target} "${EXPAT_LIB_DEBUG}")
305                                 target_link_libraries_optimized(${target} "${EXPAT_LIB}")
306                                 unset(EXPAT_LIB_DEBUG)
307                         endif()
308                 else()
309                         target_link_libraries(${target}
310                                         ${OPENCOLLADA_LIBRARIES}
311                                         ${PCRE_LIBRARIES}
312                                         ${XML2_LIBRARIES}
313                                         ${EXPAT_LIB})
314                 endif()
315         endif()
316         if(WITH_MEM_JEMALLOC)
317                 target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
318         endif()
319         if(WITH_INPUT_NDOF)
320                 target_link_libraries(${target} ${NDOF_LIBRARIES})
321         endif()
322
323         if(WIN32 AND NOT UNIX)
324                 target_link_libraries(${target} ${PTHREADS_LIBRARIES})
325         endif()
326 endmacro()
327
328 macro(TEST_SSE_SUPPORT
329         _sse_flags
330         _sse2_flags)
331
332         include(CheckCSourceRuns)
333
334         # message(STATUS "Detecting SSE support")
335         if(CMAKE_COMPILER_IS_GNUCC)
336                 set(${_sse_flags} "-msse")
337                 set(${_sse2_flags} "-msse2")
338         elseif(MSVC)
339                 set(${_sse_flags} "/arch:SSE")
340                 set(${_sse2_flags} "/arch:SSE2")
341         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
342                 set(${_sse_flags})  # icc only has sse2
343                 set(${_sse2_flags} "-xSSE2")            
344         else()
345                 message(WARNING "SSE flags for this compiler: '${CMAKE_C_COMPILER_ID}' not known")
346                 set(_sse_flags)
347                 set(_sse2_flags)
348         endif()
349
350         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
351                 set(CMAKE_REQUIRED_FLAGS ${_sse_flags} ${_sse2_flags})
352         endif()
353
354         if(NOT DEFINED ${SUPPORT_SSE_BUILD})
355                 check_c_source_runs("
356                         #include <xmmintrin.h>
357                         int main() { __m128 v = _mm_setzero_ps(); return 0; }"
358                 SUPPORT_SSE_BUILD)
359
360                 if(SUPPORT_SSE_BUILD)
361                         message(STATUS "SSE Support: detected.")
362                 else()
363                         message(STATUS "SSE Support: missing.")
364                 endif()
365                 set(${SUPPORT_SSE_BUILD} ${SUPPORT_SSE_BUILD} CACHE INTERNAL "SSE Test")
366         endif()
367
368         if(NOT DEFINED ${SUPPORT_SSE2_BUILD})
369                 check_c_source_runs("
370                         #include <emmintrin.h>
371                         int main() { __m128d v = _mm_setzero_pd(); return 0; }"
372                 SUPPORT_SSE2_BUILD)
373
374                 if(SUPPORT_SSE2_BUILD)
375                         message(STATUS "SSE2 Support: detected.")
376                 else()
377                         message(STATUS "SSE2 Support: missing.")
378                 endif()
379                 set(${SUPPORT_SSE2_BUILD} ${SUPPORT_SSE2_BUILD} CACHE INTERNAL "SSE2 Test")
380         endif()
381
382 endmacro()
383
384 # when we have warnings as errors applied globally this
385 # needs to be removed for some external libs which we dont maintain.
386
387 # utility macro
388 macro(remove_flag
389         flag)
390
391         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
392         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
393         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
394         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
395         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
396
397         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
398         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
399         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
400         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
401         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
402
403 endmacro()
404
405 macro(remove_strict_flags)
406
407         if(CMAKE_COMPILER_IS_GNUCC)
408                 remove_flag("-Wstrict-prototypes")
409                 remove_flag("-Wunused-parameter")
410                 remove_flag("-Wwrite-strings")
411                 remove_flag("-Wundef")
412                 remove_flag("-Wshadow")
413                 remove_flag("-Werror=[^ ]+")
414                 remove_flag("-Werror")
415         endif()
416
417         if(MSVC)
418                 # TODO
419         endif()
420
421 endmacro()
422
423 macro(ADD_CHECK_C_COMPILER_FLAG
424         _CFLAGS
425         _CACHE_VAR
426         _FLAG)
427
428         include(CheckCCompilerFlag)
429
430         CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
431         if(${_CACHE_VAR})
432                 # message(STATUS "Using CFLAG: ${_FLAG}")
433                 set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
434         else()
435                 message(STATUS "Unsupported CFLAG: ${_FLAG}")
436         endif()
437 endmacro()
438
439 macro(ADD_CHECK_CXX_COMPILER_FLAG
440         _CXXFLAGS
441         _CACHE_VAR
442         _FLAG)
443
444         include(CheckCXXCompilerFlag)
445
446         CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
447         if(${_CACHE_VAR})
448                 # message(STATUS "Using CXXFLAG: ${_FLAG}")
449                 set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
450         else()
451                 message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
452         endif()
453 endmacro()
454
455 macro(get_blender_version)
456         # So cmake depends on BKE_blender.h, beware of inf-loops!
457         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
458
459         file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
460
461         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
462         string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
463         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
464         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
465
466         if(NOT ${_out_version} MATCHES "[0-9]+")
467                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
468         endif()
469
470         if(NOT ${_out_subversion} MATCHES "[0-9]+")
471                 message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
472         endif()
473
474         # clumsy regex, only single char are ok but it could be unset
475
476         string(LENGTH "${_out_version_char}" _out_version_char_len)
477         if(NOT _out_version_char_len EQUAL 1)
478                 set(_out_version_char "")
479         elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
480                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
481         endif()
482
483         if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
484                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
485         endif()
486
487         math(EXPR BLENDER_VERSION_MAJOR "${_out_version} / 100")
488         math(EXPR BLENDER_VERSION_MINOR "${_out_version} % 100")
489         set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
490
491         set(BLENDER_SUBVERSION ${_out_subversion})
492         set(BLENDER_VERSION_CHAR ${_out_version_char})
493         set(BLENDER_VERSION_CYCLE ${_out_version_cycle})
494
495         # for packaging, alpha to numbers
496         string(COMPARE EQUAL "${BLENDER_VERSION_CHAR}" "" _out_version_char_empty)
497         if(${_out_version_char_empty})
498                 set(BLENDER_VERSION_CHAR_INDEX "0")
499         else()
500                 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 x y z)
501                 list(FIND _char_ls ${BLENDER_VERSION_CHAR} _out_version_char_index)
502                 math(EXPR BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index} + 1")
503                 unset(_char_ls)
504                 unset(_out_version_char_index)
505         endif()
506
507         unset(_out_subversion)
508         unset(_out_version_char)
509         unset(_out_version_char_empty)
510         unset(_out_version_cycle)
511
512         # message(STATUS "Version (Internal): ${BLENDER_VERSION}.${BLENDER_SUBVERSION}, Version (external): ${BLENDER_VERSION}${BLENDER_VERSION_CHAR}-${BLENDER_VERSION_CYCLE}")
513 endmacro()
514
515
516 # hacks to override initial project settings
517 # these macros must be called directly before/after project(Blender)
518 macro(blender_project_hack_pre)
519         # ----------------
520         # MINGW HACK START
521         # ignore system set flag, use our own
522         # must be before project(...)
523         # if the user wants to add their own its ok after first run.
524         if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
525                 set(_reset_standard_libraries OFF)
526         else()
527                 set(_reset_standard_libraries ON)
528         endif()
529
530         # ------------------
531         # GCC -O3 HACK START
532         # needed because O3 can cause problems but
533         # allow the builder to set O3 manually after.
534         if(DEFINED CMAKE_C_FLAGS_RELEASE)
535                 set(_reset_standard_cflags_rel OFF)
536         else()
537                 set(_reset_standard_cflags_rel ON)
538         endif()
539         if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
540                 set(_reset_standard_cxxflags_rel OFF)
541         else()
542                 set(_reset_standard_cxxflags_rel ON)
543         endif()
544 endmacro()
545
546
547 macro(blender_project_hack_post)
548         # --------------
549         # MINGW HACK END
550         if (_reset_standard_libraries)
551                 # Must come after project(...)
552                 #
553                 # MINGW workaround for -ladvapi32 being included which surprisingly causes
554                 # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
555                 # with a meaningless stack trace. by overriding this flag we ensure we only
556                 # have libs we define and that cmake & scons builds match.
557                 set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
558                 set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
559                 mark_as_advanced(
560                         CMAKE_C_STANDARD_LIBRARIES
561                         CMAKE_CXX_STANDARD_LIBRARIES
562                 )
563         endif()
564         unset(_reset_standard_libraries)
565
566
567         # ----------------
568         # GCC -O3 HACK END
569         if(_reset_standard_cflags_rel)
570                 string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
571                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
572                 mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
573         endif()
574
575         if(_reset_standard_cxxflags_rel)
576                 string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
577                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
578                 mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
579         endif()
580
581         unset(_reset_standard_cflags_rel)
582         unset(_reset_standard_cxxflags_rel)
583
584         # ------------------------------------------------------------------
585         # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
586         if(CMAKE_COMPILER_IS_GNUCC)
587                 if(NOT DARWIN)
588                         set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
589                 endif()
590         endif()
591
592 endmacro()