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