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