CMake: fix for MSVC, installing Python
[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                         # extract python
632                         install(
633                                 CODE
634                                 "
635                                 if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
636                                         set(PYTHON_ZIP ${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_d.tar.gz)
637                                 else()
638                                         set(PYTHON_ZIP ${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}.tar.gz)
639                                 endif()
640
641                                 execute_process(
642                                         COMMAND ${CMAKE_COMMAND} -E
643                                                 make_directory \"${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib\"
644                                         COMMAND ${CMAKE_COMMAND} -E
645                                                 tar xzfv \"\${PYTHON_ZIP} -C ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib\"
646                                 )
647                                 unset(PYTHON_ZIP)
648                                 "
649                         )
650                         # install python
651                         install(
652                                 DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib
653                                 DESTINATION ${BLENDER_VERSION}/python
654                                 PATTERN 'site-packages/*' EXCLUDE
655                         )
656
657                         # release/site-packages
658                         install(
659                                 DIRECTORY ${LIBDIR}/release/site-packages
660                                 DESTINATION ${BLENDER_VERSION}/python/lib
661                                 PATTERN ".svn" EXCLUDE
662                                 PATTERN "__pycache__" EXCLUDE           # * any cache *
663                                 PATTERN "*.pyc" EXCLUDE                 # * any cache *
664                                 PATTERN "*.pyo" EXCLUDE                 # * any cache *)
665                         )
666
667                         if(WITH_PYTHON_INSTALL_NUMPY)
668                                 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages/numpy
669                                         COMMAND ${CMAKE_COMMAND} -E tar xzvf "${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.8.tar.gz"
670                                         DEPENDS ${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.8.tar.gz
671                                         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages)
672                                 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages/numpy
673                                                 DESTINATION ${BLENDER_VERSION}/python/lib/site-packages)
674                         endif()
675
676                 endif()
677
678                 unset(_PYTHON_VERSION_NO_DOTS)
679         endif()
680
681         # EGL Runtime Components
682         if(WITH_GL_EGL)
683                 if(WIN32)
684                         install(FILES "${OPENGLES_DLL}"     DESTINATION ".")
685                         install(FILES "${OPENGLES_EGL_DLL}" DESTINATION ".")
686
687                         if(WITH_GL_ANGLE)
688                                 install(FILES "${D3DCOMPILER_DLL}" DESTINATION ".")
689                         endif()
690                 endif()
691         endif()
692
693         if(MSVC)
694                 install(
695                         FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll
696                         DESTINATION "."
697                 )
698         else()
699                 #MinGW64 comes with own version. For portable builds it will probaly have to be copied to work
700                 if(NOT WITH_MINGW64)
701                         install(
702                                 FILES ${LIBDIR}/pthreads/lib/pthreadGC2.dll
703                                 DESTINATION "."
704                         )
705                 elseif(WITH_MINGW64)
706                         install(
707                                 FILES 
708                                         ${LIBDIR}/binaries/libgcc_s_sjlj-1.dll
709                                         ${LIBDIR}/binaries/libwinpthread-1.dll
710                                         ${LIBDIR}/binaries/libstdc++-6.dll
711                                 DESTINATION "."
712                         )
713                         
714                         if(WITH_OPENMP)
715                                 install(
716                                         FILES 
717                                         ${LIBDIR}/binaries/libgomp-1.dll
718                                         DESTINATION "."
719                                 )
720                         endif()
721                 endif()
722         endif()
723
724         if(WITH_CODEC_FFMPEG)
725                 if(WITH_MINGW64)
726                         install(
727                                 FILES
728                                         ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
729                                         ${LIBDIR}/ffmpeg/lib/avformat-53.dll
730                                         ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
731                                         ${LIBDIR}/ffmpeg/lib/avutil-51.dll
732                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
733                                         ${LIBDIR}/ffmpeg/lib/swresample-0.dll
734                                         ${LIBDIR}/ffmpeg/lib/xvidcore.dll
735                                 DESTINATION "."
736                         )
737                 else()
738                         install(
739                                 FILES
740                                         ${LIBDIR}/ffmpeg/lib/avcodec-55.dll
741                                         ${LIBDIR}/ffmpeg/lib/avformat-55.dll
742                                         ${LIBDIR}/ffmpeg/lib/avdevice-55.dll
743                                         ${LIBDIR}/ffmpeg/lib/avutil-52.dll
744                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
745                                 DESTINATION "."
746                         )
747                 endif()
748         endif()
749
750         if(WITH_CODEC_SNDFILE)
751                 install(
752                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
753                         DESTINATION "."
754                 )
755         endif()
756
757         if(WITH_OPENAL)
758                 install(
759                         FILES
760                                 ${LIBDIR}/openal/lib/OpenAL32.dll
761                                 ${LIBDIR}/openal/lib/wrap_oal.dll
762                         DESTINATION "."
763                 )
764         endif()
765
766         if(WITH_SDL)
767                 install(
768                         FILES ${LIBDIR}/sdl/lib/SDL2.dll
769                         DESTINATION "."
770                 )
771         endif()
772
773         if(NOT CMAKE_CL_64)
774                 install(
775                         FILES ${LIBDIR}/thumbhandler/lib/BlendThumb.dll
776                         DESTINATION "."
777                 )
778         endif()
779                 
780         install( # x86 builds can run on x64 Windows, so this is required at all times
781                 FILES ${LIBDIR}/thumbhandler/lib/BlendThumb64.dll
782                 DESTINATION "."
783         )
784
785         if(WITH_OPENCOLORIO)
786                 set(OCIOBIN ${LIBDIR}/opencolorio/bin)
787                 if(NOT MINGW)
788                         install(
789                                 FILES
790                                         ${OCIOBIN}/OpenColorIO.dll
791                                 DESTINATION "."
792                         )
793                 else()
794                         install(
795                                 FILES
796                                         ${OCIOBIN}/libOpenColorIO.dll
797                                 DESTINATION "."
798                         )
799                 endif()
800         endif()
801
802 elseif(APPLE)
803
804         # handy install macro to exclude files, we use \$ escape for the "to"
805         # argument when calling so ${BUILD_TYPE} does not get expanded
806         macro(install_dir from to)
807                 install(
808                         DIRECTORY ${from}
809                         DESTINATION ${to}
810                         PATTERN ".git" EXCLUDE
811                         PATTERN ".svn" EXCLUDE
812                         PATTERN "*.pyc" EXCLUDE
813                         PATTERN "*.pyo" EXCLUDE
814                         PATTERN "*.orig" EXCLUDE
815                         PATTERN "*.rej" EXCLUDE
816                         PATTERN "__pycache__" EXCLUDE
817                         PATTERN "__MACOSX" EXCLUDE
818                         PATTERN ".DS_Store" EXCLUDE
819                 )
820         endmacro()
821
822         set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blender.app)
823
824         # setup Info.plist
825         execute_process(COMMAND date "+%Y-%m-%d"
826                         OUTPUT_VARIABLE BLENDER_DATE
827                         OUTPUT_STRIP_TRAILING_WHITESPACE)
828
829         set_target_properties(blender PROPERTIES
830                 MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
831                 MACOSX_BUNDLE_SHORT_VERSION_STRING ${BLENDER_VERSION}
832                 MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION} ${BLENDER_DATE}")
833
834         # Gather the date in finder-style
835         execute_process(COMMAND date "+%m/%d/%Y/%H:%M"
836         OUTPUT_VARIABLE SETFILE_DATE
837         OUTPUT_STRIP_TRAILING_WHITESPACE)
838
839         # Give the bundle actual creation/modification date
840         execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE} ${EXECUTABLE_OUTPUT_PATH}/blender.app)
841
842         install(
843                 TARGETS blender
844                 DESTINATION "."
845         )
846
847         # install release and app files
848         install(
849                 FILES ${BLENDER_TEXT_FILES}
850                 DESTINATION blender.app/Contents
851         )
852
853         install(
854                 FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
855                 DESTINATION blender.app/Contents
856         )
857
858         install_dir(
859                 ${OSX_APP_SOURCEDIR}/Contents/Resources
860                 blender.app/Contents/
861         )
862
863         if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
864                 install(
865                         FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
866                         DESTINATION blender.app/Contents/Resources/lib/
867                 )
868         endif()
869
870         if(WITH_LLVM AND NOT LLVM_STATIC)
871                 install(
872                         FILES ${LIBDIR}/llvm/lib/libLLVM-3.4.dylib
873                         DESTINATION blender.app/Contents/MacOS
874                 )
875         endif()
876
877         # python
878         if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
879                 # the python zip is first extract as part of the build process,
880                 # and then later installed as part of make install. this is much
881                 # quicker, and means we can easily exclude files on copy
882                 # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses  Pyhon framework
883                 add_custom_target(
884                         extractpyzip
885                         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
886
887                 set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
888
889                 add_custom_command(
890                         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
891                         COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
892                         COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
893                         COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
894                         DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
895
896                 add_dependencies(blender extractpyzip)
897
898                 # copy extracted python files
899                 install_dir(
900                         ${CMAKE_CURRENT_BINARY_DIR}/python
901                         \${TARGETDIR_VER}
902                 )
903                 # copy site-packages files
904                 install_dir(
905                         ${LIBDIR}/release/site-packages
906                         ${CMAKE_CURRENT_BINARY_DIR}/python/lib/python${PYTHON_VERSION}/site-packages
907                 )
908
909         endif()
910         
911         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
912         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
913         if(WITH_GAMEENGINE AND WITH_PLAYER)
914                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
915                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
916                 set(PLAYER_TARGETDIR_VER blenderplayer.app/Contents/Resources/${BLENDER_VERSION})
917
918
919                 # important to make a clean  install each time else old scripts get loaded.
920                 install(
921                         CODE
922                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
923                 )
924
925                 # Give the bundle actual creation/modification date
926                 execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE} ${EXECUTABLE_OUTPUT_PATH}/blenderplayer.app)
927
928                 install(
929                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
930                         DESTINATION blenderplayer.app/Contents
931                 )
932
933                 install_dir(
934                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
935                         blenderplayer.app/Contents/
936                 )
937
938                 if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
939                 install(
940                 FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
941                 DESTINATION blenderplayer.app/Contents/Resources/lib/
942                 )
943                 endif()
944
945
946                 # python
947                 if(WITH_PYTHON AND NOT WITH_PYTHON_FRAMEWORK)
948                         add_custom_command(
949                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
950                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
951                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
952                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
953                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
954
955                         # copy extracted python files
956                         install_dir(
957                                 ${CMAKE_CURRENT_BINARY_DIR}/python
958                                 \${PLAYER_TARGETDIR_VER}
959                         )
960                 endif()
961
962         endif()
963
964 endif()
965
966 # -----------------------------------------------------------------------------
967 # Generic Install, for all targets
968
969
970
971 # install more files specified elsewhere
972 delayed_do_install(${TARGETDIR_VER})
973
974 unset(BLENDER_TEXT_FILES)
975
976
977 # -----------------------------------------------------------------------------
978 # Setup link libs
979
980 add_dependencies(blender makesdna)
981
982 setup_blender_sorted_libs()
983
984 target_link_libraries(blender ${BLENDER_SORTED_LIBS})
985
986 setup_liblinks(blender)
987
988 # -----------------------------------------------------------------------------
989 # Setup launcher
990
991 if(WIN32 AND NOT WITH_PYTHON_MODULE)
992         set(LAUNCHER_SRC
993                 creator_launch_win.c
994                 ../icons/winblender.rc
995         )
996         add_executable(blender-launcher ${LAUNCHER_SRC})
997         target_link_libraries(blender-launcher bf_intern_utfconv ${PLATFORM_LINKLIBS})
998
999         set_target_properties(blender PROPERTIES OUTPUT_NAME blender-app)
1000         set_target_properties(blender-launcher PROPERTIES OUTPUT_NAME blender)
1001
1002         install(TARGETS blender blender-launcher
1003                         COMPONENT Blender
1004                         DESTINATION ".")
1005
1006         if(MSVC12_REDIST_DIR)
1007                 if(CMAKE_CL_64)
1008                         set(_WIN_PLATFORM x64)
1009                 else()
1010                         set(_WIN_PLATFORM x86)
1011                 endif()
1012                 install(
1013                         FILES ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.CRT/msvcp120.dll
1014                                   ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.CRT/msvcr120.dll
1015                 DESTINATION ".")
1016                 if(WITH_OPENMP)
1017                         install(
1018                                 FILES ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.OpenMP/vcomp120.dll
1019                                 DESTINATION ".")
1020                 endif()
1021         endif()
1022 endif()