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