CMake: add WITH_LINKER_LLD option for unix platforms
[blender-staging.git] / source / creator / CMakeLists.txt
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 setup_libdirs()
22
23 blender_include_dirs(
24   ../../intern/clog
25   ../../intern/glew-mx
26   ../../intern/guardedalloc
27   ../blender/blenkernel
28   ../blender/blenlib
29   ../blender/blenloader
30   ../blender/depsgraph
31   ../blender/editors/include
32   ../blender/imbuf
33   ../blender/makesrna
34   ../blender/render/extern/include
35   ../blender/gpu
36   ../blender/makesdna
37   ../blender/windowmanager
38 )
39
40 set(LIB
41   bf_windowmanager
42 )
43
44 if(WITH_TBB)
45   # Force TBB libraries to be in front of MKL (part of OpenImageDenoise), so
46   # that it is initialized before MKL and static library initialization order
47   # issues are avoided.
48   #
49   # This isn't fully robust but seems to work.
50   list(INSERT LIB 0 ${TBB_LIBRARIES})
51   list(INSERT LIB 0 bf_blenkernel)
52 endif()
53
54 add_definitions(${GL_DEFINITIONS})
55 blender_include_dirs("${GLEW_INCLUDE_PATH}")
56
57 if(WIN32)
58   blender_include_dirs(../../intern/utfconv)
59 endif()
60
61 if(WITH_LIBMV)
62   blender_include_dirs(../../intern/libmv)
63   add_definitions(-DWITH_LIBMV)
64 endif()
65
66 if(WITH_CYCLES)
67   if(WITH_CYCLES_LOGGING)
68     blender_include_dirs(../../intern/cycles/blender)
69     add_definitions(-DWITH_CYCLES_LOGGING)
70   endif()
71 endif()
72
73 if(WITH_CODEC_FFMPEG)
74   add_definitions(-DWITH_FFMPEG)
75 endif()
76
77 if(WITH_TBB)
78   blender_include_dirs(${TBB_INCLUDE_DIRS})
79   link_directories(${LIBDIR}/tbb/lib)
80 endif()
81
82
83 if(WITH_PYTHON)
84   blender_include_dirs(../blender/python)
85   add_definitions(-DWITH_PYTHON)
86
87   if(WITH_PYTHON_SECURITY)
88     add_definitions(-DWITH_PYTHON_SECURITY)
89   endif()
90 endif()
91
92 if(WITH_HEADLESS)
93   add_definitions(-DWITH_HEADLESS)
94 endif()
95
96 if(WITH_SDL)
97   if(WITH_SDL_DYNLOAD)
98     blender_include_dirs(../../extern/sdlew/include)
99     add_definitions(-DWITH_SDL_DYNLOAD)
100   endif()
101   add_definitions(-DWITH_SDL)
102 endif()
103
104 if(WITH_BINRELOC)
105   blender_include_dirs(${BINRELOC_INCLUDE_DIRS})
106   add_definitions(-DWITH_BINRELOC)
107 endif()
108
109 if(WITH_FREESTYLE)
110   blender_include_dirs(../blender/freestyle)
111   add_definitions(-DWITH_FREESTYLE)
112 endif()
113
114 if(WITH_XR_OPENXR)
115   add_definitions(-DWITH_XR_OPENXR)
116 endif()
117
118 # Setup the exe sources and buildinfo
119 set(SRC
120   creator.c
121   creator_args.c
122   creator_signals.c
123
124   creator_intern.h
125 )
126
127 # MSVC 2010 gives linking errors with the manifest
128 if(WIN32 AND NOT UNIX)
129   string(SUBSTRING ${BLENDER_VERSION} 0 1 bver1)
130   string(SUBSTRING ${BLENDER_VERSION} 2 1 bver2)
131   string(SUBSTRING ${BLENDER_VERSION} 3 1 bver3)
132   add_definitions(
133     -DBLEN_VER_RC_STR="${BLENDER_VERSION}"
134     -DBLEN_VER_RC_1=${bver1}
135     -DBLEN_VER_RC_2=${bver2}
136     -DBLEN_VER_RC_3=${bver3}
137     -DBLEN_VER_RC_4=0
138   )
139
140
141   list(APPEND SRC
142     ${CMAKE_SOURCE_DIR}/release/windows/icons/winblender.rc
143     ${CMAKE_BINARY_DIR}/blender.exe.manifest
144   )
145 endif()
146
147 if(WITH_BUILDINFO)
148   add_definitions(-DWITH_BUILDINFO)
149   # --------------------------------------------------------------------------
150   # These defines could all be moved into the header below
151   string(REPLACE " " "\ " BUILDINFO_CFLAGS "${CMAKE_C_FLAGS}")
152   string(REPLACE " " "\ " BUILDINFO_CXXFLAGS "${CMAKE_CXX_FLAGS}")
153   string(REPLACE " " "\ " BUILDINFO_LINKFLAGS "${PLATFORM_LINKFLAGS}")
154   add_definitions(
155     # # define in header now, else these get out of date on rebuilds.
156     # -DBUILD_DATE="${BUILD_DATE}"
157     # -DBUILD_TIME="${BUILD_TIME}"
158     # -DBUILD_COMMIT_TIMESTAMP="${BUILD_COMMIT_TIMESTAMP}"
159     # -DBUILD_COMMIT_TIME="${BUILD_COMMIT_TIME}"
160     # -DBUILD_COMMIT_DATE="${BUILD_COMMIT_DATE}"
161     # -DBUILD_HASH="${BUILD_HASH}"
162     # -DBUILD_BRANCH="${BUILD_BRANCH}"
163     -DWITH_BUILDINFO_HEADER # alternative to lines above
164     -DBUILD_PLATFORM="${CMAKE_SYSTEM_NAME}"
165     -DBUILD_TYPE="${CMAKE_BUILD_TYPE}"
166     -DBUILD_CFLAGS="${BUILDINFO_CFLAGS}"
167     -DBUILD_CXXFLAGS="${BUILDINFO_CXXFLAGS}"
168     -DBUILD_LINKFLAGS="${BUILDINFO_LINKFLAGS}"
169     -DBUILD_SYSTEM="CMake"
170   )
171
172   # --------------------------------------------------------------------------
173   # write header for values that change each build
174   # note, generaed file is in build dir's source/creator
175   #       except when used as an include path.
176
177   # include the output directory, where the buildinfo.h file is generated
178   include_directories(${CMAKE_CURRENT_BINARY_DIR})
179
180
181   # XXX, ${buildinfo_h_fake} is used here,
182   # because we rely on that file being detected as missing
183   # every build so that the real header "buildinfo.h" is updated.
184   #
185   # Keep this until we find a better way to resolve!
186
187   set(buildinfo_h_real "${CMAKE_CURRENT_BINARY_DIR}/buildinfo.h")
188   set(buildinfo_h_fake "${CMAKE_CURRENT_BINARY_DIR}/buildinfo.h_fake")
189
190   if(EXISTS ${buildinfo_h_fake})
191     message(FATAL_ERROR "File \"${buildinfo_h_fake}\" found, this should never be created, remove!")
192   endif()
193
194   # a custom target that is always built
195   add_custom_target(buildinfo ALL
196     DEPENDS ${buildinfo_h_fake})
197
198   # creates buildinfo.h using cmake script
199   add_custom_command(
200     OUTPUT
201       ${buildinfo_h_fake}  # ensure we always run
202       ${buildinfo_h_real}
203     COMMAND ${CMAKE_COMMAND}
204     -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
205     # overrides only used when non-empty strings
206     -DBUILD_DATE=${BUILDINFO_OVERRIDE_DATE}
207     -DBUILD_TIME=${BUILDINFO_OVERRIDE_TIME}
208     -P ${CMAKE_SOURCE_DIR}/build_files/cmake/buildinfo.cmake)
209
210   # buildinfo.h is a generated file
211   set_source_files_properties(
212     ${buildinfo_h_real}
213     PROPERTIES GENERATED TRUE
214     HEADER_FILE_ONLY TRUE)
215
216   unset(buildinfo_h_real)
217   unset(buildinfo_h_fake)
218
219   # add deps below, after adding blender
220   # -------------- done with header values.
221
222   list(APPEND SRC
223     buildinfo.c
224   )
225
226   # make an object library so can load with it in tests
227   add_library(buildinfoobj OBJECT buildinfo.c)
228   add_dependencies(buildinfoobj buildinfo)
229 endif()
230
231 add_cc_flags_custom_test(blender)
232
233 # message(STATUS "Configuring blender")
234 if(WITH_PYTHON_MODULE)
235   add_definitions(-DWITH_PYTHON_MODULE)
236
237   # creates ./bin/bpy.so which can be imported as a python module.
238   #
239   # note that 'SHARED' works on Linux and Windows,
240   # but not OSX which _must_ be 'MODULE'
241   add_library(blender MODULE ${SRC})
242   set_target_properties(
243     blender
244     PROPERTIES
245       PREFIX ""
246       OUTPUT_NAME bpy
247       LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
248       RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin  # only needed on windows
249   )
250
251   if(APPLE)
252     set_target_properties(
253       blender
254       PROPERTIES
255         MACOSX_BUNDLE TRUE
256         LINK_FLAGS_RELEASE "${PLATFORM_LINKFLAGS}"
257         LINK_FLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG}"
258     )
259   endif()
260
261   if(WIN32)
262     # python modules use this
263     set_target_properties(
264       blender
265       PROPERTIES
266       SUFFIX ".pyd"
267     )
268   endif()
269
270 else()
271   add_executable(blender ${EXETYPE} ${SRC})
272 endif()
273
274 if(WITH_BUILDINFO)
275   # explicitly say that the executable depends on the buildinfo
276   add_dependencies(blender buildinfo)
277 endif()
278
279
280 set(BLENDER_TEXT_FILES
281   ${CMAKE_SOURCE_DIR}/release/text/GPL-license.txt
282   ${CMAKE_SOURCE_DIR}/release/text/GPL3-license.txt
283   ${CMAKE_SOURCE_DIR}/release/text/copyright.txt
284   # generate this file
285   # ${CMAKE_SOURCE_DIR}/release/text/readme.html
286   ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-bfont.ttf.txt
287 )
288
289 if(WITH_PYTHON)
290   list(APPEND BLENDER_TEXT_FILES
291     ${CMAKE_SOURCE_DIR}/release/text/Python-license.txt
292   )
293 endif()
294
295 if(WITH_OPENCOLORIO)
296   list(APPEND BLENDER_TEXT_FILES
297     ${CMAKE_SOURCE_DIR}/release/text/ocio-license.txt
298   )
299 endif()
300
301 if(WITH_MEM_JEMALLOC)
302   list(APPEND BLENDER_TEXT_FILES
303     ${CMAKE_SOURCE_DIR}/release/text/jemalloc-license.txt
304   )
305 endif()
306
307 list(APPEND BLENDER_TEXT_FILES
308   ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-droidsans.ttf.txt
309   ${CMAKE_SOURCE_DIR}/release/datafiles/LICENSE-bmonofont-i18n.ttf.txt
310 )
311
312
313 # -----------------------------------------------------------------------------
314 # Platform Specific Var: TARGETDIR_VER
315
316 if(UNIX AND NOT APPLE)
317   if(WITH_PYTHON_MODULE)
318     if(WITH_INSTALL_PORTABLE)
319       set(TARGETDIR_VER ${BLENDER_VERSION})
320     else()
321       set(TARGETDIR_VER ${PYTHON_SITE_PACKAGES}/${BLENDER_VERSION})
322     endif()
323   else()
324     if(WITH_INSTALL_PORTABLE)
325       set(TARGETDIR_VER ${BLENDER_VERSION})
326     else()
327       set(TARGETDIR_VER share/blender/${BLENDER_VERSION})
328     endif()
329   endif()
330
331 elseif(WIN32)
332   set(TARGETDIR_VER ${BLENDER_VERSION})
333
334 elseif(APPLE)
335   if(WITH_PYTHON_MODULE)
336     set(TARGETDIR_VER ${BLENDER_VERSION})
337   else()
338     set(TARGETDIR_VER Blender.app/Contents/Resources/${BLENDER_VERSION})
339   endif()
340   # Skip relinking on cpack / install
341   set_target_properties(blender PROPERTIES BUILD_WITH_INSTALL_RPATH true)
342 endif()
343
344
345 # -----------------------------------------------------------------------------
346 # Install Targets (Generic, All Platforms)
347
348
349 # important to make a clean  install each time, else old scripts get loaded.
350 install(
351   CODE
352   "file(REMOVE_RECURSE ${TARGETDIR_VER})"
353 )
354
355 if(WITH_PYTHON)
356   # install(CODE "message(\"copying blender scripts...\")")
357
358   # exclude addons_contrib if release
359   if("${BLENDER_VERSION_CYCLE}" STREQUAL "release" OR
360      "${BLENDER_VERSION_CYCLE}" STREQUAL "rc")
361     set(ADDON_EXCLUDE_CONDITIONAL "addons_contrib/*")
362   else()
363     set(ADDON_EXCLUDE_CONDITIONAL "_addons_contrib/*")  # dummy, wont do anything
364   endif()
365
366   # do not install freestyle dir if disabled
367   if(NOT WITH_FREESTYLE)
368     set(FREESTYLE_EXCLUDE_CONDITIONAL "freestyle/*")
369   else()
370     set(FREESTYLE_EXCLUDE_CONDITIONAL "_freestyle/*")  # dummy, wont do anything
371   endif()
372
373   install(
374     DIRECTORY ${CMAKE_SOURCE_DIR}/release/scripts
375     DESTINATION ${TARGETDIR_VER}
376     PATTERN ".git" EXCLUDE
377     PATTERN ".gitignore" EXCLUDE
378     PATTERN ".arcconfig" EXCLUDE
379     PATTERN "__pycache__" EXCLUDE
380     PATTERN "${ADDON_EXCLUDE_CONDITIONAL}" EXCLUDE
381     PATTERN "${FREESTYLE_EXCLUDE_CONDITIONAL}" EXCLUDE
382   )
383
384   unset(ADDON_EXCLUDE_CONDITIONAL)
385   unset(FREESTYLE_EXCLUDE_CONDITIONAL)
386 endif()
387
388 # fonts
389 install(
390   DIRECTORY
391     ${CMAKE_SOURCE_DIR}/release/datafiles/fonts
392   DESTINATION ${TARGETDIR_VER}/datafiles
393 )
394
395 # localization
396 if(WITH_INTERNATIONAL)
397   set(_locale_dir "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
398   set(_locale_target_dir ${TARGETDIR_VER}/datafiles/locale)
399
400   file(GLOB _po_files "${_locale_dir}/po/*.po")
401   foreach(_po_file ${_po_files})
402     msgfmt_simple(${_po_file} _all_mo_files)
403   endforeach()
404
405   # Create a custom target which will compile all po to mo
406   add_custom_target(
407     locales
408     DEPENDS ${_all_mo_files})
409
410   add_dependencies(blender locales)
411
412   # Generate INSTALL rules
413   install(
414     FILES ${_locale_dir}/languages
415     DESTINATION ${_locale_target_dir}
416   )
417
418   foreach(_mo_file ${_all_mo_files})
419     get_filename_component(_locale_name ${_mo_file} NAME_WE)
420     install(
421       FILES ${_mo_file}
422       DESTINATION ${_locale_target_dir}/${_locale_name}/LC_MESSAGES
423       RENAME blender.mo
424     )
425     unset(_locale_name)
426   endforeach()
427
428   unset(_all_mo_files)
429   unset(_po_files)
430   unset(_po_file)
431   unset(_mo_file)
432   unset(_locale_target_dir)
433
434   unset(_locale_dir)
435 endif()
436
437 # color management
438 if(WITH_OPENCOLORIO)
439   install(
440     DIRECTORY ${CMAKE_SOURCE_DIR}/release/datafiles/colormanagement
441     DESTINATION ${TARGETDIR_VER}/datafiles
442   )
443 endif()
444
445 # helpful tip when using make
446 if("${CMAKE_GENERATOR}" MATCHES ".*Makefiles.*")
447   # message after building.
448   add_custom_command(
449     TARGET blender POST_BUILD MAIN_DEPENDENCY blender
450     COMMAND ${CMAKE_COMMAND} -E
451             echo 'now run: \"make install\" to copy runtime files and scripts to ${TARGETDIR_VER}'
452   )
453 endif()
454
455
456 # -----------------------------------------------------------------------------
457 # Install Targets (Platform Specific)
458
459 if(UNIX AND NOT APPLE)
460
461   if(NOT WITH_PYTHON_MODULE)
462     if(WITH_DOC_MANPAGE)
463       add_custom_target(
464         blender_man_page ALL
465         COMMAND ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1.py
466                 ${EXECUTABLE_OUTPUT_PATH}/blender
467                 ${CMAKE_CURRENT_BINARY_DIR}/blender.1)
468       add_dependencies(blender_man_page blender)
469     endif()
470   endif()
471
472   # there are a few differences between portable and system install
473   if(WITH_PYTHON_MODULE)
474     if(WITH_INSTALL_PORTABLE)
475       install(
476         TARGETS blender
477         DESTINATION "."
478       )
479     else()
480       install(
481         TARGETS blender
482         LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}
483       )
484     endif()
485     # none of the other files are needed currently
486   elseif(WITH_INSTALL_PORTABLE)
487     install(
488       TARGETS blender
489       DESTINATION "."
490     )
491
492     if(WITH_DOC_MANPAGE)
493       install(
494         FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
495         DESTINATION "."
496       )
497     endif()
498     install(
499       FILES
500         ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
501         ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
502         ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/symbolic/apps/blender-symbolic.svg
503       DESTINATION "."
504     )
505
506     install(
507       PROGRAMS
508       ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
509       DESTINATION "."
510     )
511
512     if(EXISTS ${LIBDIR}/mesa)
513       install(DIRECTORY ${LIBDIR}/mesa/lib DESTINATION ".")
514
515       install(
516         PROGRAMS
517         ${CMAKE_SOURCE_DIR}/release/bin/blender-softwaregl
518         DESTINATION "."
519       )
520     endif()
521
522     set(BLENDER_TEXT_FILES_DESTINATION ".")
523   else()
524     # main blender binary
525     install(
526       TARGETS blender
527       DESTINATION bin
528     )
529     if(WITH_DOC_MANPAGE)
530       # manpage only with 'blender' binary
531       install(
532         FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
533         DESTINATION share/man/man1
534       )
535     endif()
536
537     # misc files
538     install(
539       FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
540       DESTINATION share/applications
541     )
542     install(
543       FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
544       DESTINATION share/icons/hicolor/scalable/apps
545     )
546     install(
547       FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/symbolic/apps/blender-symbolic.svg
548       DESTINATION share/icons/hicolor/symbolic/apps
549     )
550     install(
551       PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
552       DESTINATION bin
553     )
554     set(BLENDER_TEXT_FILES_DESTINATION share/doc/blender)
555   endif()
556
557   if(WITH_PYTHON)
558     if(WITH_PYTHON_INSTALL)
559
560       install(
561         PROGRAMS ${PYTHON_EXECUTABLE}
562         DESTINATION ${TARGETDIR_VER}/python/bin
563       )
564
565       # on some platforms (like openSUSE) Python is linked
566       # to be used from lib64 folder.
567       # determine this from Python's libraries path
568       #
569       # ugh, its possible 'lib64' is just a symlink to 'lib' which causes incorrect use of 'lib64'
570       get_filename_component(_pypath_real ${PYTHON_LIBPATH} REALPATH)
571       if(${_pypath_real} MATCHES "lib64$")
572         set(_target_LIB "lib64")
573       else()
574         set(_target_LIB "lib")
575       endif()
576       unset(_pypath_real)
577
578       # Copy the systems python into the install directory
579       # install(CODE "message(\"copying a subset of the systems python...\")")
580       install(
581         DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
582         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
583         PATTERN "__pycache__" EXCLUDE               # * any cache *
584         PATTERN "config-${PYTHON_VERSION}m/*.a" EXCLUDE  # static lib
585         PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
586         PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
587         PATTERN "tkinter" EXCLUDE                   # ./tkinter
588         PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
589         PATTERN "idlelib" EXCLUDE                   # ./idlelib
590         PATTERN "test" EXCLUDE                      # ./test
591         PATTERN "turtledemo" EXCLUDE                # ./turtledemo
592         PATTERN "turtle.py" EXCLUDE                 # ./turtle.py
593         PATTERN "wininst*.exe" EXCLUDE              # from distutils, avoid malware false positive
594       )
595
596       # Needed for distutils/pip
597       # get the last part of the include dir, will be 'python{version}{abiflag}',
598       get_filename_component(_py_inc_suffix ${PYTHON_INCLUDE_DIR} NAME)
599       install(
600         FILES ${PYTHON_INCLUDE_DIR}/pyconfig.h
601         DESTINATION ${TARGETDIR_VER}/python/include/${_py_inc_suffix}
602       )
603       unset(_py_inc_suffix)
604
605       if(WITH_PYTHON_INSTALL_NUMPY)
606         # Install to the same directory as the source, so debian-like
607         # distros are happy with their policy.
608         set(_suffix "site-packages")
609         if(${PYTHON_NUMPY_PATH} MATCHES "dist-packages")
610           set(_suffix "dist-packages")
611         endif()
612         install(
613           DIRECTORY ${PYTHON_NUMPY_PATH}/numpy
614           DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
615           PATTERN ".svn" EXCLUDE
616           PATTERN "__pycache__" EXCLUDE           # * any cache *
617           PATTERN "*.pyc" EXCLUDE                 # * any cache *
618           PATTERN "*.pyo" EXCLUDE                 # * any cache *
619           PATTERN "oldnumeric" EXCLUDE            # ./oldnumeric
620           PATTERN "doc" EXCLUDE                   # ./doc
621           PATTERN "tests" EXCLUDE                 # ./tests
622           PATTERN "f2py" EXCLUDE                  # ./f2py - fortran/python interface code, not for blender.
623           PATTERN "include" EXCLUDE               # include dirs all over, we wont use NumPy/CAPI
624           PATTERN "*.h" EXCLUDE                   # some includes are not in include dirs
625           PATTERN "*.a" EXCLUDE                   # ./core/lib/libnpymath.a - for linking, we dont need.
626         )
627         unset(_suffix)
628       endif()
629
630       # Copy requests, we need to generalize site-packages
631       if(WITH_PYTHON_INSTALL_REQUESTS)
632         set(_suffix "site-packages")
633         if(${PYTHON_REQUESTS_PATH} MATCHES "dist-packages")
634           set(_suffix "dist-packages")
635         endif()
636         install(
637           DIRECTORY ${PYTHON_REQUESTS_PATH}/requests
638           DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
639           PATTERN ".svn" EXCLUDE
640           PATTERN "__pycache__" EXCLUDE           # * any cache *
641           PATTERN "*.pyc" EXCLUDE                 # * any cache *
642           PATTERN "*.pyo" EXCLUDE                 # * any cache *
643         )
644         # On some platforms requests does have extra dependencies.
645         set(_requests_deps "certifi" "chardet" "idna" "urllib3")
646         foreach(_requests_dep ${_requests_deps})
647           if(EXISTS ${PYTHON_REQUESTS_PATH}/${_requests_dep})
648             install(
649               DIRECTORY ${PYTHON_REQUESTS_PATH}/${_requests_dep}
650               DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
651               PATTERN ".svn" EXCLUDE
652               PATTERN "__pycache__" EXCLUDE           # * any cache *
653               PATTERN "*.pyc" EXCLUDE                 # * any cache *
654               PATTERN "*.pyo" EXCLUDE                 # * any cache *
655             )
656           endif()
657         endforeach()
658         if(EXISTS ${PYTHON_REQUESTS_PATH}/six.py)
659           install(
660             FILES ${PYTHON_REQUESTS_PATH}/six.py
661             DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
662           )
663         endif()
664         unset(_requests_dep)
665         unset(_requests_deps)
666         unset(_suffix)
667       endif()
668       unset(_target_LIB)
669
670     endif()
671   endif()
672
673   if(WITH_DRACO)
674     install(
675       PROGRAMS $<TARGET_FILE:extern_draco>
676       DESTINATION ${TARGETDIR_VER}/python/lib/python${PYTHON_VERSION}/site-packages
677     )
678   endif()
679 elseif(WIN32)
680
681   set(BLENDER_TEXT_FILES_DESTINATION ".")
682
683   if(WITH_OPENMP AND MSVC_CLANG)
684     install(
685           FILES ${CLANG_OPENMP_DLL}
686           DESTINATION "."
687     )
688   endif()
689
690   if(WITH_PYTHON)
691     string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
692
693     if(NOT CMAKE_COMPILER_IS_GNUCC)
694       install(
695         FILES ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python${_PYTHON_VERSION_NO_DOTS}.dll
696               ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python3.dll
697         DESTINATION "."
698         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
699       )
700
701       install(
702         FILES ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python${_PYTHON_VERSION_NO_DOTS}_d.dll
703               ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python3_d.dll
704         DESTINATION "."
705         CONFIGURATIONS Debug
706       )
707     endif()
708
709     if(WITH_PYTHON_INSTALL)
710       # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
711
712       install(DIRECTORY DESTINATION ${TARGETDIR_VER}/python)
713       install(DIRECTORY DESTINATION ${TARGETDIR_VER}/python/lib)
714
715       install(
716         DIRECTORY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/lib
717         DESTINATION ${BLENDER_VERSION}/python/
718         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
719         PATTERN ".svn" EXCLUDE
720         PATTERN "*_d.*" EXCLUDE                  # * debug libraries *
721         PATTERN "__pycache__" EXCLUDE           # * any cache *
722         PATTERN "*.pyc" EXCLUDE                 # * any cache *
723         PATTERN "*.pyo" EXCLUDE                 # * any cache *
724       )
725
726        install(
727         DIRECTORY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/lib
728         DESTINATION ${BLENDER_VERSION}/python/
729         CONFIGURATIONS Debug
730         PATTERN ".svn" EXCLUDE
731         PATTERN "__pycache__" EXCLUDE           # * any cache *
732         PATTERN "*.pyc" EXCLUDE                 # * any cache *
733         PATTERN "*.pyo" EXCLUDE                 # * any cache *)
734
735       )
736
737       install(
738         DIRECTORY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/DLLs
739         DESTINATION ${BLENDER_VERSION}/python
740         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
741         PATTERN "*.pdb" EXCLUDE
742         PATTERN "*_d.*" EXCLUDE
743       )
744
745       install(
746         DIRECTORY ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/DLLs
747         DESTINATION ${BLENDER_VERSION}/python
748         CONFIGURATIONS Debug
749       )
750
751       install(
752         FILES ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python${_PYTHON_VERSION_NO_DOTS}.dll
753               ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python.exe
754         DESTINATION ${BLENDER_VERSION}/python/bin
755         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
756       )
757       install(
758         FILES ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python${_PYTHON_VERSION_NO_DOTS}_d.dll
759               ${LIBDIR}/python/${_PYTHON_VERSION_NO_DOTS}/bin/python_d.exe
760         DESTINATION ${BLENDER_VERSION}/python/bin
761         CONFIGURATIONS Debug
762       )
763
764       if(WINDOWS_PYTHON_DEBUG)
765         install(
766           FILES ${LIBDIR}/python/37/libs/python${_PYTHON_VERSION_NO_DOTS}.pdb
767           DESTINATION "."
768           CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
769         )
770
771         install(
772           FILES ${LIBDIR}/python/37/libs/python${_PYTHON_VERSION_NO_DOTS}_d.pdb
773           DESTINATION "."
774           CONFIGURATIONS Debug
775         )
776       endif()
777     endif()
778
779     unset(_PYTHON_VERSION_NO_DOTS)
780   endif()
781
782   # EGL Runtime Components
783   if(WITH_GL_EGL)
784     if(WIN32)
785       install(FILES "${OPENGLES_DLL}"     DESTINATION ".")
786       install(FILES "${OPENGLES_EGL_DLL}" DESTINATION ".")
787
788       if(WITH_GL_ANGLE)
789         install(FILES "${D3DCOMPILER_DLL}" DESTINATION ".")
790       endif()
791     endif()
792   endif()
793
794   if(WITH_CODEC_FFMPEG)
795     install(
796       FILES
797         ${LIBDIR}/ffmpeg/lib/avcodec-58.dll
798         ${LIBDIR}/ffmpeg/lib/avformat-58.dll
799         ${LIBDIR}/ffmpeg/lib/avdevice-58.dll
800         ${LIBDIR}/ffmpeg/lib/avutil-56.dll
801         ${LIBDIR}/ffmpeg/lib/swscale-5.dll
802         ${LIBDIR}/ffmpeg/lib/swresample-3.dll
803       DESTINATION "."
804     )
805   endif()
806
807   if(WITH_TBB_MALLOC_PROXY)
808     install(
809       FILES
810         ${LIBDIR}/tbb/lib/tbbmalloc.dll
811         ${LIBDIR}/tbb/lib/tbbmalloc_proxy.dll
812       DESTINATION "."
813       CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
814     )
815     install(
816       FILES
817         ${LIBDIR}/tbb/lib/debug/tbbmalloc.dll
818         ${LIBDIR}/tbb/lib/debug/tbbmalloc_proxy.dll
819       DESTINATION "."
820       CONFIGURATIONS Debug
821     )
822   endif()
823
824   if(WITH_CODEC_SNDFILE)
825     install(
826       FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
827       DESTINATION "."
828     )
829   endif()
830
831   if(WITH_OPENAL)
832     install(
833       FILES
834         ${LIBDIR}/openal/lib/OpenAL32.dll
835       DESTINATION "."
836     )
837   endif()
838
839   if(WITH_SDL)
840     install(
841       FILES ${LIBDIR}/sdl/lib/SDL2.dll
842       DESTINATION "."
843     )
844   endif()
845
846   if(WITH_SYSTEM_AUDASPACE)
847     install(
848       FILES
849         ${LIBDIR}/audaspace/lib/audaspace.dll
850         ${LIBDIR}/audaspace/lib/audaspace-c.dll
851         ${LIBDIR}/audaspace/lib/audaspace-py.dll
852       DESTINATION "."
853     )
854   endif()
855
856   install(
857     FILES
858       ${CMAKE_SOURCE_DIR}/release/windows/batch/blender_debug_gpu.cmd
859       ${CMAKE_SOURCE_DIR}/release/windows/batch/blender_debug_gpu_glitchworkaround.cmd
860       ${CMAKE_SOURCE_DIR}/release/windows/batch/blender_debug_log.cmd
861       ${CMAKE_SOURCE_DIR}/release/windows/batch/blender_factory_startup.cmd
862       ${CMAKE_SOURCE_DIR}/release/windows/batch/blender_oculus.cmd
863       ${CMAKE_SOURCE_DIR}/release/windows/batch/oculus.json
864     DESTINATION "."
865   )
866
867   if(WITH_DRACO)
868     install(
869       PROGRAMS $<TARGET_FILE:extern_draco>
870       DESTINATION ${TARGETDIR_VER}/python/lib/site-packages
871     )
872   endif()
873 elseif(APPLE)
874   if(NOT WITH_PYTHON_MODULE)
875     # Uppercase name for app bundle
876     set_target_properties(blender PROPERTIES OUTPUT_NAME Blender)
877   endif()
878
879   # handy install macro to exclude files, we use \$ escape for the "to"
880   # argument when calling so ${BUILD_TYPE} does not get expanded
881   macro(install_dir from to)
882     install(
883       DIRECTORY ${from}
884       DESTINATION ${to}
885       PATTERN ".git" EXCLUDE
886       PATTERN ".svn" EXCLUDE
887       PATTERN "*.pyc" EXCLUDE
888       PATTERN "*.pyo" EXCLUDE
889       PATTERN "*.orig" EXCLUDE
890       PATTERN "*.rej" EXCLUDE
891       PATTERN "__pycache__" EXCLUDE
892       PATTERN "__MACOSX" EXCLUDE
893       PATTERN ".DS_Store" EXCLUDE
894       PATTERN "config-${PYTHON_VERSION}m/*.a" EXCLUDE  # static lib
895       PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
896       PATTERN "tkinter" EXCLUDE                   # ./tkinter
897       PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
898       PATTERN "idlelib" EXCLUDE                   # ./idlelib
899       PATTERN "test" EXCLUDE                      # ./test
900       PATTERN "turtledemo" EXCLUDE                # ./turtledemo
901       PATTERN "turtle.py" EXCLUDE                 # ./turtle.py
902       PATTERN "wininst*.exe" EXCLUDE              # from distutils, avoid malware false positive
903     )
904   endmacro()
905
906   set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/Blender.app)
907
908   # setup Info.plist
909   execute_process(COMMAND date "+%Y-%m-%d"
910                   OUTPUT_VARIABLE BLENDER_DATE
911                   OUTPUT_STRIP_TRAILING_WHITESPACE)
912
913   set_target_properties(blender PROPERTIES
914     MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
915     MACOSX_BUNDLE_SHORT_VERSION_STRING "${BLENDER_VERSION}${BLENDER_VERSION_CHAR}"
916     MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION}${BLENDER_VERSION_CHAR} ${BLENDER_DATE}")
917
918   # Gather the date in finder-style
919   execute_process(COMMAND date "+%m/%d/%Y/%H:%M"
920   OUTPUT_VARIABLE SETFILE_DATE
921   OUTPUT_STRIP_TRAILING_WHITESPACE)
922
923   # Give the bundle actual creation/modification date
924   #
925   # Note that the directory might not yet exist, which happens when CMake is first run.
926   if(NOT EXISTS ${EXECUTABLE_OUTPUT_PATH}/Blender.app)
927     file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/Blender.app)
928   endif()
929   execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE}
930                   ${EXECUTABLE_OUTPUT_PATH}/Blender.app)
931
932   install(
933     TARGETS blender
934     DESTINATION "."
935   )
936
937   # install release and app files
938   set(BLENDER_TEXT_FILES_DESTINATION Blender.app/Contents/Resources/text)
939
940   install(
941     FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
942     DESTINATION Blender.app/Contents
943   )
944
945   install_dir(
946     ${OSX_APP_SOURCEDIR}/Contents/Resources
947     Blender.app/Contents/
948   )
949
950   if(WITH_OPENMP AND OPENMP_CUSTOM)
951     install(
952       FILES ${LIBDIR}/openmp/lib/libomp.dylib
953       DESTINATION Blender.app/Contents/Resources/lib
954     )
955   endif()
956
957   if(WITH_LLVM AND NOT LLVM_STATIC)
958     install(
959       FILES ${LIBDIR}/llvm/lib/libLLVM-3.4.dylib
960       DESTINATION Blender.app/Contents/MacOS
961     )
962   endif()
963
964   # python
965   if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
966     # Copy the python libs into the install directory
967     install_dir(
968       ${PYTHON_LIBPATH}
969       ${TARGETDIR_VER}/python/lib
970     )
971
972     install(DIRECTORY ${LIBDIR}/python/bin
973       DESTINATION ${TARGETDIR_VER}/python
974       USE_SOURCE_PERMISSIONS
975     )
976
977     # Needed for distutils/pip
978     # get the last part of the include dir, will be 'python{version}{abiflag}',
979     get_filename_component(_py_inc_suffix ${PYTHON_INCLUDE_DIR} NAME)
980     install(
981       FILES ${PYTHON_INCLUDE_DIR}/pyconfig.h
982       DESTINATION ${TARGETDIR_VER}/python/include/${_py_inc_suffix}
983     )
984     unset(_py_inc_suffix)
985   endif()
986
987   if(WITH_DRACO)
988     install(
989       PROGRAMS $<TARGET_FILE:extern_draco>
990       DESTINATION ${TARGETDIR_VER}/python/lib/python${PYTHON_VERSION}/site-packages
991     )
992   endif()
993 endif()
994
995 # -----------------------------------------------------------------------------
996 # Generic Install, for all targets
997
998 if(DEFINED BLENDER_TEXT_FILES_DESTINATION)
999
1000   install(
1001     CODE
1002     "
1003     file(READ \"${CMAKE_SOURCE_DIR}/release/text/readme.html\" DATA_SRC)
1004     string(REGEX REPLACE \"BLENDER_VERSION\" \"${BLENDER_VERSION}\" DATA_DST \"\${DATA_SRC}\")
1005     file(WRITE \"${CMAKE_BINARY_DIR}/release/text/readme.html\" \"\${DATA_DST}\")
1006     unset(DATA_SRC)
1007     unset(DATA_DST)
1008     "
1009   )
1010   list(APPEND BLENDER_TEXT_FILES
1011     ${CMAKE_BINARY_DIR}/release/text/readme.html
1012   )
1013
1014   install(
1015     FILES ${BLENDER_TEXT_FILES}
1016     DESTINATION "${BLENDER_TEXT_FILES_DESTINATION}"
1017   )
1018 endif()
1019
1020 # install more files specified elsewhere
1021 delayed_do_install(${TARGETDIR_VER})
1022
1023 unset(BLENDER_TEXT_FILES)
1024 unset(BLENDER_TEXT_FILES_DESTINATION)
1025
1026
1027 # -----------------------------------------------------------------------------
1028 # Geometry Icons
1029
1030 # Geometry icons.
1031 get_property(_icon_names GLOBAL PROPERTY ICON_GEOM_NAMES)
1032 set(_icon_files)
1033 foreach(_f ${_icon_names})
1034   list(APPEND _icon_files
1035     "${CMAKE_SOURCE_DIR}/release/datafiles/icons/${_f}.dat"
1036   )
1037 endforeach()
1038 install(
1039   FILES ${_icon_files}
1040   DESTINATION ${TARGETDIR_VER}/datafiles/icons
1041 )
1042
1043 unset(_icon_names)
1044 unset(_icon_files)
1045 unset(_f)
1046
1047 # -----------------------------------------------------------------------------
1048 # Studio Lights
1049 install(
1050   DIRECTORY
1051     ${CMAKE_SOURCE_DIR}/release/datafiles/studiolights
1052   DESTINATION ${TARGETDIR_VER}/datafiles
1053 )
1054
1055 # -----------------------------------------------------------------------------
1056 # Setup link libs
1057
1058 add_dependencies(blender makesdna)
1059 target_link_libraries(blender ${LIB})
1060 unset(LIB)
1061
1062 setup_liblinks(blender)
1063
1064 if(APPLE)
1065   set_target_properties(blender PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/osx_locals.map)
1066 elseif(UNIX)
1067   set_target_properties(blender PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/blender.map)
1068 endif()
1069
1070 # -----------------------------------------------------------------------------
1071 # USD registry.
1072 # USD requires a set of JSON files that define the standard schemas. These
1073 # files are required at runtime.
1074 if(WITH_USD)
1075   add_definitions(-DWITH_USD)
1076   install(DIRECTORY
1077     ${USD_LIBRARY_DIR}/usd
1078     DESTINATION "${TARGETDIR_VER}/datafiles"
1079   )
1080 endif()
1081
1082
1083 # vcpkg substitutes our libs with theirs, which will cause issues when you
1084 # you run these builds on other systems due to missing dlls. So we opt out
1085 # the use of vcpkg
1086 if(WIN32)
1087   set_target_properties(blender PROPERTIES VS_GLOBAL_VcpkgEnabled "false")
1088 endif()
1089
1090 # -----------------------------------------------------------------------------
1091 # Setup launcher
1092
1093 if(WIN32 AND NOT WITH_PYTHON_MODULE)
1094   install(
1095     TARGETS blender
1096     COMPONENT Blender
1097     DESTINATION "."
1098   )
1099   set_target_properties(
1100     blender
1101     PROPERTIES
1102       VS_USER_PROPS "blender.Cpp.user.props"
1103   )
1104 endif()
1105
1106 # -----------------------------------------------------------------------------
1107 # Post-install script
1108
1109 if(POSTINSTALL_SCRIPT)
1110   install(SCRIPT ${POSTINSTALL_SCRIPT})
1111 endif()