Add cycles support for MinGW-w64
[blender-staging.git] / source / creator / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # ***** BEGIN GPL LICENSE BLOCK *****
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # The Original Code is Copyright (C) 2006, Blender Foundation
19 # All rights reserved.
20 #
21 # The Original Code is: all of this file.
22 #
23 # Contributor(s): Jacques Beaurain.
24 #
25 # ***** END GPL LICENSE BLOCK *****
26
27 setup_libdirs()
28
29 blender_include_dirs(
30         ../../intern/guardedalloc
31         ../blender/blenlib
32         ../blender/blenkernel
33         ../blender/blenloader
34         ../blender/editors/include
35         ../blender/makesrna
36         ../blender/imbuf
37         ../blender/render/extern/include
38         ../blender/makesdna
39         ../blender/gpu
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                 # plugins in blender 2.6 don't work at the moment.
400                 #
401                 # install(
402                 #       DIRECTORY ${CMAKE_SOURCE_DIR}/release/plugins
403                 #       DESTINATION ${TARGETDIR_VER}
404                 #       PATTERN ".svn" EXCLUDE
405                 # )
406
407         if(WITH_PYTHON)
408                 if(WITH_PYTHON_INSTALL)
409                         # on some platforms (like openSUSE) Python is linked
410                         # to be used from lib64 folder.
411                         # determine this from Python's libraries path
412                         if(${PYTHON_LIBPATH} MATCHES "lib64$")
413                                 set(_target_LIB "lib64")
414                         else()
415                                 set(_target_LIB "lib")
416                         endif()
417
418                         # Copy the systems python into the install directory
419                         # Scons copy in tools/Blender.py
420                         # install(CODE "message(\"copying a subset of the systems python...\")")
421                         install(
422                                 DIRECTORY ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
423                                 DESTINATION ${TARGETDIR_VER}/python/${_target_LIB}
424                                 PATTERN ".svn" EXCLUDE
425                                 PATTERN "__pycache__" EXCLUDE               # * any cache *
426                                 PATTERN "distutils" EXCLUDE                 # ./distutils
427                                 PATTERN "lib2to3" EXCLUDE                   # ./lib2to3
428                                 PATTERN "config" EXCLUDE                    # ./config
429                                 PATTERN "config-*" EXCLUDE                  # ./config-*
430                                 PATTERN "site-packages/*" EXCLUDE           # ./site-packages/*
431                                 PATTERN "tkinter" EXCLUDE                   # ./tkinter
432                                 PATTERN "lib-dynload/_tkinter.*" EXCLUDE    # ./lib-dynload/_tkinter.co
433                                 PATTERN "idlelib" EXCLUDE                   # ./idlelib
434                                 PATTERN "test" EXCLUDE                      # ./test
435                                 PATTERN "turtledemo" EXCLUDE                # ./turtledemo
436                                 PATTERN "turtle.py" EXCLUDE                                     # ./turtle.py
437                         )
438
439                         # # doesnt work, todo
440                         # install(CODE "execute_process(COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/ -name '*.so' -exec strip -s {} '\;')")
441                         unset(_target_LIB)
442                 endif()
443         endif()
444 elseif(WIN32)
445
446         install(
447                 FILES ${BLENDER_TEXT_FILES}
448                 DESTINATION ${TARGETDIR}
449         )
450
451         if(WITH_INTERNATIONAL AND (NOT WITH_MINGW64))
452                 install(
453                         FILES ${LIBDIR}/gettext/lib/gnu_gettext.dll
454                         DESTINATION ${TARGETDIR}
455                 )
456
457                 if(NOT CMAKE_CL_64)
458                         install(
459                                 FILES ${LIBDIR}/iconv/lib/iconv.dll
460                                 DESTINATION ${TARGETDIR}
461                         )
462                 endif()
463         endif()
464
465         # plugins in blender 2.6 don't work at the moment.
466         #
467         # install(
468         #       DIRECTORY ${CMAKE_SOURCE_DIR}/release/plugins
469         #       DESTINATION ${TARGETDIR_VER}
470         #       PATTERN ".svn" EXCLUDE
471         # )
472
473         if(WITH_PYTHON)
474                 set_lib_path(PYLIB "python/lib")
475                 install(
476                         FILES ${PYLIB}/python32.dll
477                         DESTINATION ${TARGETDIR}
478                         CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel
479                 )
480
481                 install(
482                         FILES ${PYLIB}/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                 # gettext and png are 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                 endif()
549         endif()
550
551         if(WITH_CODEC_FFMPEG)
552                 install(
553                         FILES
554                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.dll
555                                 ${LIBDIR}/ffmpeg/lib/avformat-53.dll
556                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.dll
557                                 ${LIBDIR}/ffmpeg/lib/avutil-51.dll
558                                 ${LIBDIR}/ffmpeg/lib/swscale-2.dll
559                         DESTINATION ${TARGETDIR}
560                 )
561
562         endif()
563
564         if(WITH_CODEC_SNDFILE)
565                 install(
566                         FILES ${LIBDIR}/sndfile/lib/libsndfile-1.dll
567                         DESTINATION ${TARGETDIR}
568                 )
569         endif()
570
571         if(WITH_OPENAL)
572                 install(
573                         FILES
574                                 ${LIBDIR}/openal/lib/OpenAL32.dll
575                                 ${LIBDIR}/openal/lib/wrap_oal.dll
576                         DESTINATION ${TARGETDIR}
577                 )
578         endif()
579
580         if(WITH_SDL)
581                 if(NOT CMAKE_CL_64)
582                         install(
583                                 FILES ${LIBDIR}/sdl/lib/SDL.dll
584                                 DESTINATION ${TARGETDIR}
585                         )
586                 endif()
587         endif()
588
589         if(NOT CMAKE_CL_64)
590                 install(
591                         FILES ${LIBDIR}/thumbhandler/lib/BlendThumb.dll
592                         DESTINATION ${TARGETDIR}
593                 )
594         endif()
595                 
596         install( # x86 builds can run on x64 Windows, so this is required at all times
597                 FILES ${LIBDIR}/thumbhandler/lib/BlendThumb64.dll
598                 DESTINATION ${TARGETDIR}
599         )       
600
601         if(WITH_OPENIMAGEIO)
602                 if(NOT MINGW)
603                         set_lib_path(OIIOBIN "openimageio/bin")
604                         install(
605                                 FILES
606                                         ${OIIOBIN}/OpenImageIO.dll
607                                 DESTINATION ${TARGETDIR}
608                         )
609                 endif()
610         endif()
611
612 elseif(APPLE)
613
614         # handy install macro to exclude files, we use \$ escape for the "to"
615         # argument when calling so ${BUILD_TYPE} does not get expanded
616         macro(install_dir from to)
617                 install(
618                         DIRECTORY ${from}
619                         DESTINATION ${to}
620                         PATTERN ".svn" EXCLUDE
621                         PATTERN "*.pyc" EXCLUDE
622                         PATTERN "*.pyo" EXCLUDE
623                         PATTERN "*.orig" EXCLUDE
624                         PATTERN "*.rej" EXCLUDE
625                         PATTERN "__pycache__" EXCLUDE
626                         PATTERN "__MACOSX" EXCLUDE
627                         PATTERN ".DS_Store" EXCLUDE
628                 )
629         endmacro()
630
631         set(OSX_APP_SOURCEDIR ${CMAKE_SOURCE_DIR}/source/darwin/blender.app)
632
633         # setup Info.plist
634         execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BLENDER_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
635
636         set_target_properties(blender PROPERTIES
637                 MACOSX_BUNDLE_INFO_PLIST ${OSX_APP_SOURCEDIR}/Contents/Info.plist
638                 MACOSX_BUNDLE_SHORT_VERSION_STRING ${BLENDER_VERSION}
639                 MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION} ${BLENDER_DATE}")
640
641
642         # install release and app files
643         install(
644                 FILES ${BLENDER_TEXT_FILES}
645                 DESTINATION ${TARGETDIR}
646         )
647
648         install(
649                 FILES ${OSX_APP_SOURCEDIR}/Contents/PkgInfo
650                 DESTINATION ${TARGETDIR}/blender.app/Contents
651         )
652
653         install_dir(
654                 ${OSX_APP_SOURCEDIR}/Contents/Resources
655                 \${TARGETDIR}/blender.app/Contents/
656         )
657
658         # python
659         if(WITH_PYTHON AND NOT WITH_PYTHON_MODULE)
660                 # the python zip is first extract as part of the build process,
661                 # and then later installed as part of make install. this is much
662                 # quicker, and means we can easily exclude files on copy
663                 # Not needed for PYTHON_MODULE or WEB_PLUGIN due uses  Pyhon framework
664                 add_custom_target(
665                         extractpyzip
666                         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/python)
667
668                 set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
669
670                 add_custom_command(
671                         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
672                         COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
673                         COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
674                         COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
675                         DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
676
677                 add_dependencies(blender extractpyzip)
678
679                 # copy extracted python files
680                 install_dir(
681                         ${CMAKE_CURRENT_BINARY_DIR}/python
682                         \${TARGETDIR_VER}
683                 )
684
685         endif()
686
687         # install blenderplayer bundle - copy of blender.app above. re-using macros et al
688         # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
689         if(WITH_GAMEENGINE AND WITH_PLAYER)
690                 set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/source/darwin/blenderplayer.app)
691                 set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
692                 set(PLAYER_TARGETDIR_VER ${TARGETDIR}/blenderplayer.app/Contents/MacOS/${BLENDER_VERSION})
693
694
695                 # important to make a clean  install each time else old scripts get loaded.
696                 install(
697                         CODE
698                         "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
699                 )
700
701                 install(
702                         FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
703                         DESTINATION ${TARGETDIR}/blenderplayer.app/Contents
704                 )
705
706                 install_dir(
707                         ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
708                         \${TARGETDIR}/blenderplayer.app/Contents/
709                 )
710
711                 # python
712                 if(WITH_PYTHON)
713                         add_custom_command(
714                                 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python
715                                 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/python/
716                                 COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/python/
717                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${CMAKE_CURRENT_BINARY_DIR}/python/
718                                 DEPENDS ${LIBDIR}/release/${PYTHON_ZIP})
719
720                         # copy extracted python files
721                         install_dir(
722                                 ${CMAKE_CURRENT_BINARY_DIR}/python
723                                 \${PLAYER_TARGETDIR_VER}
724                         )
725                 endif()
726
727         endif()
728 endif()
729
730 # -----------------------------------------------------------------------------
731 # Generic Install, for all targets
732
733
734
735 # install more files specified elsewhere
736 delayed_do_install(${TARGETDIR_VER})
737
738 unset(BLENDER_TEXT_FILES)
739
740
741 # -----------------------------------------------------------------------------
742 # Setup link libs
743
744 add_dependencies(blender makesdna)
745
746 get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
747
748 set(BLENDER_LINK_LIBS
749         ${BLENDER_LINK_LIBS}
750         bf_windowmanager
751         bf_render
752 )
753
754 if(WITH_MOD_FLUID)
755         list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
756 endif()
757
758 if(WITH_CYCLES)
759         list(APPEND BLENDER_LINK_LIBS
760                 cycles_render
761                 cycles_bvh
762                 cycles_device
763                 cycles_kernel
764                 cycles_util
765                 cycles_subd)
766 endif()
767
768 #if(UNIX)
769         # Sort libraries
770         set(BLENDER_SORTED_LIBS
771                 bf_windowmanager
772
773                 bf_editor_space_api
774                 bf_editor_space_action
775                 bf_editor_space_buttons
776                 bf_editor_space_console
777                 bf_editor_space_file
778                 bf_editor_space_graph
779                 bf_editor_space_image
780                 bf_editor_space_info
781                 bf_editor_space_logic
782                 bf_editor_space_nla
783                 bf_editor_space_node
784                 bf_editor_space_outliner
785                 bf_editor_space_script
786                 bf_editor_space_sequencer
787                 bf_editor_space_time
788                 bf_editor_space_userpref
789                 bf_editor_space_view3d
790                 bf_editor_space_clip
791
792                 bf_editor_text
793                 bf_editor_transform
794                 bf_editor_util
795                 bf_editor_uvedit
796                 bf_editor_curve
797                 bf_editor_armature
798                 bf_editor_gpencil
799                 bf_editor_interface
800                 bf_editor_mesh
801                 bf_editor_metaball
802                 bf_editor_object
803                 bf_editor_physics
804                 bf_editor_render
805                 bf_editor_screen
806                 bf_editor_sculpt_paint
807                 bf_editor_sound
808                 bf_editor_animation
809                 bf_editor_datafiles
810
811                 bf_render
812                 bf_intern_opennl
813                 bf_python
814                 bf_python_ext
815                 bf_python_mathutils
816                 bf_python_bmesh
817                 bf_ikplugin
818                 bf_modifiers
819                 bf_bmesh
820                 bf_blenkernel
821                 bf_nodes
822                 bf_gpu
823                 bf_blenloader
824                 bf_imbuf
825                 bf_blenlib
826                 bf_intern_ghost
827                 bf_intern_string
828                 bf_blenpluginapi
829                 bf_avi
830                 bf_imbuf_cineon
831                 bf_imbuf_openexr
832                 bf_imbuf_dds
833                 bf_collada
834                 bf_intern_bsp
835                 bf_intern_bop
836                 bf_intern_decimate
837                 bf_intern_elbeem
838                 bf_intern_ik
839                 bf_intern_memutil
840                 bf_intern_guardedalloc
841                 bf_intern_ctr
842                 bf_intern_utfconv
843                 ge_blen_routines
844                 ge_converter
845                 ge_phys_dummy
846                 ge_phys_bullet
847                 bf_intern_smoke
848                 extern_minilzo
849                 extern_lzma
850                 extern_colamd
851                 ge_logic_ketsji
852                 extern_recastnavigation
853                 ge_phys_common
854                 ge_logic
855                 ge_rasterizer
856                 ge_oglrasterizer
857                 ge_logic_expressions
858                 ge_scenegraph
859                 ge_logic_network
860                 ge_logic_ngnetwork
861                 extern_bullet
862                 ge_logic_loopbacknetwork
863                 bf_intern_moto
864                 extern_openjpeg
865                 extern_redcode
866                 ge_videotex
867                 bf_rna
868                 bf_dna
869                 bf_blenfont
870                 bf_intern_audaspace
871                 bf_intern_mikktspace
872                 bf_intern_dualcon
873                 bf_intern_cycles
874                 cycles_render
875                 cycles_bvh
876                 cycles_device
877                 cycles_kernel
878                 cycles_util
879                 cycles_subd
880         )
881
882         if(WITH_LIBMV)
883                 list(APPEND BLENDER_SORTED_LIBS extern_libmv)
884         endif()
885
886         if(WITH_MOD_CLOTH_ELTOPO)
887                 list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
888         endif()
889
890         if(WITH_BUILTIN_GLEW)
891                 list(APPEND BLENDER_SORTED_LIBS extern_glew)
892         endif()
893
894         if(WITH_BINRELOC)
895                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
896         endif()
897
898         if(WITH_CXX_GUARDEDALLOC)
899                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
900         endif()
901
902         if(WITH_IK_ITASC)
903                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
904         endif()
905
906         if(WITH_CODEC_QUICKTIME)
907                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
908         endif()
909
910         if(WITH_CARVE)
911                 list(APPEND BLENDER_SORTED_LIBS extern_carve)
912         endif()
913
914         if(WITH_GHOST_XDND)
915                 list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
916         endif()
917
918         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
919                 set(REMLIB ${SORTLIB})
920                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
921                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
922                                 set(REMLIB "")
923                         endif()
924                 endforeach()
925                 if(REMLIB)
926                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
927                         list(APPEND REM_MSG ${REMLIB})
928                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
929                 endif()
930         endforeach()
931         if(REM_MSG)
932                 list(SORT REM_MSG)
933                 message(STATUS "Blender Skipping: (${REM_MSG})")
934         endif()
935         target_link_libraries(blender ${BLENDER_SORTED_LIBS})
936
937         unset(SEARCHLIB)
938         unset(SORTLIB)
939         unset(REMLIB)
940         unset(REM_MSG)
941
942 #else()
943 #       target_link_libraries(blender ${BLENDER_LINK_LIBS})
944 #endif()
945
946 setup_liblinks(blender)