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