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