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