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