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