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