CMake: Add a flag to explicitly disable SSE/SSE2 intrinsics
[blender.git] / build_files / cmake / macros.cmake
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 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         include(CheckCSourceRuns)
726
727         # This program will compile correctly if and only if
728         # this C compiler supports C99 stdbool.
729         check_c_source_runs("
730                 #include <stdbool.h>
731                 int main(void) { return (int)false; }"
732         HAVE_STDBOOL_H)
733 endmacro()
734
735 macro(TEST_UNORDERED_MAP_SUPPORT)
736         # - Detect unordered_map availability
737         # Test if a valid implementation of unordered_map exists
738         # and define the include path
739         # This module defines
740         #  HAVE_UNORDERED_MAP, whether unordered_map implementation was found
741         #  
742         #  HAVE_STD_UNORDERED_MAP_HEADER, <unordered_map.h> was found
743         #  HAVE_UNORDERED_MAP_IN_STD_NAMESPACE, unordered_map is in namespace std
744         #  HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE, unordered_map is in namespace std::tr1
745         #  
746         #  UNORDERED_MAP_INCLUDE_PREFIX, include path prefix for unordered_map, if found
747         #  UNORDERED_MAP_NAMESPACE, namespace for unordered_map, if found
748
749         include(CheckIncludeFileCXX)
750         CHECK_INCLUDE_FILE_CXX("unordered_map" HAVE_STD_UNORDERED_MAP_HEADER)
751         if(HAVE_STD_UNORDERED_MAP_HEADER)
752                 # Even so we've found unordered_map header file it doesn't
753                 # mean unordered_map and unordered_set will be declared in
754                 # std namespace.
755                 #
756                 # Namely, MSVC 2008 have unordered_map header which declares
757                 # unordered_map class in std::tr1 namespace. In order to support
758                 # this, we do extra check to see which exactly namespace is
759                 # to be used.
760
761                 include(CheckCXXSourceCompiles)
762                 CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
763                                           int main() {
764                                             std::unordered_map<int, int> map;
765                                             return 0;
766                                           }"
767                                           HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
768                 if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
769                         message(STATUS "Found unordered_map/set in std namespace.")
770
771                         set(HAVE_UNORDERED_MAP "TRUE")
772                         set(UNORDERED_MAP_INCLUDE_PREFIX "")
773                         set(UNORDERED_MAP_NAMESPACE "std")
774                 else()
775                         CHECK_CXX_SOURCE_COMPILES("#include <unordered_map>
776                                                   int main() {
777                                                     std::tr1::unordered_map<int, int> map;
778                                                     return 0;
779                                                   }"
780                                                   HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
781                         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
782                                 message(STATUS "Found unordered_map/set in std::tr1 namespace.")
783
784                                 set(HAVE_UNORDERED_MAP "TRUE")
785                                 set(UNORDERED_MAP_INCLUDE_PREFIX "")
786                                 set(UNORDERED_MAP_NAMESPACE "std::tr1")
787                         else()
788                                 message(STATUS "Found <unordered_map> but cannot find either std::unordered_map "
789                                         "or std::tr1::unordered_map.")
790                         endif()
791                 endif()
792         else()
793                 CHECK_INCLUDE_FILE_CXX("tr1/unordered_map" HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
794                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
795                         message(STATUS "Found unordered_map/set in std::tr1 namespace.")
796
797                         set(HAVE_UNORDERED_MAP "TRUE")
798                         set(UNORDERED_MAP_INCLUDE_PREFIX "tr1")
799                         set(UNORDERED_MAP_NAMESPACE "std::tr1")
800                 else()
801                         message(STATUS "Unable to find <unordered_map> or <tr1/unordered_map>. ")
802                 endif()
803         endif()
804 endmacro()
805
806 macro(TEST_SHARED_PTR_SUPPORT)
807         # This check are coming from Ceres library.
808         #
809         # Find shared pointer header and namespace.
810         #
811         # This module defines the following variables:
812         #
813         # SHARED_PTR_FOUND: TRUE if shared_ptr found.
814         # SHARED_PTR_TR1_MEMORY_HEADER: True if <tr1/memory> header is to be used
815         # for the shared_ptr object, otherwise use <memory>.
816         # SHARED_PTR_TR1_NAMESPACE: TRUE if shared_ptr is defined in std::tr1 namespace,
817         # otherwise it's assumed to be defined in std namespace.
818
819         include(CheckIncludeFileCXX)
820         set(SHARED_PTR_FOUND FALSE)
821         CHECK_INCLUDE_FILE_CXX(memory HAVE_STD_MEMORY_HEADER)
822         if(HAVE_STD_MEMORY_HEADER)
823                 # Finding the memory header doesn't mean that shared_ptr is in std
824                 # namespace.
825                 #
826                 # In particular, MSVC 2008 has shared_ptr declared in std::tr1.  In
827                 # order to support this, we do an extra check to see which namespace
828                 # should be used.
829                 include(CheckCXXSourceCompiles)
830                 CHECK_CXX_SOURCE_COMPILES("#include <memory>
831                                            int main() {
832                                              std::shared_ptr<int> int_ptr;
833                                              return 0;
834                                            }"
835                                           HAVE_SHARED_PTR_IN_STD_NAMESPACE)
836
837                 if(HAVE_SHARED_PTR_IN_STD_NAMESPACE)
838                         message("-- Found shared_ptr in std namespace using <memory> header.")
839                         set(SHARED_PTR_FOUND TRUE)
840                 else()
841                         CHECK_CXX_SOURCE_COMPILES("#include <memory>
842                                                    int main() {
843                                                    std::tr1::shared_ptr<int> int_ptr;
844                                                    return 0;
845                                                    }"
846                                                   HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
847                         if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE)
848                                 message("-- Found shared_ptr in std::tr1 namespace using <memory> header.")
849                                 set(SHARED_PTR_TR1_NAMESPACE TRUE)
850                                 set(SHARED_PTR_FOUND TRUE)
851                         endif()
852                 endif()
853         endif()
854
855         if(NOT SHARED_PTR_FOUND)
856                 # Further, gcc defines shared_ptr in std::tr1 namespace and
857                 # <tr1/memory> is to be included for this. And what makes things
858                 # even more tricky is that gcc does have <memory> header, so
859                 # all the checks above wouldn't find shared_ptr.
860                 CHECK_INCLUDE_FILE_CXX("tr1/memory" HAVE_TR1_MEMORY_HEADER)
861                 if(HAVE_TR1_MEMORY_HEADER)
862                         CHECK_CXX_SOURCE_COMPILES("#include <tr1/memory>
863                                                    int main() {
864                                                    std::tr1::shared_ptr<int> int_ptr;
865                                                    return 0;
866                                                    }"
867                                                    HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
868                         if(HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER)
869                                 message("-- Found shared_ptr in std::tr1 namespace using <tr1/memory> header.")
870                                 set(SHARED_PTR_TR1_MEMORY_HEADER TRUE)
871                                 set(SHARED_PTR_TR1_NAMESPACE TRUE)
872                                 set(SHARED_PTR_FOUND TRUE)
873                         endif()
874                 endif()
875         endif()
876 endmacro()
877
878 # when we have warnings as errors applied globally this
879 # needs to be removed for some external libs which we dont maintain.
880
881 # utility macro
882 macro(remove_cc_flag
883         flag)
884
885         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
886         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
887         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
888         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
889         string(REGEX REPLACE ${flag} "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
890
891         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
892         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
893         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
894         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}")
895         string(REGEX REPLACE ${flag} "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
896
897 endmacro()
898
899 macro(add_cc_flag
900         flag)
901
902         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
903         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
904 endmacro()
905
906 macro(remove_strict_flags)
907
908         if(CMAKE_COMPILER_IS_GNUCC)
909                 remove_cc_flag("-Wstrict-prototypes")
910                 remove_cc_flag("-Wmissing-prototypes")
911                 remove_cc_flag("-Wunused-parameter")
912                 remove_cc_flag("-Wwrite-strings")
913                 remove_cc_flag("-Wredundant-decls")
914                 remove_cc_flag("-Wundef")
915                 remove_cc_flag("-Wshadow")
916                 remove_cc_flag("-Wdouble-promotion")
917                 remove_cc_flag("-Wold-style-definition")
918                 remove_cc_flag("-Werror=[^ ]+")
919                 remove_cc_flag("-Werror")
920
921                 # negate flags implied by '-Wall'
922                 add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
923         endif()
924
925         if(CMAKE_C_COMPILER_ID MATCHES "Clang")
926                 remove_cc_flag("-Wunused-parameter")
927                 remove_cc_flag("-Wunused-variable")
928                 remove_cc_flag("-Werror=[^ ]+")
929                 remove_cc_flag("-Werror")
930
931                 # negate flags implied by '-Wall'
932                 add_cc_flag("${CC_REMOVE_STRICT_FLAGS}")
933         endif()
934
935         if(MSVC)
936                 # TODO
937         endif()
938
939 endmacro()
940
941 # note, we can only append flags on a single file so we need to negate the options.
942 # at the moment we cant shut up ffmpeg deprecations, so use this, but will
943 # probably add more removals here.
944 macro(remove_strict_flags_file
945         filenames)
946
947         foreach(_SOURCE ${ARGV})
948
949                 if(CMAKE_COMPILER_IS_GNUCC OR
950                   (CMAKE_C_COMPILER_ID MATCHES "Clang"))
951
952                         set_source_files_properties(${_SOURCE}
953                                 PROPERTIES
954                                         COMPILE_FLAGS "${CC_REMOVE_STRICT_FLAGS}"
955                         )
956                 endif()
957
958                 if(MSVC)
959                         # TODO
960                 endif()
961
962         endforeach()
963
964         unset(_SOURCE)
965
966 endmacro()
967
968
969 macro(ADD_CHECK_C_COMPILER_FLAG
970         _CFLAGS
971         _CACHE_VAR
972         _FLAG)
973
974         include(CheckCCompilerFlag)
975
976         CHECK_C_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
977         if(${_CACHE_VAR})
978                 # message(STATUS "Using CFLAG: ${_FLAG}")
979                 set(${_CFLAGS} "${${_CFLAGS}} ${_FLAG}")
980         else()
981                 message(STATUS "Unsupported CFLAG: ${_FLAG}")
982         endif()
983 endmacro()
984
985 macro(ADD_CHECK_CXX_COMPILER_FLAG
986         _CXXFLAGS
987         _CACHE_VAR
988         _FLAG)
989
990         include(CheckCXXCompilerFlag)
991
992         CHECK_CXX_COMPILER_FLAG("${_FLAG}" "${_CACHE_VAR}")
993         if(${_CACHE_VAR})
994                 # message(STATUS "Using CXXFLAG: ${_FLAG}")
995                 set(${_CXXFLAGS} "${${_CXXFLAGS}} ${_FLAG}")
996         else()
997                 message(STATUS "Unsupported CXXFLAG: ${_FLAG}")
998         endif()
999 endmacro()
1000
1001 macro(get_blender_version)
1002         # So cmake depends on BKE_blender.h, beware of inf-loops!
1003         CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h
1004                        ${CMAKE_BINARY_DIR}/source/blender/blenkernel/BKE_blender.h.done)
1005
1006         file(STRINGS ${CMAKE_SOURCE_DIR}/source/blender/blenkernel/BKE_blender.h _contents REGEX "^#define[ \t]+BLENDER_.*$")
1007
1008         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION[ \t]+([0-9]+).*" "\\1" _out_version "${_contents}")
1009         string(REGEX REPLACE ".*#define[ \t]+BLENDER_SUBVERSION[ \t]+([0-9]+).*" "\\1" _out_subversion "${_contents}")
1010         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CHAR[ \t]+([a-z]+).*" "\\1" _out_version_char "${_contents}")
1011         string(REGEX REPLACE ".*#define[ \t]+BLENDER_VERSION_CYCLE[ \t]+([a-z]+).*" "\\1" _out_version_cycle "${_contents}")
1012
1013         if(NOT ${_out_version} MATCHES "[0-9]+")
1014                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION")
1015         endif()
1016
1017         if(NOT ${_out_subversion} MATCHES "[0-9]+")
1018                 message(FATAL_ERROR "Version parsing failed for BLENDER_SUBVERSION")
1019         endif()
1020
1021         # clumsy regex, only single char are ok but it could be unset
1022
1023         string(LENGTH "${_out_version_char}" _out_version_char_len)
1024         if(NOT _out_version_char_len EQUAL 1)
1025                 set(_out_version_char "")
1026         elseif(NOT ${_out_version_char} MATCHES "[a-z]+")
1027                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CHAR")
1028         endif()
1029
1030         if(NOT ${_out_version_cycle} MATCHES "[a-z]+")
1031                 message(FATAL_ERROR "Version parsing failed for BLENDER_VERSION_CYCLE")
1032         endif()
1033
1034         math(EXPR BLENDER_VERSION_MAJOR "${_out_version} / 100")
1035         math(EXPR BLENDER_VERSION_MINOR "${_out_version} % 100")
1036         set(BLENDER_VERSION "${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}")
1037
1038         set(BLENDER_SUBVERSION ${_out_subversion})
1039         set(BLENDER_VERSION_CHAR ${_out_version_char})
1040         set(BLENDER_VERSION_CYCLE ${_out_version_cycle})
1041
1042         # for packaging, alpha to numbers
1043         string(COMPARE EQUAL "${BLENDER_VERSION_CHAR}" "" _out_version_char_empty)
1044         if(${_out_version_char_empty})
1045                 set(BLENDER_VERSION_CHAR_INDEX "0")
1046         else()
1047                 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)
1048                 list(FIND _char_ls ${BLENDER_VERSION_CHAR} _out_version_char_index)
1049                 math(EXPR BLENDER_VERSION_CHAR_INDEX "${_out_version_char_index} + 1")
1050                 unset(_char_ls)
1051                 unset(_out_version_char_index)
1052         endif()
1053
1054         unset(_out_subversion)
1055         unset(_out_version_char)
1056         unset(_out_version_char_empty)
1057         unset(_out_version_cycle)
1058
1059         # message(STATUS "Version (Internal): ${BLENDER_VERSION}.${BLENDER_SUBVERSION}, Version (external): ${BLENDER_VERSION}${BLENDER_VERSION_CHAR}-${BLENDER_VERSION_CYCLE}")
1060 endmacro()
1061
1062
1063 # hacks to override initial project settings
1064 # these macros must be called directly before/after project(Blender)
1065 macro(blender_project_hack_pre)
1066         # ----------------
1067         # MINGW HACK START
1068         # ignore system set flag, use our own
1069         # must be before project(...)
1070         # if the user wants to add their own its ok after first run.
1071         if(DEFINED CMAKE_C_STANDARD_LIBRARIES)
1072                 set(_reset_standard_libraries OFF)
1073         else()
1074                 set(_reset_standard_libraries ON)
1075         endif()
1076
1077         # ------------------
1078         # GCC -O3 HACK START
1079         # needed because O3 can cause problems but
1080         # allow the builder to set O3 manually after.
1081         if(DEFINED CMAKE_C_FLAGS_RELEASE)
1082                 set(_reset_standard_cflags_rel OFF)
1083         else()
1084                 set(_reset_standard_cflags_rel ON)
1085         endif()
1086         if(DEFINED CMAKE_CXX_FLAGS_RELEASE)
1087                 set(_reset_standard_cxxflags_rel OFF)
1088         else()
1089                 set(_reset_standard_cxxflags_rel ON)
1090         endif()
1091 endmacro()
1092
1093
1094 macro(blender_project_hack_post)
1095         # --------------
1096         # MINGW HACK END
1097         if (_reset_standard_libraries)
1098                 # Must come after projecINCt(...)
1099                 #
1100                 # MINGW workaround for -ladvapi32 being included which surprisingly causes
1101                 # string formatting of floats, eg: printf("%.*f", 3, value). to crash blender
1102                 # with a meaningless stack trace. by overriding this flag we ensure we only
1103                 # have libs we define and that cmake & scons builds match.
1104                 set(CMAKE_C_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
1105                 set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "" FORCE)
1106                 mark_as_advanced(
1107                         CMAKE_C_STANDARD_LIBRARIES
1108                         CMAKE_CXX_STANDARD_LIBRARIES
1109                 )
1110         endif()
1111         unset(_reset_standard_libraries)
1112
1113
1114         # ----------------
1115         # GCC -O3 HACK END
1116         if(_reset_standard_cflags_rel)
1117                 string(REGEX REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
1118                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
1119                 mark_as_advanced(CMAKE_C_FLAGS_RELEASE)
1120         endif()
1121
1122         if(_reset_standard_cxxflags_rel)
1123                 string(REGEX REPLACE "-O3" "-O2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
1124                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
1125                 mark_as_advanced(CMAKE_CXX_FLAGS_RELEASE)
1126         endif()
1127
1128         unset(_reset_standard_cflags_rel)
1129         unset(_reset_standard_cxxflags_rel)
1130
1131         # ------------------------------------------------------------------
1132         # workaround for omission in cmake 2.8.4's GNU.cmake, fixed in 2.8.5
1133         if(CMAKE_COMPILER_IS_GNUCC)
1134                 if(NOT DARWIN)
1135                         set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
1136                 endif()
1137         endif()
1138
1139 endmacro()
1140
1141 # pair of macros to allow libraries to be specify files to install, but to
1142 # only install them at the end so the directories don't get cleared with
1143 # the files in them. used by cycles to install addon.
1144 macro(delayed_install
1145         base
1146         files
1147         destination)
1148
1149         foreach(f ${files})
1150                 if(IS_ABSOLUTE ${f})
1151                         set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${f})
1152                 else()
1153                         set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${base}/${f})
1154                 endif()
1155                 set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_DESTINATIONS ${destination})
1156         endforeach()
1157 endmacro()
1158
1159 # note this is a function instead of a macro so that ${BUILD_TYPE} in targetdir
1160 # does not get expanded in calling but is preserved
1161 function(delayed_do_install
1162         targetdir)
1163
1164         get_property(files GLOBAL PROPERTY DELAYED_INSTALL_FILES)
1165         get_property(destinations GLOBAL PROPERTY DELAYED_INSTALL_DESTINATIONS)
1166
1167         if(files)
1168                 list(LENGTH files n)
1169                 math(EXPR n "${n}-1")
1170
1171                 foreach(i RANGE ${n})
1172                         list(GET files ${i} f)
1173                         list(GET destinations ${i} d)
1174                         install(FILES ${f} DESTINATION ${targetdir}/${d})
1175                 endforeach()
1176         endif()
1177 endfunction()
1178
1179
1180 macro(data_to_c
1181       file_from file_to
1182       list_to_add)
1183
1184         list(APPEND ${list_to_add} ${file_to})
1185
1186         get_filename_component(_file_to_path ${file_to} PATH)
1187
1188         add_custom_command(
1189                 OUTPUT ${file_to}
1190                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1191                 COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${file_from} ${file_to}
1192                 DEPENDS ${file_from} datatoc)
1193
1194         set_source_files_properties(${file_to} PROPERTIES GENERATED TRUE)
1195
1196         unset(_file_to_path)
1197 endmacro()
1198
1199
1200 # same as above but generates the var name and output automatic.
1201 macro(data_to_c_simple
1202       file_from
1203       list_to_add)
1204
1205         # remove ../'s
1206         get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from}   REALPATH)
1207         get_filename_component(_file_to   ${CMAKE_CURRENT_BINARY_DIR}/${file_from}.c REALPATH)
1208
1209         list(APPEND ${list_to_add} ${_file_to})
1210
1211         get_filename_component(_file_to_path ${_file_to} PATH)
1212
1213         add_custom_command(
1214                 OUTPUT  ${_file_to}
1215                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1216                 COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${_file_from} ${_file_to}
1217                 DEPENDS ${_file_from} datatoc)
1218
1219         set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
1220
1221         unset(_file_from)
1222         unset(_file_to)
1223         unset(_file_to_path)
1224 endmacro()
1225
1226 # macro for converting pixmap directory to a png and then a c file
1227 macro(data_to_c_simple_icons
1228       path_from
1229       list_to_add
1230       )
1231
1232         # Conversion steps
1233         #  path_from  ->  _file_from  ->  _file_to
1234         #  foo/*.dat  ->  foo.png     ->  foo.png.c
1235
1236         get_filename_component(_path_from_abs ${path_from} ABSOLUTE)
1237         # remove ../'s
1238         get_filename_component(_file_from ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png   REALPATH)
1239         get_filename_component(_file_to   ${CMAKE_CURRENT_BINARY_DIR}/${path_from}.png.c REALPATH)
1240
1241         list(APPEND ${list_to_add} ${_file_to})
1242
1243         get_filename_component(_file_to_path ${_file_to} PATH)
1244
1245         # ideally we wouldn't glob, but storing all names for all pixmaps is a bit heavy
1246         file(GLOB _icon_files "${path_from}/*.dat")
1247
1248         add_custom_command(
1249                 OUTPUT  ${_file_from} ${_file_to}
1250                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1251                 #COMMAND python3 ${CMAKE_SOURCE_DIR}/source/blender/datatoc/datatoc_icon.py ${_path_from_abs} ${_file_from}
1252                 COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc_icon ${_path_from_abs} ${_file_from}
1253                 COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/datatoc ${_file_from} ${_file_to}
1254                 DEPENDS
1255                         ${_icon_files}
1256                         datatoc_icon
1257                         datatoc
1258                         # could be an arg but for now we only create icons depending on UI_icons.h
1259                         ${CMAKE_SOURCE_DIR}/source/blender/editors/include/UI_icons.h
1260                 )
1261
1262         set_source_files_properties(${_file_from} ${_file_to} PROPERTIES GENERATED TRUE)
1263
1264         unset(_path_from_abs)
1265         unset(_file_from)
1266         unset(_file_to)
1267         unset(_file_to_path)
1268         unset(_icon_files)
1269
1270 endmacro()
1271
1272 # XXX Not used for now...
1273 macro(svg_to_png
1274       file_from
1275       file_to
1276       dpi
1277       list_to_add)
1278
1279         # remove ../'s
1280         get_filename_component(_file_from ${CMAKE_CURRENT_SOURCE_DIR}/${file_from} REALPATH)
1281         get_filename_component(_file_to   ${CMAKE_CURRENT_SOURCE_DIR}/${file_to}   REALPATH)
1282
1283         list(APPEND ${list_to_add} ${_file_to})
1284
1285         find_program(INKSCAPE_EXE inkscape)
1286         mark_as_advanced(INKSCAPE_EXE)
1287
1288         if(INKSCAPE_EXE)
1289                 if(APPLE)
1290                         # in OS X app bundle, the binary is a shim that doesn't take any
1291                         # command line arguments, replace it with the actual binary
1292                         string(REPLACE "MacOS/Inkscape" "Resources/bin/inkscape" INKSCAPE_REAL_EXE ${INKSCAPE_EXE})
1293                         if(EXISTS "${INKSCAPE_REAL_EXE}")
1294                                 set(INKSCAPE_EXE ${INKSCAPE_REAL_EXE})
1295                         endif()
1296                 endif()
1297
1298                 add_custom_command(
1299                         OUTPUT  ${_file_to}
1300                         COMMAND ${INKSCAPE_EXE} ${_file_from} --export-dpi=${dpi}  --without-gui --export-png=${_file_to}
1301                         DEPENDS ${_file_from} ${INKSCAPE_EXE}
1302                 )
1303         else()
1304                 message(WARNING "Inkscape not found, could not re-generate ${_file_to} from ${_file_from}!")
1305         endif()
1306
1307         unset(_file_from)
1308         unset(_file_to)
1309
1310 endmacro()
1311
1312 macro(msgfmt_simple
1313       file_from
1314       list_to_add)
1315
1316         # remove ../'s
1317         get_filename_component(_file_from_we ${file_from} NAME_WE)
1318
1319         get_filename_component(_file_from ${file_from} REALPATH)
1320         get_filename_component(_file_to ${CMAKE_CURRENT_BINARY_DIR}/${_file_from_we}.mo REALPATH)
1321
1322         list(APPEND ${list_to_add} ${_file_to})
1323
1324         get_filename_component(_file_to_path ${_file_to} PATH)
1325
1326         add_custom_command(
1327                 OUTPUT  ${_file_to}
1328                 COMMAND ${CMAKE_COMMAND} -E make_directory ${_file_to_path}
1329                 COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/msgfmt ${_file_from} ${_file_to}
1330                 DEPENDS msgfmt ${_file_from})
1331
1332         set_source_files_properties(${_file_to} PROPERTIES GENERATED TRUE)
1333
1334         unset(_file_from_we)
1335         unset(_file_from)
1336         unset(_file_to)
1337         unset(_file_to_path)
1338 endmacro()
1339
1340 macro(find_python_package
1341       package)
1342
1343         string(TOUPPER ${package} _upper_package)
1344
1345         # set but invalid
1346         if((NOT ${PYTHON_${_upper_package}_PATH} STREQUAL "") AND
1347            (NOT ${PYTHON_${_upper_package}_PATH} MATCHES NOTFOUND))
1348 #               if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}/${package}")
1349 #                       message(WARNING "PYTHON_${_upper_package}_PATH is invalid, ${package} not found in '${PYTHON_${_upper_package}_PATH}' "
1350 #                                       "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
1351 #                       set(WITH_PYTHON_INSTALL${_upper_package} OFF)
1352 #               endif()
1353         # not set, so initialize
1354         else()
1355                 string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
1356                 list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
1357
1358                 # re-cache
1359                 unset(PYTHON_${_upper_package}_PATH CACHE)
1360                 find_path(PYTHON_${_upper_package}_PATH
1361                   NAMES
1362                     ${package}
1363                   HINTS
1364                     "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
1365                     "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
1366                   PATH_SUFFIXES
1367                     site-packages
1368                     dist-packages
1369                    NO_DEFAULT_PATH
1370                 )
1371
1372                  if(NOT EXISTS "${PYTHON_${_upper_package}_PATH}")
1373                         message(WARNING "'${package}' path could not be found in:\n"
1374                                         "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${package}', "
1375                                         "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/${package}', "
1376                                         "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/${package}', "
1377                                         "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/${package}', "
1378                                         "WITH_PYTHON_INSTALL_${_upper_package} option will be ignored when installing python")
1379                         set(WITH_PYTHON_INSTALL_${_upper_package} OFF)
1380                 else()
1381                         message(STATUS "${package} found at '${PYTHON_${_upper_package}_PATH}'")
1382                 endif()
1383
1384                 unset(_PY_VER_SPLIT)
1385                 unset(_PY_VER_MAJOR)
1386           endif()
1387
1388           unset(_upper_package)
1389 endmacro()