Add lib for n-dimensional cubic curve fitting
[blender-staging.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 macro(list_insert_after
27         list_id item_check item_add
28         )
29         set(_index)
30         list(FIND "${list_id}" "${item_check}" _index)
31         if("${_index}" MATCHES "-1")
32                 message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
33         endif()
34         math(EXPR _index "${_index} + 1")
35         list(INSERT ${list_id} "${_index}" ${item_add})
36         unset(_index)
37 endmacro()
38
39 macro(list_insert_before
40         list_id item_check item_add
41         )
42         set(_index)
43         list(FIND "${list_id}" "${item_check}" _index)
44         if("${_index}" MATCHES "-1")
45                 message(FATAL_ERROR "'${list_id}' doesn't contain '${item_check}'")
46         endif()
47         list(INSERT ${list_id} "${_index}" ${item_add})
48         unset(_index)
49 endmacro()
50
51 function(list_assert_duplicates
52         list_id
53         )
54         
55         # message(STATUS "list data: ${list_id}")
56
57         list(LENGTH list_id _len_before)
58         list(REMOVE_DUPLICATES list_id)
59         list(LENGTH list_id _len_after)
60         # message(STATUS "list size ${_len_before} -> ${_len_after}")
61         if(NOT _len_before EQUAL _len_after)
62                 message(FATAL_ERROR "duplicate found in list which should not contain duplicates: ${list_id}")
63         endif()
64         unset(_len_before)
65         unset(_len_after)
66 endfunction()
67
68
69 # foo_bar.spam --> foo_barMySuffix.spam
70 macro(file_suffix
71         file_name_new file_name file_suffix
72         )
73
74         get_filename_component(_file_name_PATH ${file_name} PATH)
75         get_filename_component(_file_name_NAME_WE ${file_name} NAME_WE)
76         get_filename_component(_file_name_EXT ${file_name} EXT)
77         set(${file_name_new} "${_file_name_PATH}/${_file_name_NAME_WE}${file_suffix}${_file_name_EXT}")
78
79         unset(_file_name_PATH)
80         unset(_file_name_NAME_WE)
81         unset(_file_name_EXT)
82 endmacro()
83
84 # useful for adding debug suffix to library lists:
85 # /somepath/foo.lib --> /somepath/foo_d.lib
86 macro(file_list_suffix
87         fp_list_new fp_list fn_suffix
88         )
89
90         # incase of empty list
91         set(_fp)
92         set(_fp_suffixed)
93
94         set(fp_list_new)
95
96         foreach(_fp ${fp_list})
97                 file_suffix(_fp_suffixed "${_fp}" "${fn_suffix}")
98                 list(APPEND "${fp_list_new}" "${_fp_suffixed}")
99         endforeach()
100
101         unset(_fp)
102         unset(_fp_suffixed)
103
104 endmacro()
105
106 if(UNIX AND NOT APPLE)
107         macro(find_package_static)
108                 set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
109                 set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
110                 find_package(${ARGV})
111                 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
112                 unset(_cmake_find_library_suffixes_back)
113         endmacro()
114
115         macro(find_library_static)
116                 set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
117                 set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
118                 find_library(${ARGV})
119                 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
120                 unset(_cmake_find_library_suffixes_back)
121         endmacro()
122 endif()
123
124 function(target_link_libraries_optimized
125         TARGET
126         LIBS
127         )
128
129         foreach(_LIB ${LIBS})
130                 target_link_libraries(${TARGET} optimized "${_LIB}")
131         endforeach()
132 endfunction()
133
134 function(target_link_libraries_debug
135         TARGET
136         LIBS
137         )
138
139         foreach(_LIB ${LIBS})
140                 target_link_libraries(${TARGET} debug "${_LIB}")
141         endforeach()
142 endfunction()
143
144 # Nicer makefiles with -I/1/foo/ instead of -I/1/2/3/../../foo/
145 # use it instead of include_directories()
146 function(blender_include_dirs
147         includes
148         )
149
150         set(_ALL_INCS "")
151         foreach(_INC ${ARGV})
152                 get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
153                 list(APPEND _ALL_INCS ${_ABS_INC})
154                 # for checking for invalid includes, disable for regular use
155                 ##if(NOT EXISTS "${_ABS_INC}/")
156                 ##      message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
157                 ##endif()
158         endforeach()
159         include_directories(${_ALL_INCS})
160 endfunction()
161
162 function(blender_include_dirs_sys
163         includes
164         )
165
166         set(_ALL_INCS "")
167         foreach(_INC ${ARGV})
168                 get_filename_component(_ABS_INC ${_INC} ABSOLUTE)
169                 list(APPEND _ALL_INCS ${_ABS_INC})
170                 ##if(NOT EXISTS "${_ABS_INC}/")
171                 ##      message(FATAL_ERROR "Include not found: ${_ABS_INC}/")
172                 ##endif()
173         endforeach()
174         include_directories(SYSTEM ${_ALL_INCS})
175 endfunction()
176
177 function(blender_source_group
178         sources
179         )
180
181         # Group by location on disk
182         source_group("Source Files" FILES CMakeLists.txt)
183
184         foreach(_SRC ${sources})
185                 get_filename_component(_SRC_EXT ${_SRC} EXT)
186                 if((${_SRC_EXT} MATCHES ".h") OR
187                    (${_SRC_EXT} MATCHES ".hpp") OR
188                    (${_SRC_EXT} MATCHES ".hh"))
189
190                         set(GROUP_ID "Header Files")
191                 else()
192                         set(GROUP_ID "Source Files")
193                 endif()
194                 source_group("${GROUP_ID}" FILES ${_SRC})
195         endforeach()
196 endfunction()
197
198
199 # only MSVC uses SOURCE_GROUP
200 function(blender_add_lib_nolist
201         name
202         sources
203         includes
204         includes_sys
205         )
206
207         # message(STATUS "Configuring library ${name}")
208
209         # include_directories(${includes})
210         # include_directories(SYSTEM ${includes_sys})
211         blender_include_dirs("${includes}")
212         blender_include_dirs_sys("${includes_sys}")
213
214         add_library(${name} ${sources})
215
216         # works fine without having the includes
217         # listed is helpful for IDE's (QtCreator/MSVC)
218         blender_source_group("${sources}")
219
220         list_assert_duplicates("${sources}")
221         list_assert_duplicates("${includes}")
222         # Not for system includes because they can resolve to the same path
223         # list_assert_duplicates("${includes_sys}")
224
225 endfunction()
226
227
228 function(blender_add_lib
229         name
230         sources
231         includes
232         includes_sys
233         )
234
235         blender_add_lib_nolist(${name} "${sources}" "${includes}" "${includes_sys}")
236
237         set_property(GLOBAL APPEND PROPERTY BLENDER_LINK_LIBS ${name})
238 endfunction()
239
240
241 function(SETUP_LIBDIRS)
242
243         # NOTE: For all new libraries, use absolute library paths.
244         # This should eventually be phased out.
245
246         link_directories(${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${FREETYPE_LIBPATH})
247
248         if(WITH_PYTHON)  #  AND NOT WITH_PYTHON_MODULE  # WIN32 needs
249                 link_directories(${PYTHON_LIBPATH})
250         endif()
251         if(WITH_SDL AND NOT WITH_SDL_DYNLOAD)
252                 link_directories(${SDL_LIBPATH})
253         endif()
254         if(WITH_CODEC_FFMPEG)
255                 link_directories(${FFMPEG_LIBPATH})
256         endif()
257         if(WITH_IMAGE_OPENEXR)
258                 link_directories(${OPENEXR_LIBPATH})
259         endif()
260         if(WITH_IMAGE_TIFF)
261                 link_directories(${TIFF_LIBPATH})
262         endif()
263         if(WITH_BOOST)
264                 link_directories(${BOOST_LIBPATH})
265         endif()
266         if(WITH_OPENIMAGEIO)
267                 link_directories(${OPENIMAGEIO_LIBPATH})
268         endif()
269         if(WITH_OPENCOLORIO)
270                 link_directories(${OPENCOLORIO_LIBPATH})
271         endif()
272         if(WITH_OPENVDB)
273                 link_directories(${OPENVDB_LIBPATH})
274         endif()
275         if(WITH_OPENAL)
276                 link_directories(${OPENAL_LIBPATH})
277         endif()
278         if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
279                 link_directories(${JACK_LIBPATH})
280         endif()
281         if(WITH_CODEC_SNDFILE)
282                 link_directories(${SNDFILE_LIBPATH})
283         endif()
284         if(WITH_FFTW3)
285                 link_directories(${FFTW3_LIBPATH})
286         endif()
287         if(WITH_OPENCOLLADA)
288                 link_directories(${OPENCOLLADA_LIBPATH})
289                 ## Never set
290                 # link_directories(${PCRE_LIBPATH})
291                 # link_directories(${EXPAT_LIBPATH})
292         endif()
293         if(WITH_LLVM)
294                 link_directories(${LLVM_LIBPATH})
295         endif()
296
297         if(WIN32 AND NOT UNIX)
298                 link_directories(${PTHREADS_LIBPATH})
299         endif()
300 endfunction()
301
302 function(setup_liblinks
303         target
304         )
305
306         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
307         set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
308
309         set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
310         set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
311
312         set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}" PARENT_SCOPE)
313         set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE)
314
315         target_link_libraries(
316                 ${target}
317                 ${PNG_LIBRARIES}
318                 ${ZLIB_LIBRARIES}
319                 ${FREETYPE_LIBRARY}
320         )
321
322         # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
323         if(WITH_PYTHON)  # AND NOT WITH_PYTHON_MODULE  # WIN32 needs
324                 target_link_libraries(${target} ${PYTHON_LINKFLAGS})
325
326                 if(WIN32 AND NOT UNIX)
327                         file_list_suffix(PYTHON_LIBRARIES_DEBUG "${PYTHON_LIBRARIES}" "_d")
328                         target_link_libraries_debug(${target} "${PYTHON_LIBRARIES_DEBUG}")
329                         target_link_libraries_optimized(${target} "${PYTHON_LIBRARIES}")
330                         unset(PYTHON_LIBRARIES_DEBUG)
331                 else()
332                         target_link_libraries(${target} ${PYTHON_LIBRARIES})
333                 endif()
334         endif()
335
336         if(WITH_LZO AND WITH_SYSTEM_LZO)
337                 target_link_libraries(${target} ${LZO_LIBRARIES})
338         endif()
339         if(WITH_SYSTEM_GLEW)
340                 target_link_libraries(${target} ${BLENDER_GLEW_LIBRARIES})
341         endif()
342         if(WITH_BULLET AND WITH_SYSTEM_BULLET)
343                 target_link_libraries(${target} ${BULLET_LIBRARIES})
344         endif()
345         if(WITH_AUDASPACE AND WITH_SYSTEM_AUDASPACE)
346                 target_link_libraries(${target} ${AUDASPACE_C_LIBRARIES} ${AUDASPACE_PY_LIBRARIES})
347         endif()
348         if(WITH_OPENAL)
349                 target_link_libraries(${target} ${OPENAL_LIBRARY})
350         endif()
351         if(WITH_FFTW3)
352                 target_link_libraries(${target} ${FFTW3_LIBRARIES})
353         endif()
354         if(WITH_JACK AND NOT WITH_JACK_DYNLOAD)
355                 target_link_libraries(${target} ${JACK_LIBRARIES})
356         endif()
357         if(WITH_CODEC_SNDFILE)
358                 target_link_libraries(${target} ${SNDFILE_LIBRARIES})
359         endif()
360         if(WITH_SDL AND NOT WITH_SDL_DYNLOAD)
361                 target_link_libraries(${target} ${SDL_LIBRARY})
362         endif()
363         if(WITH_CODEC_QUICKTIME)
364                 target_link_libraries(${target} ${QUICKTIME_LIBRARIES})
365         endif()
366         if(WITH_IMAGE_TIFF)
367                 target_link_libraries(${target} ${TIFF_LIBRARY})
368         endif()
369         if(WITH_OPENIMAGEIO)
370                 target_link_libraries(${target} ${OPENIMAGEIO_LIBRARIES})
371         endif()
372         if(WITH_OPENCOLORIO)
373                 target_link_libraries(${target} ${OPENCOLORIO_LIBRARIES})
374         endif()
375         if(WITH_OPENSUBDIV)
376                 if(WIN32 AND NOT UNIX)
377                         file_list_suffix(OPENSUBDIV_LIBRARIES_DEBUG "${OPENSUBDIV_LIBRARIES}" "_d")
378                         target_link_libraries_debug(${target} "${OPENSUBDIV_LIBRARIES_DEBUG}")
379                         target_link_libraries_optimized(${target} "${OPENSUBDIV_LIBRARIES}")
380                         unset(OPENSUBDIV_LIBRARIES_DEBUG)
381                 else()
382                         target_link_libraries(${target} ${OPENSUBDIV_LIBRARIES})
383                 endif()
384         endif()
385         if(WITH_OPENVDB)
386                 target_link_libraries(${target} ${OPENVDB_LIBRARIES} ${TBB_LIBRARIES})
387         endif()
388         if(WITH_CYCLES_OSL)
389                 target_link_libraries(${target} ${OSL_LIBRARIES})
390         endif()
391         if(WITH_BOOST)
392                 target_link_libraries(${target} ${BOOST_LIBRARIES})
393                 if(Boost_USE_STATIC_LIBS AND Boost_USE_ICU)
394                         target_link_libraries(${target} ${ICU_LIBRARIES})
395                 endif()
396         endif()
397         target_link_libraries(${target} ${JPEG_LIBRARIES})
398         if(WITH_IMAGE_OPENEXR)
399                 target_link_libraries(${target} ${OPENEXR_LIBRARIES})
400         endif()
401         if(WITH_IMAGE_OPENJPEG AND WITH_SYSTEM_OPENJPEG)
402                 target_link_libraries(${target} ${OPENJPEG_LIBRARIES})
403         endif()
404         if(WITH_CODEC_FFMPEG)
405                 target_link_libraries(${target} ${FFMPEG_LIBRARIES})
406         endif()
407         if(WITH_OPENCOLLADA)
408                 if(WIN32 AND NOT UNIX)
409                         file_list_suffix(OPENCOLLADA_LIBRARIES_DEBUG "${OPENCOLLADA_LIBRARIES}" "_d")
410                         target_link_libraries_debug(${target} "${OPENCOLLADA_LIBRARIES_DEBUG}")
411                         target_link_libraries_optimized(${target} "${OPENCOLLADA_LIBRARIES}")
412                         unset(OPENCOLLADA_LIBRARIES_DEBUG)
413
414                         file_list_suffix(PCRE_LIBRARIES_DEBUG "${PCRE_LIBRARIES}" "_d")
415                         target_link_libraries_debug(${target} "${PCRE_LIBRARIES_DEBUG}")
416                         target_link_libraries_optimized(${target} "${PCRE_LIBRARIES}")
417                         unset(PCRE_LIBRARIES_DEBUG)
418
419                         if(EXPAT_LIB)
420                                 file_list_suffix(EXPAT_LIB_DEBUG "${EXPAT_LIB}" "_d")
421                                 target_link_libraries_debug(${target} "${EXPAT_LIB_DEBUG}")
422                                 target_link_libraries_optimized(${target} "${EXPAT_LIB}")
423                                 unset(EXPAT_LIB_DEBUG)
424                         endif()
425                 else()
426                         target_link_libraries(
427                                 ${target}
428                                 ${OPENCOLLADA_LIBRARIES}
429                                 ${PCRE_LIBRARIES}
430                                 ${XML2_LIBRARIES}
431                                 ${EXPAT_LIB}
432                         )
433                 endif()
434         endif()
435         if(WITH_MEM_JEMALLOC)
436                 target_link_libraries(${target} ${JEMALLOC_LIBRARIES})
437         endif()
438         if(WITH_INPUT_NDOF)
439                 target_link_libraries(${target} ${NDOF_LIBRARIES})
440         endif()
441         if(WITH_MOD_CLOTH_ELTOPO)
442                 target_link_libraries(${target} ${LAPACK_LIBRARIES})
443         endif()
444         if(WITH_LLVM)
445                 target_link_libraries(${target} ${LLVM_LIBRARY})
446         endif()
447         if(WIN32 AND NOT UNIX)
448                 target_link_libraries(${target} ${PTHREADS_LIBRARIES})
449         endif()
450         if(UNIX AND NOT APPLE)
451                 if(WITH_OPENMP_STATIC)
452                         target_link_libraries(${target} ${OpenMP_LIBRARIES})
453                 endif()
454         endif()
455
456         # We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES dpeends on them..
457         if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
458                 target_link_libraries(${target} "extern_clew")
459                 if(WITH_CUDA_DYNLOAD)
460                         target_link_libraries(${target} "extern_cuew")
461                 else()
462                         target_link_libraries(${target} ${CUDA_CUDA_LIBRARY})
463                 endif()
464         endif()
465
466         #system libraries with no dependencies such as platform link libs or opengl should go last
467         target_link_libraries(${target}
468                         ${BLENDER_GL_LIBRARIES})
469
470         target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS})
471 endfunction()
472
473
474 function(SETUP_BLENDER_SORTED_LIBS)
475
476         get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
477
478         list(APPEND BLENDER_LINK_LIBS
479                 bf_windowmanager
480                 bf_render
481         )
482
483         if(WITH_MOD_FLUID)
484                 list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
485         endif()
486
487         if(WITH_CYCLES)
488                 list(APPEND BLENDER_LINK_LIBS
489                         cycles_render
490                         cycles_bvh
491                         cycles_device
492                         cycles_kernel
493                         cycles_util
494                         cycles_subd)
495                 if(WITH_CYCLES_OSL)
496                         list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
497                 endif()
498         endif()
499
500         # Sort libraries
501         set(BLENDER_SORTED_LIBS
502                 bf_windowmanager
503
504                 bf_editor_space_api
505                 bf_editor_space_action
506                 bf_editor_space_buttons
507                 bf_editor_space_console
508                 bf_editor_space_file
509                 bf_editor_space_graph
510                 bf_editor_space_image
511                 bf_editor_space_info
512                 bf_editor_space_logic
513                 bf_editor_space_nla
514                 bf_editor_space_node
515                 bf_editor_space_outliner
516                 bf_editor_space_script
517                 bf_editor_space_sequencer
518                 bf_editor_space_text
519                 bf_editor_space_time
520                 bf_editor_space_userpref
521                 bf_editor_space_view3d
522                 bf_editor_space_clip
523
524                 bf_editor_transform
525                 bf_editor_util
526                 bf_editor_uvedit
527                 bf_editor_curve
528                 bf_editor_gpencil
529                 bf_editor_interface
530                 bf_editor_mesh
531                 bf_editor_metaball
532                 bf_editor_object
533                 bf_editor_armature
534                 bf_editor_physics
535                 bf_editor_render
536                 bf_editor_screen
537                 bf_editor_sculpt_paint
538                 bf_editor_sound
539                 bf_editor_animation
540                 bf_editor_datafiles
541                 bf_editor_mask
542                 bf_editor_io
543
544                 bf_render
545                 bf_python
546                 bf_python_ext
547                 bf_python_mathutils
548                 bf_python_bmesh
549                 bf_freestyle
550                 bf_ikplugin
551                 bf_modifiers
552                 bf_bmesh
553                 bf_gpu
554                 bf_blenkernel
555                 bf_physics
556                 bf_nodes
557                 bf_rna
558                 bf_blenloader
559                 bf_imbuf
560                 bf_blenlib
561                 bf_depsgraph
562                 bf_intern_ghost
563                 bf_intern_string
564                 bf_avi
565                 bf_imbuf_cineon
566                 bf_imbuf_openexr
567                 bf_imbuf_openimageio
568                 bf_imbuf_dds
569                 bf_collada
570                 bf_intern_elbeem
571                 bf_intern_memutil
572                 bf_intern_guardedalloc
573                 bf_intern_ctr
574                 bf_intern_utfconv
575                 ge_blen_routines
576                 ge_converter
577                 ge_phys_dummy
578                 ge_phys_bullet
579                 bf_intern_smoke
580                 extern_lzma
581                 extern_curve_fit_nd
582                 ge_logic_ketsji
583                 extern_recastnavigation
584                 ge_logic
585                 ge_rasterizer
586                 ge_oglrasterizer
587                 ge_logic_expressions
588                 ge_scenegraph
589                 ge_logic_network
590                 ge_logic_ngnetwork
591                 ge_logic_loopbacknetwork
592                 bf_intern_moto
593                 extern_openjpeg
594                 ge_videotex
595                 bf_dna
596                 bf_blenfont
597                 bf_blentranslation
598                 bf_intern_audaspace
599                 bf_intern_mikktspace
600                 bf_intern_dualcon
601                 bf_intern_cycles
602                 cycles_render
603                 cycles_bvh
604                 cycles_device
605                 cycles_kernel
606                 cycles_util
607                 cycles_subd
608                 bf_intern_opencolorio
609                 bf_intern_eigen
610                 extern_rangetree
611                 extern_wcwidth
612                 bf_intern_libmv
613                 extern_glog
614                 extern_gflags
615                 extern_sdlew
616
617                 bf_intern_glew_mx
618         )
619
620         if(WITH_COMPOSITOR)
621                 # added for opencl compositor
622                 list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
623                 list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_intern_opencl")
624         endif()
625
626         if(WITH_LIBMV)
627                 list(APPEND BLENDER_SORTED_LIBS extern_ceres)
628         endif()
629
630         if(WITH_MOD_CLOTH_ELTOPO)
631                 list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
632         endif()
633
634         if(NOT WITH_SYSTEM_LZO)
635                 list(APPEND BLENDER_SORTED_LIBS extern_minilzo)
636         endif()
637
638         if(NOT WITH_SYSTEM_GLEW)
639                 list(APPEND BLENDER_SORTED_LIBS ${BLENDER_GLEW_LIBRARIES})
640         endif()
641
642         if(WITH_BINRELOC)
643                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
644         endif()
645
646         if(WITH_CXX_GUARDEDALLOC)
647                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
648         endif()
649
650         if(WITH_IK_SOLVER)
651                 list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
652         endif()
653
654         if(WITH_IK_ITASC)
655                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
656         endif()
657
658         if(WITH_CODEC_QUICKTIME)
659                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
660         endif()
661
662         if(WITH_INPUT_NDOF)
663                 list(APPEND BLENDER_SORTED_LIBS bf_intern_ghostndof3dconnexion)
664         endif()
665         
666         if(WITH_MOD_BOOLEAN)
667                 list(APPEND BLENDER_SORTED_LIBS extern_carve)
668         endif()
669
670         if(WITH_GHOST_XDND)
671                 list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
672         endif()
673
674         if(WITH_CYCLES_OSL)
675                 list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
676         endif()
677
678         if(WITH_INTERNATIONAL)
679                 list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
680         endif()
681
682         if(WITH_BULLET)
683                 list_insert_after(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_intern_rigidbody")
684         endif()
685
686         if(WITH_BULLET AND NOT WITH_SYSTEM_BULLET)
687                 list_insert_after(BLENDER_SORTED_LIBS "ge_logic_ngnetwork" "extern_bullet")
688         endif()
689
690         if(WITH_OPENSUBDIV)
691                 list(APPEND BLENDER_SORTED_LIBS bf_intern_opensubdiv)
692         endif()
693
694         if(WITH_OPENVDB)
695                 list(APPEND BLENDER_SORTED_LIBS bf_intern_openvdb)
696         endif()
697
698         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
699                 set(REMLIB ${SORTLIB})
700                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
701                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
702                                 set(REMLIB "")
703                         endif()
704                 endforeach()
705                 if(REMLIB)
706                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
707                         list(APPEND REM_MSG ${REMLIB})
708                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
709                 endif()
710         endforeach()
711         if(REM_MSG)
712                 list(SORT REM_MSG)
713                 message(STATUS "Blender Skipping: (${REM_MSG})")
714         endif()
715
716
717         set(BLENDER_SORTED_LIBS ${BLENDER_SORTED_LIBS} PARENT_SCOPE)
718
719         # for top-level tests
720         set_property(GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP ${BLENDER_SORTED_LIBS})
721 endfunction()
722
723 macro(TEST_SSE_SUPPORT
724         _sse_flags
725         _sse2_flags)
726
727         include(CheckCSourceRuns)
728
729         # message(STATUS "Detecting SSE support")
730         if(CMAKE_COMPILER_IS_GNUCC OR (CMAKE_C_COMPILER_ID MATCHES "Clang"))
731                 set(${_sse_flags} "-msse")
732                 set(${_sse2_flags} "-msse2")
733         elseif(MSVC)
734                 # x86_64 has this auto enabled
735                 if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
736                         set(${_sse_flags} "")
737                         set(${_sse2_flags} "")
738                 else()
739                         set(${_sse_flags} "/arch:SSE")
740                         set(${_sse2_flags} "/arch:SSE2")
741                 endif()
742         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
743                 set(${_sse_flags} "")  # icc defaults to -msse
744                 set(${_sse2_flags} "-msse2")
745         else()
746                 message(WARNING "SSE flags for this compiler: '${CMAKE_C_COMPILER_ID}' not known")
747                 set(${_sse_flags})
748                 set(${_sse2_flags})
749         endif()
750
751         set(CMAKE_REQUIRED_FLAGS "${${_sse_flags}} ${${_sse2_flags}}")
752
753         if(NOT DEFINED SUPPORT_SSE_BUILD)
754                 # result cached
755                 check_c_source_runs("
756                         #include <xmmintrin.h>
757                         int main(void) { __m128 v = _mm_setzero_ps(); return 0; }"
758                 SUPPORT_SSE_BUILD)
759
760                 if(SUPPORT_SSE_BUILD)
761                         message(STATUS "SSE Support: detected.")
762                 else()
763                         message(STATUS "SSE Support: missing.")
764                 endif()
765         endif()
766
767         if(NOT DEFINED SUPPORT_SSE2_BUILD)
768                 # result cached
769                 check_c_source_runs("
770                         #include <emmintrin.h>
771                         int main(void) { __m128d v = _mm_setzero_pd(); return 0; }"
772                 SUPPORT_SSE2_BUILD)
773
774                 if(SUPPORT_SSE2_BUILD)
775                         message(STATUS "SSE2 Support: detected.")
776                 else()
777                         message(STATUS "SSE2 Support: missing.")
778                 endif()
779         endif()
780
781         unset(CMAKE_REQUIRED_FLAGS)
782 endmacro()
783
784 # Only print message if running CMake first time
785 macro(message_first_run)
786         if(FIRST_RUN)
787                 message(${ARGV})
788         endif()
789 endmacro()
790
791 macro(TEST_UNORDERED_MAP_SUPPORT)
792         # - Detect unordered_map availability
793         # Test if a valid implementation of unordered_map exists
794         # and define the include path
795         # This module defines
796         #  HAVE_UNORDERED_MAP, whether unordered_map implementation was found
797         #
798         #  HAVE_STD_UNORDERED_MAP_HEADER, <unordered_map.h> was found
799         #  HAVE_UNORDERED_MAP_IN_STD_NAMESPACE, unordered_map is in namespace std
800         #  HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE, unordered_map is in namespace std::tr1
801         #
802         #  UNORDERED_MAP_INCLUDE_PREFIX, include path prefix for unordered_map, if found
803         #  UNORDERED_MAP_NAMESPACE, namespace for unordered_map, if found
804
805         include(CheckIncludeFileCXX)
806         CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_STD_UNORDERED_MAP_HEADER)
807         if(HAVE_STD_UNORDERED_MAP_HEADER)
808                 # Even so we've found unordered_map header file it doesn't
809                 # mean unordered_map and unordered_set will be declared in
810                 # std namespace.
811                 #
812                 # Namely, MSVC 2008 have unordered_map header which declares
813                 # unordered_map class in std::tr1 namespace. In order to support
814                 # this, we do extra check to see which exactly namespace is
815                 # to be used.
816
817                 include(CheckCXXSourceCompiles)
818                 CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
819                                           int main() {
820                                             std::unordered_map<int, int> map;
821                                             return 0;
822                                           }"
823                                           HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
824                 if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
825                         message_first_run(STATUS "Found unordered_map/set in std namespace.")
826
827                         set(HAVE_UNORDERED_MAP "TRUE")
828                         set(UNORDERED_MAP_INCLUDE_PREFIX "")
829                         set(UNORDERED_MAP_NAMESPACE "std")
830                 else()
831                         CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
832                                                   int main() {
833                                                     std::tr1::unordered_map<int, int> map;
834                                                     return 0;
835                                                   }"
836                                                   HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
837                         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
838                                 message_first_run(STATUS "Found unordered_map/set in std::tr1 namespace.")
839
840                                 set(HAVE_UNORDERED_MAP "TRUE")
841                                 set(UNORDERED_MAP_INCLUDE_PREFIX "")
842                                 set(UNORDERED_MAP_NAMESPACE "std::tr1")
843                         else()
844                                 message_first_run(STATUS "Found <unordered_map> but cannot find either std::unordered_map "
845                                                   "or std::tr1::unordered_map.")
846                         endif()
847                 endif()
848         else()
849                 CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
850                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
851                         message_first_run(STATUS "Found unordered_map/set in std::tr1 namespace.")
852
853                         set(HAVE_UNORDERED_MAP "TRUE")
854                         set(UNORDERED_MAP_INCLUDE_PREFIX "tr1")
855                         set(UNORDERED_MAP_NAMESPACE "std::tr1")
856                 else()
857                         message_first_run(STATUS "Unable to find <unordered_map> or <tr1/unordered_map>. ")
858                 endif()
859         endif()
860 endmacro()
861
862 macro(TEST_SHARED_PTR_SUPPORT)
863         # This check are coming from Ceres library.
864         #
865         # Find shared pointer header and namespace.
866         #
867         # This module defines the following variables:
868         #
869         # SHARED_PTR_FOUND: TRUE if shared_ptr found.
870         # SHARED_PTR_TR1_MEMORY_HEADER: True if <tr1/memory> header is to be used
871         # for the shared_ptr object, otherwise use <memory>.
872         # SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace,
873         # otherwise it's assumed to be defined in std namespace.
874
875         include(CheckIncludeFileCXX)
876         set(SHARED_PTR_FOUND FALSE)
877         CHECK_INCLUDE_FILE_CXX(memory HAVE_STD_MEMORY_HEADER)
878         if(HAVE_STD_MEMORY_HEADER)
879                 # Finding the memory header doesn't mean that shared_ptr is in std
880                 # namespace.
881                 #
882                 # In particular, MSVC 2008 has shared_ptr declared in std::tr1.  In
883                 # order to support this, we do an extra check to see which namespace
884                 # should be used.
885                 include(CheckCXXSourceCompiles)
886                 CHECK_CXX_SOURCE_COMPILES("#include <memory>
887                                            int main() {
888                                              std::shared_ptr<int> int_ptr;
889                                              return 0;
890                                            }"
891                                           HAVE_SHARED_PTR_IN_STD_NAMESPACE)
892
893                 if(HAVE_SHARED_PTR_IN_STD_NAMESPACE)
894                         message_first_run("-- Found shared_ptr in std namespace using <memory> header.")
895                         set(SHARED_PTR_FOUND TRUE)
896                 else()
897                         CHECK_CXX_SOURCE_COMPILES("#include <memory>
898                                                    int main() {
899                                                    std::tr1::shared_ptr<int> int_ptr;
900                                                    return 0;
901                                                    }"
902                                                   HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
903                         if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
904                                 message_first_run("-- Found shared_ptr in std::tr1 namespace using <memory> header.")
905                                 set(SHARED_PTR_TR1_NAMESPACE TRUE)
906                                 set(SHARED_PTR_FOUND TRUE)
907                         endif()
908                 endif()
909         endif()
910
911         if(NOT SHARED_PTR_FOUND)
912                 # Further, gcc defines shared_ptr in std::tr1 namespace and
913                 # <tr1/memory> is to be included for this. And what makes things
914                 # even more tricky is that gcc does have <memory> header, so
915                 # all the checks above wouldn't find shared_ptr.
916                 CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY_HEADER)
917                 if(HAVE_TR1_MEMORY_HEADER)
918                         CHECK_CXX_SOURCE_COMPILES("#include <tr1/memory>
919                                                    int main() {
920                                                    std::tr1::shared_ptr<int> int_ptr;
921                                                    return 0;
922                                                    }"
923                                                    HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
924                         if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
925                                 message_first_run("-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.")
926                                 set(SHARED_PTR_TR1_MEMORY_HEADER TRUE)
927                                 set(SHARED_PTR_TR1_NAMESPACE TRUE)
928                                 set(SHARED_PTR_FOUND TRUE)
929                         endif()
930                 endif()
931         endif()
932 endmacro()
933
934 # when we have warnings as errors applied globally this
935 # needs to be removed for some external libs which we dont maintain.
936
937 # utility macro
938 macro(remove_cc_flag
939         _flag)
940
941         foreach(flag ${ARGV})
942                 string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
943                 string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
944                 string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
945                 string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
946                 string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
947
948                 string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
949                 string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
950                 string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
951                 string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
952                 string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
953         endforeach()
954         unset(flag)
955
956 endmacro()
957
958 macro(add_cc_flag
959         flag)
960
961         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
962         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
963 endmacro()
964
965 macro(remove_strict_flags)
966
967         if(CMAKE_COMPILER_IS_GNUCC)
968                 remove_cc_flag(
969                         "-Wstrict-prototypes"
970                         "-Wmissing-prototypes"
971                         "-Wmissing-format-attribute"
972                         "-Wunused-local-typedefs"
973                         "-Wunused-macros"
974                         "-Wunused-parameter"
975                         "-Wwrite-strings"
976                         "-Wredundant-decls"
977                         "-Wundef"
978                         "-Wshadow"
979                         "-Wdouble-promotion"
980                         "-Wold-style-definition"
981                         "-Werror=[^ ]+"
982                         "-Werror"
983                 )
984
985                 # negate flags implied by '-Wall'
986                 add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
987         endif()
988
989         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
990                 remove_cc_flag(
991                         "-Wunused-parameter"
992                         "-Wunused-variable"
993                         "-Werror=[^ ]+"
994                         "-Werror"
995                 )
996
997                 # negate flags implied by '-Wall'
998                 add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
999         endif()
1000
1001         if(MSVC)
1002                 # TODO
1003         endif()
1004
1005 endmacro()
1006
1007 macro(remove_extra_strict_flags)
1008         if(CMAKE_COMPILER_IS_GNUCC)
1009                 remove_cc_flag(
1010                         "-Wunused-parameter"
1011                 )
1012         endif()
1013
1014         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
1015                 remove_cc_flag(
1016                         "-Wunused-parameter"
1017                 )
1018         endif()
1019
1020         if(MSVC)
1021                 # TODO
1022         endif()
1023 endmacro()
1024
1025 # note, we can only append flags on a single file so we need to negate the options.
1026 # at the moment we cant shut up ffmpeg deprecations, so use this, but will
1027 # probably add more removals here.
1028 macro(remove_strict_flags_file
1029         filenames)
1030
1031         foreach(_SOURCE ${ARGV})
1032
1033                 if(CMAKE_COMPILER_IS_GNUCC OR
1034                   (CMAKE_C_COMPILER_ID MATCHES "Clang"))
1035
1036                         set_source_files_properties(${_SOURCE}
1037                                 PROPERTIES
1038                                         COMPILE_FLAGS "${CC_REMOVE_STRICT_FLAGS}"
1039                         )
1040                 endif()
1041
1042                 if(MSVC)
1043                         # TODO
1044                 endif()
1045
1046         endforeach()
1047
1048         unset(_SOURCE)
1049
1050 endmacro()
1051
1052
1053 function(ADD_CHECK_C_COMPILER_FLAG
1054         _CFLAGS
1055         _CACHE_VAR
1056         _FLAG
1057         )
1058
1059         include(CheckCCompilerFlag)
1060
1061         CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
1062         if(${_CACHE_VAR})
1063                 # message(STATUS "Using CFLAG: ${_FLAG}")
1064                 set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}" PARENT_SCOPE)
1065         else()
1066                 message(STATUS "Unsupported CFLAG: ${_FLAG}")
1067         endif()
1068 endfunction()
1069
1070 function(ADD_CHECK_CXX_COMPILER_FLAG
1071         _CXXFLAGS
1072         _CACHE_VAR
1073         _FLAG
1074         )
1075
1076         include(CheckCXXCompilerFlag)
1077
1078         CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
1079         if(${_CACHE_VAR})
1080                 # message(STATUS "Using CXXFLAG: ${_FLAG}")
1081                 set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}" PARENT_SCOPE)
1082         else()
1083                 message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
1084         endif()
1085 endfunction()
1086
1087 function(get_blender_version)
1088         # extracts header vars and defines them in the parent scope:
1089         #
1090         # - BLENDER_VERSION (major.minor)
1091         # - BLENDER_VERSION_MAJOR
1092         # - BLENDER_VERSION_MINOR
1093         # - BLENDER_SUBVERSION (used for internal versioning mainly)
1094         # - BLENDER_VERSION_CHAR (a, b, c, ...or empty string)
1095         # - BLENDER_VERSION_CYCLE (alpha, beta, rc, release)
1096
1097         # So cmake depends on BKE_blender.h, beware of inf-loops!
1098         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h
1099                        ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
1100
1101         file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
1102
1103         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
1104         string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
1105         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
1106         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
1107
1108         if(NOT ${_out_version} MATCHES "[0-9]+")
1109                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
1110         endif()
1111
1112         if(NOT ${_out_subversion} MATCHES "[0-9]+")
1113                 message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
1114         endif()
1115
1116         # clumsy regex, only single char are ok but it could be unset
1117
1118         string(LENGTH "${_out_version_char}" _out_version_char_len)
1119         if(NOT _out_version_char_len EQUAL 1)
1120                 set(_out_version_char "")
1121         elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
1122                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
1123         endif()
1124
1125         if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
1126                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
1127         endif()
1128
1129         math(EXPR _out_version_major "${_out_version} / 100")
1130         math(EXPR _out_version_minor "${_out_version} % 100")
1131
1132         # for packaging, alpha to numbers
1133         string(COMPARE EQUAL "${_out_version_char}" "" _out_version_char_empty)
1134         if(${_out_version_char_empty})
1135                 set(_out_version_char_index "0")
1136         else()
1137                 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)
1138                 list(FIND _char_ls ${_out_version_char} _out_version_char_index)
1139                 math(EXPR _out_version_char_index "${_out_version_char_index} + 1")
1140         endif()
1141
1142         # output vars
1143         set(BLENDER_VERSION "${_out_version_major}.${_out_version_minor}" PARENT_SCOPE)
1144         set(BLENDER_VERSION_MAJOR "${_out_version_major}" PARENT_SCOPE)
1145         set(BLENDER_VERSION_MINOR "${_out_version_minor}" PARENT_SCOPE)
1146         set(BLENDER_SUBVERSION "${_out_subversion}" PARENT_SCOPE)
1147         set(BLENDER_VERSION_CHAR "${_out_version_char}" PARENT_SCOPE)
1148         set(BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index}" PARENT_SCOPE)
1149         set(BLENDER_VERSION_CYCLE "${_out_version_cycle}" PARENT_SCOPE)
1150
1151 endfunction()
1152
1153
1154 # hacks to override initial project settings
1155 # these macros must be called directly before/after project(Blender)
1156 macro(blender_project_hack_pre)
1157         # ----------------
1158         # MINGW HACK START
1159         # ignore system set flag, use our own
1160         # must be before project(...)
1161         # if the user wants to add their own its ok after first run.
1162         if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
1163                 set(_reset_standard_libraries OFF)
1164         else()
1165                 set(_reset_standard_libraries ON)
1166         endif()
1167
1168         # ------------------
1169         # GCC -O3 HACK START
1170         # needed because O3 can cause problems but
1171         # allow the builder to set O3 manually after.
1172         if(DEFINED CMAKE_C_FLAGS_RELEASE)
1173                 set(_reset_standard_cflags_rel OFF)
1174         else()
1175                 set(_reset_standard_cflags_rel ON)
1176         endif()
1177         if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
1178                 set(_reset_standard_cxxflags_rel OFF)
1179         else()
1180                 set(_reset_standard_cxxflags_rel ON)
1181         endif()
1182 endmacro()
1183
1184
1185 macro(blender_project_hack_post)
1186         # --------------
1187         # MINGW HACK END
1188         if(_reset_standard_libraries)
1189                 # Must come after projecINCt(...)
1190                 #
1191                 # MINGW workaround for -ladvapi32 being included which surprisingly causes
1192                 # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
1193                 # with a meaningless stack trace. by overriding this flag we ensure we only
1194                 # have libs we define.
1195                 set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
1196                 set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
1197                 mark_as_advanced(
1198                         CMAKE_C_STANDARD_LIBRARIES
1199                         CMAKE_CXX_STANDARD_LIBRARIES
1200                 )
1201         endif()
1202         unset(_reset_standard_libraries)
1203
1204
1205         # ----------------
1206         # GCC -O3 HACK END
1207         if(_reset_standard_cflags_rel)
1208                 string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
1209                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
1210                 mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
1211         endif()
1212
1213         if(_reset_standard_cxxflags_rel)
1214                 string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1215                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
1216                 mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
1217         endif()
1218
1219         unset(_reset_standard_cflags_rel)
1220         unset(_reset_standard_cxxflags_rel)
1221
1222         # ------------------------------------------------------------------
1223         # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
1224         if(CMAKE_COMPILER_IS_GNUCC)
1225                 if(NOT DARWIN)
1226                         set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
1227                 endif()
1228         endif()
1229
1230 endmacro()
1231
1232 # pair of macros to allow libraries to be specify files to install, but to
1233 # only install them at the end so the directories don't get cleared with
1234 # the files in them. used by cycles to install addon.
1235 function(delayed_install
1236         base
1237         files
1238         destination)
1239
1240         foreach(f ${files})
1241                 if(IS_ABSOLUTE ${f})
1242                         set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${f})
1243                 else()
1244                         set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${base}/${f})
1245                 endif()
1246                 set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
1247         endforeach()
1248 endfunction()
1249
1250 # note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
1251 # does not get expanded in calling but is preserved
1252 function(delayed_do_install
1253         targetdir)
1254
1255         get_property(files GLOBAL PROPERTY DELAYED_INSTALL_FILES)
1256         get_property(destinations GLOBAL PROPERTY DELAYED_INSTALL_DESTINATIONS)
1257
1258         if(files)
1259                 list(LENGTH files n)
1260                 math(EXPR n "${n}-1")
1261
1262                 foreach(i RANGE ${n})
1263                         list(GET files ${i} f)
1264                         list(GET destinations ${i} d)
1265                         install(FILES ${f} DESTINATION ${targetdir}/${d})
1266                 endforeach()
1267         endif()
1268 endfunction()
1269
1270
1271 function(data_to_c
1272         file_from file_to
1273         list_to_add
1274         )
1275
1276         list(APPEND ${list_to_add} ${file_to})
1277         set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
1278
1279         get_filename_component(_file_to_path ${file_to} PATH)
1280
1281         add_custom_command(
1282                 OUTPUT ${file_to}
1283                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1284                 COMMAND "$<TARGET_FILE:datatoc>" ${file_from} ${file_to}
1285                 DEPENDS ${file_from} datatoc)
1286
1287         set_source_files_properties(${file_to} PROPERTIES GENERATED TRUE)
1288 endfunction()
1289
1290
1291 # same as above but generates the var name and output automatic.
1292 function(data_to_c_simple
1293         file_from
1294         list_to_add
1295         )
1296
1297         # remove ../'s
1298         get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from}   REALPATH)
1299         get_filename_component(_file_to   ${CMAKE_CURRENT_BINARY_DIR}/${file_from}.c REALPATH)
1300
1301         list(APPEND ${list_to_add} ${_file_to})
1302         set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
1303
1304         get_filename_component(_file_to_path ${_file_to} PATH)
1305
1306         add_custom_command(
1307                 OUTPUT  ${_file_to}
1308                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1309                 COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
1310                 DEPENDS ${_file_from} datatoc)
1311
1312         set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
1313 endfunction()
1314
1315 # macro for converting pixmap directory to a png and then a c file
1316 function(data_to_c_simple_icons
1317         path_from
1318         list_to_add
1319         )
1320
1321         # Conversion steps
1322         #  path_from  ->  _file_from  ->  _file_to
1323         #  foo/*.dat  ->  foo.png     ->  foo.png.c
1324
1325         get_filename_component(_path_from_abs ${path_from} ABSOLUTE)
1326         # remove ../'s
1327         get_filename_component(_file_from ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png   REALPATH)
1328         get_filename_component(_file_to   ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png.c REALPATH)
1329
1330         list(APPEND ${list_to_add} ${_file_to})
1331         set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
1332
1333         get_filename_component(_file_to_path ${_file_to} PATH)
1334
1335         # ideally we wouldn't glob, but storing all names for all pixmaps is a bit heavy
1336         file(GLOB _icon_files "${path_from}/*.dat")
1337
1338         add_custom_command(
1339                 OUTPUT  ${_file_from} ${_file_to}
1340                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1341                 #COMMAND python3 ${CMAKE_SOURCE_DIR}/source/blender/datatoc/datatoc_icon.py ${_path_from_abs} ${_file_from}
1342                 COMMAND "$<TARGET_FILE:datatoc_icon>" ${_path_from_abs} ${_file_from}
1343                 COMMAND "$<TARGET_FILE:datatoc>" ${_file_from} ${_file_to}
1344                 DEPENDS
1345                         ${_icon_files}
1346                         datatoc_icon
1347                         datatoc
1348                         # could be an arg but for now we only create icons depending on UI_icons.h
1349                         ${CMAKE_SOURCE_DIR}/source/blender/editors/include/UI_icons.h
1350                 )
1351
1352         set_source_files_properties(${_file_from} ${_file_to} PROPERTIES GENERATED TRUE)
1353 endfunction()
1354
1355 # XXX Not used for now...
1356 function(svg_to_png
1357         file_from
1358         file_to
1359         dpi
1360         list_to_add
1361         )
1362
1363         # remove ../'s
1364         get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
1365         get_filename_component(_file_to   ${CMAKE_CURRENT_SOURCE_DIR}/${file_to}   REALPATH)
1366
1367         list(APPEND ${list_to_add} ${_file_to})
1368         set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
1369
1370         find_program(INKSCAPE_EXE inkscape)
1371         mark_as_advanced(INKSCAPE_EXE)
1372
1373         if(INKSCAPE_EXE)
1374                 if(APPLE)
1375                         # in OS X app bundle, the binary is a shim that doesn't take any
1376                         # command line arguments, replace it with the actual binary
1377                         string(REPLACE "MacOS/Inkscape" "Resources/bin/inkscape" INKSCAPE_REAL_EXE ${INKSCAPE_EXE})
1378                         if(EXISTS "${INKSCAPE_REAL_EXE}")
1379                                 set(INKSCAPE_EXE ${INKSCAPE_REAL_EXE})
1380                         endif()
1381                 endif()
1382
1383                 add_custom_command(
1384                         OUTPUT  ${_file_to}
1385                         COMMAND ${INKSCAPE_EXE} ${_file_from} --export-dpi=${dpi}  --without-gui --export-png=${_file_to}
1386                         DEPENDS ${_file_from} ${INKSCAPE_EXE}
1387                 )
1388         else()
1389                 message(WARNING "Inkscape not found, could not re-generate ${_file_to} from ${_file_from}!")
1390         endif()
1391 endfunction()
1392
1393 function(msgfmt_simple
1394         file_from
1395         list_to_add
1396         )
1397
1398         # remove ../'s
1399         get_filename_component(_file_from_we ${file_from} NAME_WE)
1400
1401         get_filename_component(_file_from ${file_from} REALPATH)
1402         get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${_file_from_we}.mo REALPATH)
1403
1404         list(APPEND ${list_to_add} ${_file_to})
1405         set(${list_to_add} ${${list_to_add}} PARENT_SCOPE)
1406
1407         get_filename_component(_file_to_path ${_file_to} PATH)
1408
1409         add_custom_command(
1410                 OUTPUT  ${_file_to}
1411                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1412                 COMMAND "$<TARGET_FILE:msgfmt>" ${_file_from} ${_file_to}
1413                 DEPENDS msgfmt ${_file_from})
1414
1415         set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
1416 endfunction()
1417
1418 function(find_python_package
1419         package
1420         )
1421
1422         string(TOUPPER ${package} _upper_package)
1423
1424         # set but invalid
1425         if((NOT ${PYTHON_${_upper_package}_PATH} STREQUAL "") AND
1426            (NOT ${PYTHON_${_upper_package}_PATH} MATCHES NOTFOUND))
1427 #               if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}/${package}")
1428 #                       message(WARNING "PYTHON_${_upper_package}_PATH is invalid, ${package} not found in '${PYTHON_${_upper_package}_PATH}' "
1429 #                                       "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
1430 #                       set(WITH_PYTHON_INSTALL${_upper_package} OFF)
1431 #               endif()
1432         # not set, so initialize
1433         else()
1434                 string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
1435                 list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
1436
1437                 # re-cache
1438                 unset(PYTHON_${_upper_package}_PATH CACHE)
1439                 find_path(PYTHON_${_upper_package}_PATH
1440                   NAMES
1441                     ${package}
1442                   HINTS
1443                     "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
1444                     "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
1445                   PATH_SUFFIXES
1446                     site-packages
1447                     dist-packages
1448                    NO_DEFAULT_PATH
1449                 )
1450
1451                  if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
1452                         message(WARNING
1453                                 "Python package '${package}' path could not be found in:\n"
1454                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${package}', "
1455                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${package}', "
1456                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
1457                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
1458                                 "\n"
1459                                 "The 'WITH_PYTHON_INSTALL_${_upper_package}' option will be ignored when installing Python.\n"
1460                                 "The build will be usable, only add-ons that depend on this package won't be functional."
1461                         )
1462                         set(WITH_PYTHON_INSTALL_${_upper_package} OFF PARENT_SCOPE)
1463                 else()
1464                         message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
1465                 endif()
1466         endif()
1467 endfunction()
1468
1469 # like Python's 'print(dir())'
1470 function(print_all_vars)
1471         get_cmake_property(_vars VARIABLES)
1472         foreach(_var ${_vars})
1473                 message("${_var}=${${_var}}")
1474         endforeach()
1475 endfunction()