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