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