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