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