Merged changes in the trunk up to revision 52546.
[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 # color management
306 if(WITH_OPENCOLORIO)
307         install(
308                 DIRECTORY ${CMAKE_SOURCE_DIR}/release/datafiles/colormanagement
309                 DESTINATION ${TARGETDIR_VER}/datafiles
310                 PATTERN ".svn" EXCLUDE
311         )
312 endif()
313
314 # helpful tip when using make
315 if("${CMAKE_GENERATOR}" MATCHES ".*Makefiles.*")
316         # message after building.
317         add_custom_command(
318                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
319                 COMMAND ${CMAKE_COMMAND} -E echo 'now run: \"make install\" to copy runtime files and scripts to ${TARGETDIR_VER}'
320         )
321 endif()
322
323
324 # -----------------------------------------------------------------------------
325 # Install Targets (Platform Specific)
326
327 if(UNIX AND NOT APPLE)
328
329         # there are a few differences between portable and system install
330         if(WITH_INSTALL_PORTABLE)
331                 install(
332                         FILES
333                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
334                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
335                                 ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1
336                         DESTINATION ${TARGETDIR}
337                 )
338
339                 install(
340                         PROGRAMS
341                         ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
342                         DESTINATION ${TARGETDIR}
343                 )
344
345                 install(
346                         FILES ${BLENDER_TEXT_FILES}
347                         DESTINATION ${TARGETDIR}
348                 )
349
350         else()
351                 # main blender binary
352                 if(WITH_PYTHON_MODULE)
353                         install(
354                                 TARGETS blender
355                                 LIBRARY
356                                 DESTINATION ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages
357                         )
358                 else()
359                         install(
360                                 PROGRAMS ${TARGETDIR}/blender
361                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
362                         )
363                 endif()
364
365
366                 if(WITH_GAMEENGINE AND WITH_PLAYER)
367                         install(
368                                 PROGRAMS ${TARGETDIR}/blenderplayer
369                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
370                         )
371                 endif()
372
373                 # misc files
374                 install(
375                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
376                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
377                 )
378                 install(
379                         DIRECTORY
380                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/16x16
381                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/22x22
382                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/24x24
383                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/32x32
384                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/48x48
385                                 ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/256x256
386                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor
387                         PATTERN ".svn" EXCLUDE
388                         PATTERN "*.svg" EXCLUDE
389                 )
390                 install(
391                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/apps/blender.svg
392                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps
393                 )
394                 install(
395                         PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
396                         DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
397                 )
398                 install(
399                         FILES ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1
400                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
401                 )
402                 install(
403                         FILES ${BLENDER_TEXT_FILES}
404                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/blender
405                 )
406         endif()
407
408         if(WITH_PYTHON)
409                 if(WITH_PYTHON_INSTALL)
410                         # on some platforms (like openSUSE) Python is linked
411                         # to be used from lib64 folder.
412                         # determine this from Python's libraries path
413                         if(${PYTHON_LIBPATH} MATCHES "lib64$")
414                                 set(_target_LIB "lib64")
415                         else()
416                                 set(_target_LIB "lib")
417                         endif()
418
419                         # Copy the systems python into the install directory
420                         # Scons copy in tools/Blender.py
421                         # install(CODE "message(\"copying a subset of the systems python...\")")
422                         install(
423                                 DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
424                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
425                                 PATTERN ".svn" EXCLUDE
426                                 PATTERN "__pycache__" EXCLUDE               # * any cache *
427                                 PATTERN "distutils" EXCLUDE                 # ./distutils
428                                 PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
429                                 PATTERN "config" EXCLUDE                    # ./config
430                                 PATTERN "config-*" EXCLUDE                  # ./config-*
431                                 PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
432                                 PATTERN "tkinter" EXCLUDE                   # ./tkinter
433                                 PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
434                                 PATTERN "idlelib" EXCLUDE                   # ./idlelib
435                                 PATTERN "test" EXCLUDE                      # ./test
436                                 PATTERN "turtledemo" EXCLUDE                # ./turtledemo
437                                 PATTERN "turtle.py" EXCLUDE                                     # ./turtle.py
438                         )
439
440                         # # doesnt work, todo
441                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
442                         
443                         if(WITH_PYTHON_INSTALL_NUMPY)
444                                 install(
445                                         DIRECTORY ${PYTHON_NUMPY_PATH}/numpy
446                                         DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}/python${PYTHON_VERSION}/site-packages
447                                         PATTERN ".svn" EXCLUDE
448                                         PATTERN "__pycache__" EXCLUDE           # * any cache *
449                                         PATTERN "*.pyc" EXCLUDE                 # * any cache *
450                                         PATTERN "*.pyo" EXCLUDE                 # * any cache *
451                                         PATTERN "distutils" EXCLUDE             # ./distutils
452                                         PATTERN "oldnumeric" EXCLUDE            # ./oldnumeric
453                                         PATTERN "doc" EXCLUDE                   # ./doc
454                                         PATTERN "tests" EXCLUDE                 # ./tests
455                                         PATTERN "f2py" EXCLUDE                  # ./f2py - fortran/python interface code, not fun for blender devs.
456                                         PATTERN "include" EXCLUDE               # include dirs all over, we wont use NumPy/CAPI
457                                         PATTERN "*.h" EXCLUDE                   # some includes are not in include dirs
458                                         PATTERN "*.a" EXCLUDE                   # ./core/lib/libnpymath.a - for linking, we dont need.
459                                 )
460                         endif()
461                         
462                         unset(_target_LIB)
463                         
464                 endif()
465         endif()
466 elseif(WIN32)
467
468         install(
469                 FILES ${BLENDER_TEXT_FILES}
470                 DESTINATION ${TARGETDIR}
471         )
472
473         if(WITH_PYTHON)
474                 set_lib_path(PYLIB "python")
475                 install(
476                         FILES ${PYLIB}/lib/python32.dll
477                         DESTINATION ${TARGETDIR}
478                         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
479                 )
480
481                 install(
482                         FILES ${PYLIB}/lib/python32_d.dll
483                         DESTINATION ${TARGETDIR}
484                         CONFIGURATIONS Debug
485                 )
486
487                 if(WITH_PYTHON_INSTALL)
488                         # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
489
490                         # create the directory in multiple steps, so it actually gets created when it doesn't exist yet
491                         install(
492                                 CODE
493                                 "
494                                 message(\"creating ${TARGETDIR_VER}/python/lib\")
495                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python\")
496                                 file(MAKE_DIRECTORY \"${TARGETDIR_VER}/python/lib\")
497                                 message(\"done creating dir\")
498                                 "
499                         )
500
501                         install(
502                                 CODE
503                                 "
504                                 if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" STREQUAL \"Debug\")
505                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
506                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python32_d.tar.gz\")
507                                 else()
508                                         execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \"${TARGETDIR_VER}/python/lib\"
509                                                 \"${CMAKE_COMMAND}\" -E tar xzfv \"${LIBDIR}/release/python32.tar.gz\")
510                                 endif()
511                                 "
512                         )
513
514                         # doesnt work, todo
515                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
516                 endif()
517         endif()
518
519         if(CMAKE_CL_64)
520                 # png is statically linked on win64
521                 install(
522                         FILES ${LIBDIR}/zlib/lib/zlib.dll
523                         DESTINATION ${TARGETDIR}
524                 )
525         else()
526                 #not needed since we link statically, maybe also unneeded for MinGW?
527                 if(NOT WITH_MINGW64)
528                         install(
529                                 FILES
530                                         ${LIBDIR}/zlib/lib/zlib.dll
531                                 DESTINATION ${TARGETDIR}
532                         )
533                 endif()
534         endif()
535
536         if(MSVC)
537                 install(
538                         FILES ${LIBDIR}/pthreads/lib/pthreadVC2.dll
539                         DESTINATION ${TARGETDIR}
540                 )
541         else()
542                 #MinGW64 comes with own version. For portable builds it will probaly have to be copied to work
543                 if(NOT WITH_MINGW64)
544                         install(
545                                 FILES ${LIBDIR}/pthreads/lib/pthreadGC2.dll
546                                 DESTINATION ${TARGETDIR}
547                         )
548                 elseif(WITH_MINGW64)
549                         install(
550                                 FILES 
551                                         ${LIBDIR}/binaries/libgcc_s_sjlj-1.dll
552                                         ${LIBDIR}/binaries/libwinpthread-1.dll
553                                         ${LIBDIR}/binaries/libstdc++-6.dll
554                                 DESTINATION ${TARGETDIR}
555                         )
556                         
557                         if(WITH_OPENMP)
558                                 install(
559                                         FILES 
560                                         ${LIBDIR}/binaries/libgomp-1.dll
561                                         DESTINATION ${TARGETDIR}
562                                 )
563                         endif()
564                 endif()
565         endif()
566
567         if(WITH_CODEC_FFMPEG)
568                 install(
569                         FILES
570                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
571                                 ${LIBDIR}/ffmpeg/lib/avformat-53.dll
572                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
573                                 ${LIBDIR}/ffmpeg/lib/avutil-51.dll
574                                 ${LIBDIR}/ffmpeg/lib/swscale-2.dll
575                         DESTINATION ${TARGETDIR}
576                 )
577                 if(WITH_MINGW64)
578                 install(
579                         FILES
580                                 ${LIBDIR}/ffmpeg/lib/swresample-0.dll
581                                 ${LIBDIR}/ffmpeg/lib/xvidcore.dll
582                         DESTINATION ${TARGETDIR}
583                 )
584                 endif()
585         endif()
586
587         if(WITH_CODEC_SNDFILE)
588                 install(
589                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
590                         DESTINATION ${TARGETDIR}
591                 )
592         endif()
593
594         if(WITH_OPENAL)
595                 install(
596                         FILES
597                                 ${LIBDIR}/openal/lib/OpenAL32.dll
598                                 ${LIBDIR}/openal/lib/wrap_oal.dll
599                         DESTINATION ${TARGETDIR}
600                 )
601         endif()
602
603         if(WITH_SDL)
604                 if(NOT CMAKE_CL_64)
605                         install(
606                                 FILES ${LIBDIR}/sdl/lib/SDL.dll
607                                 DESTINATION ${TARGETDIR}
608                         )
609                 endif()
610         endif()
611
612         if(NOT CMAKE_CL_64)
613                 install(
614                         FILES ${LIBDIR}/thumbhandler/lib/BlendThumb.dll
615                         DESTINATION ${TARGETDIR}
616                 )
617         endif()
618                 
619         install( # x86 builds can run on x64 Windows, so this is required at all times
620                 FILES ${LIBDIR}/thumbhandler/lib/BlendThumb64.dll
621                 DESTINATION ${TARGETDIR}
622         )
623
624         if(WITH_OPENCOLORIO)
625                 set(OCIOBIN ${LIBDIR}/opencolorio/bin)
626                 if(NOT MINGW)
627                         install(
628                                 FILES
629                                         ${OCIOBIN}/OpenColorIO.dll
630                                 DESTINATION ${TARGETDIR}
631                         )
632                 else()
633                         install(
634                                 FILES
635                                         ${OCIOBIN}/libOpenColorIO.dll
636                                 DESTINATION ${TARGETDIR}
637                         )
638                 endif()
639         endif()
640
641 elseif(APPLE)
642
643         # handy install macro to exclude files, we use \$ escape for the "to"
644         # argument when calling so ${BUILD_TYPE} does not get expanded
645         macro(install_dir from to)
646                 install(
647                         DIRECTORY ${from}
648                         DESTINATION ${to}
649                         PATTERN ".svn" EXCLUDE
650                         PATTERN "*.pyc" EXCLUDE
651                         PATTERN "*.pyo" EXCLUDE
652                         PATTERN "*.orig" EXCLUDE
653                         PATTERN "*.rej" EXCLUDE
654                         PATTERN "__pycache__" EXCLUDE
655                         PATTERN "__MACOSX" EXCLUDE
656                         PATTERN ".DS_Store" EXCLUDE
657                 )
658         endmacro()
659
660         set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blender.app)
661
662         # setup Info.plist
663         execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BLENDER_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
664
665         set_target_properties(blender PROPERTIES
666                 MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
667                 MACOSX_BUNDLE_SHORT_VERSION_STRING ${BLENDER_VERSION}
668                 MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION} ${BLENDER_DATE}")
669
670
671         # install release and app files
672         install(
673                 FILES ${BLENDER_TEXT_FILES}
674                 DESTINATION ${TARGETDIR}
675         )
676
677         install(
678                 FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
679                 DESTINATION ${TARGETDIR}/blender.app/Contents
680         )
681
682         install_dir(
683                 ${OSX_APP_SOURCEDIR}/Contents/Resources
684                 \${TARGETDIR}/blender.app/Contents/
685         )
686
687         # python
688         if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE)
689                 # the python zip is first extract as part of the build process,
690                 # and then later installed as part of make install. this is much
691                 # quicker, and means we can easily exclude files on copy
692                 # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses  Pyhon framework
693                 add_custom_target(
694                         extractpyzip
695                         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
696
697                 set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
698
699                 add_custom_command(
700                         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
701                         COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
702                         COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
703                         COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
704                         DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
705
706                 add_dependencies(blender extractpyzip)
707
708                 # copy extracted python files
709                 install_dir(
710                         ${CMAKE_CURRENT_BINARY_DIR}/python
711                         \${TARGETDIR_VER}
712                 )
713
714         endif()
715         
716         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
717         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
718         if(WITH_GAMEENGINE AND WITH_PLAYER)
719                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
720                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
721                 set(PLAYER_TARGETDIR_VER ${TARGETDIR}/blenderplayer.app/Contents/MacOS/${BLENDER_VERSION})
722
723
724                 # important to make a clean  install each time else old scripts get loaded.
725                 install(
726                         CODE
727                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
728                 )
729
730                 install(
731                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
732                         DESTINATION ${TARGETDIR}/blenderplayer.app/Contents
733                 )
734
735                 install_dir(
736                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
737                         \${TARGETDIR}/blenderplayer.app/Contents/
738                 )
739
740                 # python
741                 if(WITH_PYTHON)
742                         add_custom_command(
743                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
744                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
745                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
746                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
747                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
748
749                         # copy extracted python files
750                         install_dir(
751                                 ${CMAKE_CURRENT_BINARY_DIR}/python
752                                 \${PLAYER_TARGETDIR_VER}
753                         )
754                 endif()
755
756         endif()
757                 
758 endif()
759
760 # -----------------------------------------------------------------------------
761 # Generic Install, for all targets
762
763
764
765 # install more files specified elsewhere
766 delayed_do_install(${TARGETDIR_VER})
767
768 unset(BLENDER_TEXT_FILES)
769
770
771 # -----------------------------------------------------------------------------
772 # Setup link libs
773
774 add_dependencies(blender makesdna)
775
776 get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
777
778 set(BLENDER_LINK_LIBS
779         ${BLENDER_LINK_LIBS}
780         bf_windowmanager
781         bf_render
782 )
783
784 if(WITH_MOD_FLUID)
785         list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
786 endif()
787
788 if(WITH_CYCLES)
789         list(APPEND BLENDER_LINK_LIBS
790                 cycles_render
791                 cycles_bvh
792                 cycles_device
793                 cycles_kernel
794                 cycles_util
795                 cycles_subd)
796         if(WITH_CYCLES_OSL)
797                 list(APPEND BLENDER_LINK_LIBS cycles_kernel_osl)
798         endif()
799 endif()
800
801 #if(UNIX)
802         # Sort libraries
803         set(BLENDER_SORTED_LIBS
804                 bf_windowmanager
805
806                 bf_editor_space_api
807                 bf_editor_space_action
808                 bf_editor_space_buttons
809                 bf_editor_space_console
810                 bf_editor_space_file
811                 bf_editor_space_graph
812                 bf_editor_space_image
813                 bf_editor_space_info
814                 bf_editor_space_logic
815                 bf_editor_space_nla
816                 bf_editor_space_node
817                 bf_editor_space_outliner
818                 bf_editor_space_script
819                 bf_editor_space_sequencer
820                 bf_editor_space_time
821                 bf_editor_space_userpref
822                 bf_editor_space_view3d
823                 bf_editor_space_clip
824
825                 bf_editor_text
826                 bf_editor_transform
827                 bf_editor_util
828                 bf_editor_uvedit
829                 bf_editor_curve
830                 bf_editor_armature
831                 bf_editor_gpencil
832                 bf_editor_interface
833                 bf_editor_mesh
834                 bf_editor_metaball
835                 bf_editor_object
836                 bf_editor_physics
837                 bf_editor_render
838                 bf_editor_screen
839                 bf_editor_sculpt_paint
840                 bf_editor_sound
841                 bf_editor_animation
842                 bf_editor_datafiles
843                 bf_editor_mask
844                 bf_editor_io
845
846                 bf_render
847                 bf_intern_opennl
848                 bf_python
849                 bf_python_ext
850                 bf_python_mathutils
851                 bf_python_bmesh
852                 bf_freestyle
853                 bf_ikplugin
854                 bf_modifiers
855                 bf_bmesh
856                 bf_blenkernel
857                 bf_nodes
858                 bf_gpu
859                 bf_blenloader
860                 bf_imbuf
861                 bf_blenlib
862                 bf_intern_ghost
863                 bf_intern_string
864                 bf_avi
865                 bf_imbuf_cineon
866                 bf_imbuf_openexr
867                 bf_imbuf_dds
868                 bf_collada
869                 bf_intern_bsp
870                 bf_intern_elbeem
871                 bf_intern_memutil
872                 bf_intern_guardedalloc
873                 bf_intern_ctr
874                 bf_intern_utfconv
875                 ge_blen_routines
876                 ge_converter
877                 ge_phys_dummy
878                 ge_phys_bullet
879                 bf_intern_smoke
880                 extern_minilzo
881                 extern_lzma
882                 extern_colamd
883                 ge_logic_ketsji
884                 extern_recastnavigation
885                 ge_phys_common
886                 ge_logic
887                 ge_rasterizer
888                 ge_oglrasterizer
889                 ge_logic_expressions
890                 ge_scenegraph
891                 ge_logic_network
892                 ge_logic_ngnetwork
893                 extern_bullet
894                 ge_logic_loopbacknetwork
895                 bf_intern_moto
896                 extern_openjpeg
897                 extern_redcode
898                 ge_videotex
899                 bf_rna
900                 bf_dna
901                 bf_blenfont
902                 bf_intern_audaspace
903                 bf_intern_mikktspace
904                 bf_intern_dualcon
905                 bf_intern_cycles
906                 cycles_render
907                 cycles_bvh
908                 cycles_device
909                 cycles_kernel
910                 cycles_util
911                 cycles_subd
912                 bf_intern_raskter
913                 bf_intern_opencolorio
914         )
915
916         if(WITH_COMPOSITOR)
917                 # added for opencl compositor
918                 list_insert_before(BLENDER_SORTED_LIBS "bf_blenkernel" "bf_compositor")
919                 list_insert_after(BLENDER_SORTED_LIBS "bf_compositor" "bf_opencl")
920         endif()
921
922         if(WITH_LIBMV)
923                 list(APPEND BLENDER_SORTED_LIBS extern_libmv)
924                 list(APPEND BLENDER_SORTED_LIBS extern_ceres)
925         endif()
926
927         if(WITH_MOD_CLOTH_ELTOPO)
928                 list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
929         endif()
930
931         if(NOT WITH_SYSTEM_GLEW)
932                 list(APPEND BLENDER_SORTED_LIBS extern_glew)
933         endif()
934
935         if(WITH_BINRELOC)
936                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
937         endif()
938
939         if(WITH_CXX_GUARDEDALLOC)
940                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
941         endif()
942
943         if(WITH_IK_SOLVER)
944                 list_insert_after(BLENDER_SORTED_LIBS "bf_intern_elbeem" "bf_intern_iksolver")
945         endif()
946
947         if(WITH_IK_ITASC)
948                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
949         endif()
950
951         if(WITH_CODEC_QUICKTIME)
952                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
953         endif()
954
955         if(WITH_MOD_BOOLEAN)
956                 list(APPEND BLENDER_SORTED_LIBS extern_carve)
957         endif()
958
959         if(WITH_GHOST_XDND)
960                 list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
961         endif()
962
963         if(WITH_CYCLES_OSL)
964                 list_insert_after(BLENDER_SORTED_LIBS "cycles_kernel" "cycles_kernel_osl")
965         endif()
966
967         if(WITH_INTERNATIONAL)
968                 list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
969         endif()
970
971         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
972                 set(REMLIB ${SORTLIB})
973                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
974                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
975                                 set(REMLIB "")
976                         endif()
977                 endforeach()
978                 if(REMLIB)
979                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
980                         list(APPEND REM_MSG ${REMLIB})
981                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
982                 endif()
983         endforeach()
984         if(REM_MSG)
985                 list(SORT REM_MSG)
986                 message(STATUS "Blender Skipping: (${REM_MSG})")
987         endif()
988         target_link_libraries(blender ${BLENDER_SORTED_LIBS})
989
990         unset(SEARCHLIB)
991         unset(SORTLIB)
992         unset(REMLIB)
993         unset(REM_MSG)
994
995 #else()
996 #       target_link_libraries(blender ${BLENDER_LINK_LIBS})
997 #endif()
998
999 setup_liblinks(blender)