tweak remove_strict_flags so it can be used with gcc's -Wall
[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_cc_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(add_cc_flag
398         flag)
399
400         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
401         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
402 endmacro()
403
404 macro(remove_strict_flags)
405
406         if(CMAKE_COMPILER_IS_GNUCC)
407                 remove_cc_flag("-Wstrict-prototypes")
408                 remove_cc_flag("-Wunused-parameter")
409                 remove_cc_flag("-Wwrite-strings")
410                 remove_cc_flag("-Wundef")
411                 remove_cc_flag("-Wshadow")
412                 remove_cc_flag("-Werror=[^ ]+")
413                 remove_cc_flag("-Werror")
414
415                 # negate flags implied by '-Wall'
416                 add_cc_flag("-Wno-unused-parameter")
417                 add_cc_flag("-Wno-unused-but-set-variable")
418         endif()
419
420         if(MSVC)
421                 # TODO
422         endif()
423
424 endmacro()
425
426 # note, we can only append flags on a single file so we need to negate the options.
427 # at the moment we cant shut up ffmpeg deprecations, so use this, but will
428 # probably add more removals here.
429 macro(remove_strict_flags_file
430         filenames)
431
432         foreach(_SOURCE ${ARGV})
433
434                 if(CMAKE_COMPILER_IS_GNUCC)
435                         set_source_files_properties(${_SOURCE}
436                                 PROPERTIES
437                                         COMPILE_FLAGS "-Wno-deprecated-declarations"
438                         )
439                 endif()
440
441                 if(MSVC)
442                         # TODO
443                 endif()
444
445         endforeach()    
446
447         unset(_SOURCE)
448
449 endmacro()
450
451
452 macro(ADD_CHECK_C_COMPILER_FLAG
453         _CFLAGS
454         _CACHE_VAR
455         _FLAG)
456
457         include(CheckCCompilerFlag)
458
459         CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
460         if(${_CACHE_VAR})
461                 # message(STATUS "Using CFLAG: ${_FLAG}")
462                 set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
463         else()
464                 message(STATUS "Unsupported CFLAG: ${_FLAG}")
465         endif()
466 endmacro()
467
468 macro(ADD_CHECK_CXX_COMPILER_FLAG
469         _CXXFLAGS
470         _CACHE_VAR
471         _FLAG)
472
473         include(CheckCXXCompilerFlag)
474
475         CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
476         if(${_CACHE_VAR})
477                 # message(STATUS "Using CXXFLAG: ${_FLAG}")
478                 set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
479         else()
480                 message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
481         endif()
482 endmacro()
483
484 macro(get_blender_version)
485         # So cmake depends on BKE_blender.h, beware of inf-loops!
486         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
487
488         file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
489
490         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
491         string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
492         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
493         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
494
495         if(NOT ${_out_version} MATCHES "[0-9]+")
496                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
497         endif()
498
499         if(NOT ${_out_subversion} MATCHES "[0-9]+")
500                 message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
501         endif()
502
503         # clumsy regex, only single char are ok but it could be unset
504
505         string(LENGTH "${_out_version_char}" _out_version_char_len)
506         if(NOT _out_version_char_len EQUAL 1)
507                 set(_out_version_char "")
508         elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
509                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
510         endif()
511
512         if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
513                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
514         endif()
515
516         math(EXPR BLENDER_VERSION_MAJOR "${_out_version} / 100")
517         math(EXPR BLENDER_VERSION_MINOR "${_out_version} % 100")
518         set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
519
520         set(BLENDER_SUBVERSION ${_out_subversion})
521         set(BLENDER_VERSION_CHAR ${_out_version_char})
522         set(BLENDER_VERSION_CYCLE ${_out_version_cycle})
523
524         # for packaging, alpha to numbers
525         string(COMPARE EQUAL "${BLENDER_VERSION_CHAR}" "" _out_version_char_empty)
526         if(${_out_version_char_empty})
527                 set(BLENDER_VERSION_CHAR_INDEX "0")
528         else()
529                 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)
530                 list(FIND _char_ls ${BLENDER_VERSION_CHAR} _out_version_char_index)
531                 math(EXPR BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index} + 1")
532                 unset(_char_ls)
533                 unset(_out_version_char_index)
534         endif()
535
536         unset(_out_subversion)
537         unset(_out_version_char)
538         unset(_out_version_char_empty)
539         unset(_out_version_cycle)
540
541         # message(STATUS "Version (Internal): ${BLENDER_VERSION}.${BLENDER_SUBVERSION}, Version (external): ${BLENDER_VERSION}${BLENDER_VERSION_CHAR}-${BLENDER_VERSION_CYCLE}")
542 endmacro()
543
544
545 # hacks to override initial project settings
546 # these macros must be called directly before/after project(Blender)
547 macro(blender_project_hack_pre)
548         # ----------------
549         # MINGW HACK START
550         # ignore system set flag, use our own
551         # must be before project(...)
552         # if the user wants to add their own its ok after first run.
553         if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
554                 set(_reset_standard_libraries OFF)
555         else()
556                 set(_reset_standard_libraries ON)
557         endif()
558
559         # ------------------
560         # GCC -O3 HACK START
561         # needed because O3 can cause problems but
562         # allow the builder to set O3 manually after.
563         if(DEFINED CMAKE_C_FLAGS_RELEASE)
564                 set(_reset_standard_cflags_rel OFF)
565         else()
566                 set(_reset_standard_cflags_rel ON)
567         endif()
568         if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
569                 set(_reset_standard_cxxflags_rel OFF)
570         else()
571                 set(_reset_standard_cxxflags_rel ON)
572         endif()
573 endmacro()
574
575
576 macro(blender_project_hack_post)
577         # --------------
578         # MINGW HACK END
579         if (_reset_standard_libraries)
580                 # Must come after project(...)
581                 #
582                 # MINGW workaround for -ladvapi32 being included which surprisingly causes
583                 # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
584                 # with a meaningless stack trace. by overriding this flag we ensure we only
585                 # have libs we define and that cmake & scons builds match.
586                 set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
587                 set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
588                 mark_as_advanced(
589                         CMAKE_C_STANDARD_LIBRARIES
590                         CMAKE_CXX_STANDARD_LIBRARIES
591                 )
592         endif()
593         unset(_reset_standard_libraries)
594
595
596         # ----------------
597         # GCC -O3 HACK END
598         if(_reset_standard_cflags_rel)
599                 string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
600                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
601                 mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
602         endif()
603
604         if(_reset_standard_cxxflags_rel)
605                 string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
606                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
607                 mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
608         endif()
609
610         unset(_reset_standard_cflags_rel)
611         unset(_reset_standard_cxxflags_rel)
612
613         # ------------------------------------------------------------------
614         # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
615         if(CMAKE_COMPILER_IS_GNUCC)
616                 if(NOT DARWIN)
617                         set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
618                 endif()
619         endif()
620
621 endmacro()