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