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