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