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