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