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