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