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