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