Fix for building blender as a Python module
[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
243 set(BLENDER_TEXT_FILES
244         ${CMAKE_SOURCE_DIR}/release/text/GPL-license.txt
245         ${CMAKE_SOURCE_DIR}/release/text/Python-license.txt
246         ${CMAKE_SOURCE_DIR}/release/text/copyright.txt
247         # generate this file
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_PYTHON_MODULE)
265                 set(TARGETDIR_VER ${PYTHON_SITE_PACKAGES}/${BLENDER_VERSION})
266         else()
267                 if(WITH_INSTALL_PORTABLE)
268                         set(TARGETDIR_VER ${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_PYTHON_MODULE)
411                 install(
412                         TARGETS blender
413                         LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}
414                 )
415                 # none of the other files are needed currently
416         elseif(WITH_INSTALL_PORTABLE)
417                 install(
418                         TARGETS blender
419                         DESTINATION "."
420                 )
421
422                 if(WITH_DOC_MANPAGE)
423                         install(
424                                 FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
425                                 DESTINATION "."
426                         )
427                 endif()
428                 install(
429                         FILES
430                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
431                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
432                         DESTINATION "."
433                 )
434
435                 install(
436                         PROGRAMS
437                         ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
438                         DESTINATION "."
439                 )
440
441                 set(BLENDER_TEXT_FILES_DESTINATION ".")
442         else()
443                 # main blender binary
444                 install(
445                         TARGETS blender
446                         DESTINATION bin
447                 )
448                 if(WITH_DOC_MANPAGE)
449                         # manpage only with 'blender' binary
450                         install(
451                                 FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
452                                 DESTINATION share/man/man1
453                         )
454                 endif()
455
456                 # misc files
457                 install(
458                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
459                         DESTINATION share/applications
460                 )
461                 install(
462                         DIRECTORY
463                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/16x16
464                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/22x22
465                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/24x24
466                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/32x32
467                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/48x48
468                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/256x256
469                         DESTINATION share/icons/hicolor
470                         PATTERN "*.svg" EXCLUDE
471                 )
472                 install(
473                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
474                         DESTINATION share/icons/hicolor/scalable/apps
475                 )
476                 install(
477                         PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
478                         DESTINATION bin
479                 )
480                 set(BLENDER_TEXT_FILES_DESTINATION share/doc/blender)
481         endif()
482
483         if(WITH_PYTHON)
484                 if(WITH_PYTHON_INSTALL)
485                         # on some platforms (like openSUSE) Python is linked
486                         # to be used from lib64 folder.
487                         # determine this from Python's libraries path
488                         #
489                         # ugh, its possible 'lib64' is just a symlink to 'lib' which causes incorrect use of 'lib64'
490                         get_filename_component(_pypath_real ${PYTHON_LIBPATH} REALPATH)
491                         if(${_pypath_real} MATCHES "lib64$")
492                                 set(_target_LIB "lib64")
493                         else()
494                                 set(_target_LIB "lib")
495                         endif()
496                         unset(_pypath_real)
497
498                         # Copy the systems python into the install directory
499                         # Scons copy in tools/Blender.py
500                         # install(CODE "message(\"copying a subset of the systems python...\")")
501                         install(
502                                 DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
503                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
504                                 PATTERN ".svn" EXCLUDE
505                                 PATTERN "__pycache__" EXCLUDE               # * any cache *
506                                 PATTERN "distutils" EXCLUDE                 # ./distutils
507                                 PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
508                                 PATTERN "config" EXCLUDE                    # ./config
509                                 PATTERN "config-*" EXCLUDE                  # ./config-*
510                                 PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
511                                 PATTERN "tkinter" EXCLUDE                   # ./tkinter
512                                 PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
513                                 PATTERN "idlelib" EXCLUDE                   # ./idlelib
514                                 PATTERN "test" EXCLUDE                      # ./test
515                                 PATTERN "turtledemo" EXCLUDE                # ./turtledemo
516                                 PATTERN "turtle.py" EXCLUDE                 # ./turtle.py
517                         )
518
519                         # # doesnt work, todo
520                         # install(CODE "execute_process(COMMAND find ${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
521
522                         if(WITH_PYTHON_INSTALL_NUMPY)
523                                 # Install to the same directory as the source, so debian-like
524                                 # distros are happy with their policy.
525                                 set(_suffix "site-packages")
526                                 if(${PYTHON_NUMPY_PATH} MATCHES "dist-packages")
527                                         set(_suffix "dist-packages")
528                                 endif()
529                                 install(
530                                         DIRECTORY ${PYTHON_NUMPY_PATH}/numpy
531                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
532                                         PATTERN ".svn" EXCLUDE
533                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
534                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
535                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
536                                         PATTERN "distutils" EXCLUDE             # ./distutils
537                                         PATTERN "oldnumeric" EXCLUDE            # ./oldnumeric
538                                         PATTERN "doc" EXCLUDE                   # ./doc
539                                         PATTERN "tests" EXCLUDE                 # ./tests
540                                         PATTERN "f2py" EXCLUDE                  # ./f2py - fortran/python interface code, not fun for blender devs.
541                                         PATTERN "include" EXCLUDE               # include dirs all over, we wont use NumPy/CAPI
542                                         PATTERN "*.h" EXCLUDE                   # some includes are not in include dirs
543                                         PATTERN "*.a" EXCLUDE                   # ./core/lib/libnpymath.a - for linking, we dont need.
544                                 )
545                                 unset(_suffix)
546                         endif()
547
548                         # Copy requests, we need to generalize site-packages
549                         if(WITH_PYTHON_INSTALL_REQUESTS)
550                                 set(_suffix "site-packages")
551                                 if(${PYTHON_REQUESTS_PATH} MATCHES "dist-packages")
552                                         set(_suffix "dist-packages")
553                                 endif()
554                                 install(
555                                         DIRECTORY ${PYTHON_REQUESTS_PATH}/requests
556                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
557                                         PATTERN ".svn" EXCLUDE
558                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
559                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
560                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
561                                         PATTERN "cacert.pem" EXCLUDE            # for now we don't deal with security
562                                 )
563                                 # On some platforms requests does have extra dependencies.
564                                 set(_requests_deps "chardet" "urllib3")
565                                 foreach(_requests_dep ${_requests_deps})
566                                         if(EXISTS ${PYTHON_REQUESTS_PATH}/${_requests_dep})
567                                                 install(
568                                                         DIRECTORY ${PYTHON_REQUESTS_PATH}/${_requests_dep}
569                                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
570                                                         PATTERN ".svn" EXCLUDE
571                                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
572                                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
573                                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
574                                                 )
575                                         endif()
576                                 endforeach()
577                                 if(EXISTS ${PYTHON_REQUESTS_PATH}/six.py)
578                                         install(
579                                                 FILES ${PYTHON_REQUESTS_PATH}/six.py
580                                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/${_suffix}
581                                         )
582                                         endif()
583                                 unset(_requests_dep)
584                                 unset(_requests_deps)
585                                 unset(_suffix)
586                         endif()
587                         unset(_target_LIB)
588                         
589                 endif()
590         endif()
591 elseif(WIN32)
592
593         set(BLENDER_TEXT_FILES_DESTINATION ".")
594
595         if(WITH_PYTHON)
596                 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
597
598                 install(
599                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.dll ${LIBDIR}/python/lib/sqlite3.dll
600                         DESTINATION "."
601                         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
602                 )
603
604                 install(
605                         FILES ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}_d.dll ${LIBDIR}/python/lib/sqlite3_d.dll
606                         DESTINATION "."
607                         CONFIGURATIONS Debug
608                 )
609
610                 if(WITH_PYTHON_INSTALL)
611                         # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
612
613                         install(DIRECTORY DESTINATION ${TARGETDIR_VER}/python)
614                         install(DIRECTORY DESTINATION ${TARGETDIR_VER}/python/lib)
615
616                         # WARNING: its important that 'CMAKE_INSTALL_CONFIG_NAME' is evaluated at build time
617                         # and _NOT_ configuration time, when modifying the lines below,
618                         # check it works in both Release & Debug mode.
619                         #
620                         # Edit with extreme care! - Campbell
621
622                         # extract python
623                         install(
624                                 CODE
625                                 "
626                                 message(STATUS \"Extracting Python to: \${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}/python\")
627                                 if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\")
628                                         set(PYTHON_ZIP \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_d.tar.gz\")
629                                 else()
630                                         set(PYTHON_ZIP \"${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}.tar.gz\")
631                                 endif()
632
633                                 execute_process(
634                                         COMMAND \${CMAKE_COMMAND} -E make_directory
635                                                 \"\${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}/python/lib\"
636                                         COMMAND \${CMAKE_COMMAND} -E
637                                                 chdir \"\${CMAKE_INSTALL_PREFIX}/${BLENDER_VERSION}/python/lib\"
638                                                 \${CMAKE_COMMAND} -E
639                                                 tar xzfv \"\${PYTHON_ZIP}\"
640                                 )
641                                 unset(PYTHON_ZIP)
642                                 "
643                         )
644
645                         # release/site-packages
646                         install(
647                                 DIRECTORY ${LIBDIR}/release/site-packages
648                                 DESTINATION ${BLENDER_VERSION}/python/lib
649                                 PATTERN ".svn" EXCLUDE
650                                 PATTERN "__pycache__" EXCLUDE           # * any cache *
651                                 PATTERN "*.pyc" EXCLUDE                 # * any cache *
652                                 PATTERN "*.pyo" EXCLUDE                 # * any cache *)
653                         )
654
655                         if(WITH_PYTHON_INSTALL_NUMPY)
656                                 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages/numpy
657                                         COMMAND ${CMAKE_COMMAND} -E tar xzvf "${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.9.tar.gz"
658                                         DEPENDS ${LIBDIR}/release/python${_PYTHON_VERSION_NO_DOTS}_numpy_1.9.tar.gz
659                                         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages)
660                                 add_custom_target(python_numpy ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages/numpy)
661                                 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${BLENDER_VERSION}/python/lib/site-packages/numpy
662                                                 DESTINATION ${BLENDER_VERSION}/python/lib/site-packages)
663                         endif()
664                 endif()
665
666                 unset(_PYTHON_VERSION_NO_DOTS)
667         endif()
668
669         # EGL Runtime Components
670         if(WITH_GL_EGL)
671                 if(WIN32)
672                         install(FILES "${OPENGLES_DLL}"     DESTINATION ".")
673                         install(FILES "${OPENGLES_EGL_DLL}" DESTINATION ".")
674
675                         if(WITH_GL_ANGLE)
676                                 install(FILES "${D3DCOMPILER_DLL}" DESTINATION ".")
677                         endif()
678                 endif()
679         endif()
680
681         if(MSVC)
682                 install(
683                         FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll
684                         DESTINATION "."
685                 )
686         else()
687                 #MinGW64 comes with own version. For portable builds it will probaly have to be copied to work
688                 if(NOT WITH_MINGW64)
689                         install(
690                                 FILES ${LIBDIR}/pthreads/lib/pthreadGC2.dll
691                                 DESTINATION "."
692                         )
693                 elseif(WITH_MINGW64)
694                         install(
695                                 FILES 
696                                         ${LIBDIR}/binaries/libgcc_s_sjlj-1.dll
697                                         ${LIBDIR}/binaries/libwinpthread-1.dll
698                                         ${LIBDIR}/binaries/libstdc++-6.dll
699                                 DESTINATION "."
700                         )
701                         
702                         if(WITH_OPENMP)
703                                 install(
704                                         FILES 
705                                         ${LIBDIR}/binaries/libgomp-1.dll
706                                         DESTINATION "."
707                                 )
708                         endif()
709                 endif()
710         endif()
711
712         if(WITH_CODEC_FFMPEG)
713                 if(WITH_MINGW64)
714                         install(
715                                 FILES
716                                         ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
717                                         ${LIBDIR}/ffmpeg/lib/avformat-53.dll
718                                         ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
719                                         ${LIBDIR}/ffmpeg/lib/avutil-51.dll
720                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
721                                         ${LIBDIR}/ffmpeg/lib/swresample-0.dll
722                                         ${LIBDIR}/ffmpeg/lib/xvidcore.dll
723                                 DESTINATION "."
724                         )
725                 else()
726                         install(
727                                 FILES
728                                         ${LIBDIR}/ffmpeg/lib/avcodec-55.dll
729                                         ${LIBDIR}/ffmpeg/lib/avformat-55.dll
730                                         ${LIBDIR}/ffmpeg/lib/avdevice-55.dll
731                                         ${LIBDIR}/ffmpeg/lib/avutil-52.dll
732                                         ${LIBDIR}/ffmpeg/lib/swscale-2.dll
733                                 DESTINATION "."
734                         )
735                 endif()
736         endif()
737
738         if(WITH_CODEC_SNDFILE)
739                 install(
740                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
741                         DESTINATION "."
742                 )
743         endif()
744
745         if(WITH_OPENAL)
746                 install(
747                         FILES
748                                 ${LIBDIR}/openal/lib/OpenAL32.dll
749                         DESTINATION "."
750                 )
751         endif()
752
753         if(WITH_SDL)
754                 install(
755                         FILES ${LIBDIR}/sdl/lib/SDL2.dll
756                         DESTINATION "."
757                 )
758         endif()
759
760         if(NOT CMAKE_CL_64)
761                 install(
762                         FILES ${LIBDIR}/thumbhandler/lib/BlendThumb.dll
763                         DESTINATION "."
764                 )
765         endif()
766                 
767         install( # x86 builds can run on x64 Windows, so this is required at all times
768                 FILES ${LIBDIR}/thumbhandler/lib/BlendThumb64.dll
769                 DESTINATION "."
770         )
771
772         if(WITH_OPENCOLORIO)
773                 set(OCIOBIN ${LIBDIR}/opencolorio/bin)
774                 if(NOT MINGW)
775                         install(
776                                 FILES
777                                         ${OCIOBIN}/OpenColorIO.dll
778                                 DESTINATION "."
779                         )
780                 else()
781                         install(
782                                 FILES
783                                         ${OCIOBIN}/libOpenColorIO.dll
784                                 DESTINATION "."
785                         )
786                 endif()
787         endif()
788
789 elseif(APPLE)
790
791         # handy install macro to exclude files, we use \$ escape for the "to"
792         # argument when calling so ${BUILD_TYPE} does not get expanded
793         macro(install_dir from to)
794                 install(
795                         DIRECTORY ${from}
796                         DESTINATION ${to}
797                         PATTERN ".git" EXCLUDE
798                         PATTERN ".svn" EXCLUDE
799                         PATTERN "*.pyc" EXCLUDE
800                         PATTERN "*.pyo" EXCLUDE
801                         PATTERN "*.orig" EXCLUDE
802                         PATTERN "*.rej" EXCLUDE
803                         PATTERN "__pycache__" EXCLUDE
804                         PATTERN "__MACOSX" EXCLUDE
805                         PATTERN ".DS_Store" EXCLUDE
806                 )
807         endmacro()
808
809         set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blender.app)
810
811         # setup Info.plist
812         execute_process(COMMAND date "+%Y-%m-%d"
813                         OUTPUT_VARIABLE BLENDER_DATE
814                         OUTPUT_STRIP_TRAILING_WHITESPACE)
815
816         set_target_properties(blender PROPERTIES
817                 MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
818                 MACOSX_BUNDLE_SHORT_VERSION_STRING ${BLENDER_VERSION}
819                 MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION} ${BLENDER_DATE}")
820
821         # Gather the date in finder-style
822         execute_process(COMMAND date "+%m/%d/%Y/%H:%M"
823         OUTPUT_VARIABLE SETFILE_DATE
824         OUTPUT_STRIP_TRAILING_WHITESPACE)
825
826         # Give the bundle actual creation/modification date
827         execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE} ${EXECUTABLE_OUTPUT_PATH}/blender.app)
828
829         install(
830                 TARGETS blender
831                 DESTINATION "."
832         )
833
834         # install release and app files
835         set(BLENDER_TEXT_FILES_DESTINATION blender.app/Contents)
836
837         install(
838                 FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
839                 DESTINATION blender.app/Contents
840         )
841
842         install_dir(
843                 ${OSX_APP_SOURCEDIR}/Contents/Resources
844                 blender.app/Contents/
845         )
846
847         if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
848                 install(
849                         FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
850                         DESTINATION blender.app/Contents/Resources/lib/
851                 )
852         endif()
853
854         if(WITH_LLVM AND NOT LLVM_STATIC)
855                 install(
856                         FILES ${LIBDIR}/llvm/lib/libLLVM-3.4.dylib
857                         DESTINATION blender.app/Contents/MacOS
858                 )
859         endif()
860
861         # python
862         if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
863                 # the python zip is first extract as part of the build process,
864                 # and then later installed as part of make install. this is much
865                 # quicker, and means we can easily exclude files on copy
866                 # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses  Pyhon framework
867                 add_custom_target(
868                         extractpyzip
869                         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
870
871                 set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
872
873                 add_custom_command(
874                         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
875                         COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
876                         COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
877                         COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
878                         DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
879
880                 add_dependencies(blender extractpyzip)
881
882                 # copy extracted python files
883                 install_dir(
884                         ${CMAKE_CURRENT_BINARY_DIR}/python
885                         \${TARGETDIR_VER}
886                 )
887                 # copy site-packages files
888                 install_dir(
889                         ${LIBDIR}/release/site-packages
890                         ${CMAKE_CURRENT_BINARY_DIR}/python/lib/python${PYTHON_VERSION}/site-packages
891                 )
892
893         endif()
894         
895         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
896         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
897         if(WITH_GAMEENGINE AND WITH_PLAYER)
898                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
899                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
900                 set(PLAYER_TARGETDIR_VER blenderplayer.app/Contents/Resources/${BLENDER_VERSION})
901
902
903                 # important to make a clean  install each time else old scripts get loaded.
904                 install(
905                         CODE
906                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
907                 )
908
909                 # Give the bundle actual creation/modification date
910                 execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE} ${EXECUTABLE_OUTPUT_PATH}/blenderplayer.app)
911
912                 install(
913                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
914                         DESTINATION blenderplayer.app/Contents
915                 )
916
917                 install_dir(
918                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
919                         blenderplayer.app/Contents/
920                 )
921
922                 if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
923                 install(
924                 FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
925                 DESTINATION blenderplayer.app/Contents/Resources/lib/
926                 )
927                 endif()
928
929
930                 # python
931                 if(WITH_PYTHON AND NOT WITH_PYTHON_FRAMEWORK)
932                         add_custom_command(
933                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
934                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
935                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
936                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
937                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
938
939                         # copy extracted python files
940                         install_dir(
941                                 ${CMAKE_CURRENT_BINARY_DIR}/python
942                                 \${PLAYER_TARGETDIR_VER}
943                         )
944                 endif()
945
946         endif()
947
948 endif()
949
950 # -----------------------------------------------------------------------------
951 # Generic Install, for all targets
952
953 if(DEFINED BLENDER_TEXT_FILES_DESTINATION)
954
955         install(
956                 CODE
957                 "
958                 file(READ \"${CMAKE_SOURCE_DIR}/release/text/readme.html\" DATA_SRC)
959                 string(REGEX REPLACE \"BLENDER_VERSION\" \"${BLENDER_VERSION}\" DATA_DST \"\${DATA_SRC}\")
960                 file(WRITE \"\${CMAKE_BINARY_DIR}/release/text/readme.html\" \"\${DATA_DST}\")
961                 unset(DATA_SRC)
962                 unset(DATA_DST)
963                 "
964         )
965         list(APPEND BLENDER_TEXT_FILES
966                 ${CMAKE_BINARY_DIR}/release/text/readme.html
967         )
968
969         install(
970                 FILES ${BLENDER_TEXT_FILES}
971                 DESTINATION "${BLENDER_TEXT_FILES_DESTINATION}"
972         )
973 endif()
974
975 # install more files specified elsewhere
976 delayed_do_install(${TARGETDIR_VER})
977
978 unset(BLENDER_TEXT_FILES)
979 unset(BLENDER_TEXT_FILES_DESTINATION)
980
981
982 # -----------------------------------------------------------------------------
983 # Setup link libs
984
985 add_dependencies(blender makesdna)
986
987 setup_blender_sorted_libs()
988
989 target_link_libraries(blender ${BLENDER_SORTED_LIBS})
990
991 setup_liblinks(blender)
992
993 # -----------------------------------------------------------------------------
994 # Setup launcher
995
996 if(WIN32 AND NOT WITH_PYTHON_MODULE)
997         set(LAUNCHER_SRC
998                 creator_launch_win.c
999                 ../icons/winblender.rc
1000         )
1001         add_executable(blender-launcher ${LAUNCHER_SRC})
1002         target_link_libraries(blender-launcher bf_intern_utfconv ${PLATFORM_LINKLIBS})
1003
1004         set_target_properties(blender PROPERTIES OUTPUT_NAME blender-app)
1005         set_target_properties(blender-launcher PROPERTIES OUTPUT_NAME blender)
1006
1007         install(TARGETS blender blender-launcher
1008                         COMPONENT Blender
1009                         DESTINATION ".")
1010
1011         if(MSVC12_REDIST_DIR)
1012                 if(CMAKE_CL_64)
1013                         set(_WIN_PLATFORM x64)
1014                 else()
1015                         set(_WIN_PLATFORM x86)
1016                 endif()
1017                 install(
1018                         FILES ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.CRT/msvcp120.dll
1019                                   ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.CRT/msvcr120.dll
1020                 DESTINATION ".")
1021                 if(WITH_OPENMP)
1022                         install(
1023                                 FILES ${MSVC12_REDIST_DIR}/${_WIN_PLATFORM}/Microsoft.VC120.OpenMP/vcomp120.dll
1024                                 DESTINATION ".")
1025                 endif()
1026         endif()
1027 endif()