ac38540631dd1d7914ac9610eaf6f2df0da5c714
[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 endif()
79
80 if(WITH_GAMEENGINE)
81         blender_include_dirs(
82                 ../kernel/gen_messaging
83                 ../kernel/gen_system
84         )
85
86         add_definitions(-DWITH_GAMEENGINE)
87 endif()
88
89 if(NOT WITH_SDL)
90         add_definitions(-DDISABLE_SDL)
91 endif()
92
93 if(WITH_BINRELOC)
94         add_definitions(-DWITH_BINRELOC)
95         blender_include_dirs(${BINRELOC_INC})
96 endif()
97
98 # Setup the exe sources and buildinfo
99 set(SRC
100         creator.c
101 )
102
103 if(WIN32 AND NOT UNIX)
104         list(APPEND SRC
105                 ../icons/winblender.rc
106         )
107 endif()
108
109 if(WITH_BUILDINFO)
110         # --------------------------------------------------------------------------
111         # These defines could all be moved into the header below
112         string(REPLACE " " "\ " BUILDINFO_CFLAGS "${CMAKE_C_FLAGS}")
113         string(REPLACE " " "\ " BUILDINFO_CXXFLAGS "${CMAKE_CXX_FLAGS}")
114         string(REPLACE " " "\ " BUILDINFO_LINKFLAGS "${PLATFORM_LINKFLAGS}")
115         add_definitions(
116                 # # define in header now, else these get out of date on rebuilds.
117                 # -DBUILD_DATE="${BUILD_DATE}"
118                 # -DBUILD_TIME="${BUILD_TIME}"
119                 # -DBUILD_REV="${BUILD_REV}"
120                 -DWITH_BUILDINFO_HEADER # alternative to lines above
121                 -DBUILD_PLATFORM="${CMAKE_SYSTEM_NAME}"
122                 -DBUILD_TYPE="${CMAKE_BUILD_TYPE}"
123                 -DBUILD_CFLAGS="${BUILDINFO_CFLAGS}"
124                 -DBUILD_CXXFLAGS="${BUILDINFO_CXXFLAGS}"
125                 -DBUILD_LINKFLAGS="${BUILDINFO_LINKFLAGS}"
126                 -DBUILD_SYSTEM="CMake"
127         )
128
129         # --------------------------------------------------------------------------
130         # write header for values that change each build
131         # note, generaed file is in build dir's source/creator
132         #       except when used as an include path.
133
134         # include the output directory, where the buildinfo.h file is generated
135         include_directories(${CMAKE_BINARY_DIR}/source/creator)
136
137         # a custom target that is always built
138         add_custom_target(buildinfo ALL
139                 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h)
140
141         # creates svnheader.h using cmake script
142         add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h
143                 COMMAND ${CMAKE_COMMAND}
144                 -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
145                 -P ${CMAKE_SOURCE_DIR}/build_files/cmake/buildinfo.cmake)
146
147         # buildinfo.h is a generated file
148         set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/buildinfo.h
149                 PROPERTIES GENERATED TRUE
150                 HEADER_FILE_ONLY TRUE)
151                 
152         # add deps below, after adding blender
153         # -------------- done with header values.
154
155         list(APPEND SRC
156                 buildinfo.c
157         )
158 endif()
159
160 # message(STATUS "Configuring blender")
161 if(WITH_PYTHON_MODULE)
162         add_definitions(-DWITH_PYTHON_MODULE)
163
164         # creates ./bin/bpy.so which can be imported as a python module.
165         add_library(blender SHARED ${SRC})
166         set_target_properties(
167                 blender
168                 PROPERTIES
169                          PREFIX ""
170                          OUTPUT_NAME bpy
171                          LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/
172         )
173 else()
174         add_executable(blender ${EXETYPE} ${SRC})
175 endif()
176
177 if(WITH_BUILDINFO)
178         # explicitly say that the executable depends on the buildinfo
179         add_dependencies(blender buildinfo)
180 endif()
181
182 # Post build steps for bundling/packaging.
183
184 set(TARGETDIR ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
185
186 if(WITH_INSTALL)
187
188         if(UNIX)
189                 add_custom_command(TARGET blender
190                         POST_BUILD
191                         MAIN_DEPENDENCY blender
192                         #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/plugins ${TARGETDIR}/
193                         #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/text/* ${TARGETDIR}/
194                 )
195         endif()
196
197         if(UNIX AND NOT APPLE)
198                 
199                 # Local installation, "make install" can be done after this optionally
200                 
201                 add_custom_command(
202                         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
203                         COMMAND rm -Rf ${TARGETDIR}/${BLENDER_VERSION}
204                         COMMAND mkdir ${TARGETDIR}/${BLENDER_VERSION}/
205                         COMMAND cp ${CMAKE_SOURCE_DIR}/release/bin/.blender/.bfont.ttf ${TARGETDIR}/${BLENDER_VERSION}/
206                 )
207         
208                 if(WITH_INTERNATIONAL)
209                         add_custom_command(
210                                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
211                                 COMMAND cp ${CMAKE_SOURCE_DIR}/release/bin/.blender/.Blanguages ${TARGETDIR}/${BLENDER_VERSION}/
212                                 COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale ${TARGETDIR}/${BLENDER_VERSION}/
213                         )
214                 endif()
215         
216                 if(WITH_PYTHON)
217                         add_custom_command(
218                                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
219                                 COMMENT "copying blender scripts..."
220                                 COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/${BLENDER_VERSION}/
221                                 COMMAND find ${TARGETDIR} -name '*.py[co]' -prune -exec rm -rf {} '\;'
222                                 COMMAND find ${TARGETDIR} -name '__pycache__' -exec rmdir {} '+'
223                         )
224                         if(WITH_PYTHON_INSTALL)
225                                 # Copy the systems python into the install directory
226                                 # Scons copy in tools/Blender.py
227                                 add_custom_command(
228                                         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
229                                         COMMENT "copying a subset of the systems python..."
230
231                                         COMMAND mkdir ${TARGETDIR}/${BLENDER_VERSION}/python # PYTHONPATH and PYTHONHOME is set here
232                                         COMMAND mkdir ${TARGETDIR}/${BLENDER_VERSION}/python/lib/
233                                         COMMAND cp -R ${PYTHON_LIBPATH}/python${PYTHON_VERSION} ${TARGETDIR}/${BLENDER_VERSION}/python/lib/
234
235                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/distutils
236                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/lib2to3
237                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/idlelib
238                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/tkinter
239                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/config
240
241                                         COMMAND rm -rf ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/site-packages
242                                         COMMAND mkdir ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/site-packages  # python needs it.
243
244                                         COMMAND rm -f ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION}/lib-dynload/_tkinter.so
245                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -type d -name 'test' -prune -exec rm -rf {} '\;'
246                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -type d -name 'turtledemo' -prune -exec rm -rf {} '\;'
247                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -type d -name 'config-*' -prune -exec rm -rf {} '\;'
248                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -name '*.py[co]' -exec rm -rf {} '\;'
249                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -name '__pycache__' -exec rmdir {} '+'
250                                         COMMAND find ${TARGETDIR}/${BLENDER_VERSION}/python/lib/python${PYTHON_VERSION} -name '*.so' -exec strip -s {} '\;'
251                                 )
252                         endif()
253                 endif()
254           
255                 add_custom_command(
256                         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
257                         COMMAND find ${TARGETDIR} -name .svn -prune -exec rm -rf {} "\;"
258                 )
259         
260         
261                 # Above we bundle a portable distribution in ./bin
262                 # This is an optional "make install" which installs blender on the system.
263                 install(
264                         PROGRAMS ${TARGETDIR}/blender
265                         DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
266                 )
267
268                 if(WITH_GAMEENGINE AND WITH_PLAYER)
269                         install(
270                                 PROGRAMS ${TARGETDIR}/blenderplayer
271                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
272                         )
273                 endif()
274
275                 install(
276                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
277                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
278                 )
279                 install(
280                         FILES ${CMAKE_SOURCE_DIR}/release/freedesktop/icons/scalable/blender.svg
281                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps
282                 )
283                 install(
284                         PROGRAMS ${CMAKE_SOURCE_DIR}/release/bin/blender-thumbnailer.py
285                         DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
286                 )
287                 install(
288                         FILES ${CMAKE_SOURCE_DIR}/doc/manpage/blender.1
289                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
290                 )
291                 install(
292                         DIRECTORY ${CMAKE_SOURCE_DIR}/release/text/
293                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/doc/blender
294                         PATTERN ".svn" EXCLUDE
295                 )
296                 install(
297                         DIRECTORY ${CMAKE_SOURCE_DIR}/release/scripts/
298                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/blender/${BLENDER_VERSION}/scripts
299                         PATTERN ".svn" EXCLUDE
300                         PATTERN "*.pyc" EXCLUDE
301                         PATTERN "__pycache__" EXCLUDE
302                 )
303                 install(
304                         DIRECTORY ${CMAKE_SOURCE_DIR}/release/datafiles/brushicons/
305                         DESTINATION ${CMAKE_INSTALL_PREFIX}/share/blender/${BLENDER_VERSION}/datafiles/brushicons
306                         PATTERN ".svn" EXCLUDE
307                 )
308                 if(WITH_INTERNATIONAL)
309                         install(
310                                 DIRECTORY ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale/
311                                 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/blender/${BLENDER_VERSION}/datafiles/locale
312                                 PATTERN ".svn" EXCLUDE
313                         )
314                 endif()
315                 
316                 # end "make install"
317         
318         elseif(WIN32)
319                 # notice 'xcopy /Y /H' on .bfont.ttf, this is needed when building over samba
320                 add_custom_command(TARGET blender
321                         POST_BUILD
322                         MAIN_DEPENDENCY blender
323                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\"
324                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\\scripts\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\\scripts\"
325                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\\config\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\\config\"
326                         COMMAND if not exist \"${TARGETDIR}\\plugins\" mkdir \"${TARGETDIR}\\plugins\"
327                         COMMAND xcopy /Y /H \"${CMAKE_SOURCE_DIR}\\release\\bin\\.blender\\.bfont.ttf\" \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\\"
328                         COMMAND xcopy /E /Y \"${CMAKE_SOURCE_DIR}\\release\\scripts\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\scripts\\\"
329                         COMMAND xcopy /E /Y \"${CMAKE_SOURCE_DIR}\\release\\plugins\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\plugins\\\"
330                         COMMAND copy /Y \"${CMAKE_SOURCE_DIR}\\release\\text\\*.*\" \"${TARGETDIR}\\\"
331                 )
332         
333                 if(CMAKE_CL_64)
334                         # gettext and png are statically linked on win64
335                         add_custom_command(TARGET blender
336                                 POST_BUILD
337                                 MAIN_DEPENDENCY blender
338                                 COMMAND copy /Y \"${LIBDIR}\\zlib\\lib\\zlib.dll\" \"${TARGETDIR}\\\"
339                         )
340                 else()
341                         add_custom_command(TARGET blender
342                                 POST_BUILD
343                                 MAIN_DEPENDENCY blender
344                                 COMMAND copy /Y \"${LIBDIR}\\gettext\\lib\\gnu_gettext.dll\" \"${TARGETDIR}\\\"
345                                 COMMAND copy /Y \"${LIBDIR}\\png\\lib\\libpng.dll\" \"${TARGETDIR}\\\"
346                                 COMMAND copy /Y \"${LIBDIR}\\zlib\\lib\\zlib.dll\" \"${TARGETDIR}\\\"
347                         )
348                 endif()
349                 
350                 
351                 if(MSVC)
352                         add_custom_command(TARGET blender
353                                 POST_BUILD
354                                 MAIN_DEPENDENCY blender
355                                 COMMAND copy /Y \"${LIBDIR}\\pthreads\\lib\\pthreadVC2.dll\" \"${TARGETDIR}\\\"
356                         )
357                 else()
358                         add_custom_command(TARGET blender
359                                 POST_BUILD
360                                 MAIN_DEPENDENCY blender
361                                 COMMAND copy /Y \"${LIBDIR}\\pthreads\\lib\\pthreadGC2.dll\" \"${TARGETDIR}\\\"
362                         )
363                 endif()
364
365                 if(WITH_PYTHON)
366                         # note, as far as python is concerned 'RelWithDebInfo' is not debug since its without debug flags.
367                         if(NOT CMAKE_BUILD_TYPE) # hack: with multi-configuration generator this is "", so for now copy both python32.dll/zip and python32_d.dll/zip
368                                 add_custom_command(TARGET blender
369                                         POST_BUILD
370                                         MAIN_DEPENDENCY blender
371                                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\"
372                                         COMMAND if \"$(ConfigurationName)\" == \"\" copy /Y \"${LIBDIR}\\python\\lib\\python32.dll\" \"${TARGETDIR}\\\"
373                                         COMMAND if \"$(ConfigurationName)\" == \"\" xcopy /E /Y \"${LIBDIR}\\release\\python32\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
374                                         COMMAND if \"$(ConfigurationName)\" == \"Debug\" copy /Y \"${LIBDIR}\\python\\lib\\python32_d.dll\" \"${TARGETDIR}\\\"
375                                         COMMAND if \"$(ConfigurationName)\" == \"Debug\" xcopy /E /Y \"${LIBDIR}\\release\\python32_d\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
376                                         COMMAND if \"$(ConfigurationName)\" == \"RelWithDebInfo\" copy /Y \"${LIBDIR}\\python\\lib\\python32.dll\" \"${TARGETDIR}\\\"
377                                         COMMAND if \"$(ConfigurationName)\" == \"RelWithDebInfo\" xcopy /E /Y \"${LIBDIR}\\release\\python32\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
378                                         COMMAND if \"$(ConfigurationName)\" == \"Release\" copy /Y \"${LIBDIR}\\python\\lib\\python32.dll\" \"${TARGETDIR}\\\"
379                                         COMMAND if \"$(ConfigurationName)\" == \"Release\" xcopy /E /Y \"${LIBDIR}\\release\\python32\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
380                                         COMMAND if \"$(ConfigurationName)\" == \"MinSizeRel\" copy /Y \"${LIBDIR}\\python\\lib\\python32.dll\" \"${TARGETDIR}\\\"
381                                         COMMAND if \"$(ConfigurationName)\" == \"MinSizeRel\" xcopy /E /Y \"${LIBDIR}\\release\\python32\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
382                                 )
383                         else()
384                                 if(CMAKE_BUILD_TYPE STREQUAL Debug)
385                                         add_custom_command(TARGET blender
386                                                 POST_BUILD
387                                                 MAIN_DEPENDENCY blender
388                                                 COMMAND copy /Y \"${LIBDIR}\\python\\lib\\python32_d.dll\" \"${TARGETDIR}\\\"
389                                                 COMMAND xcopy /E /Y \"${LIBDIR}\\release\\python32_d\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
390                                         )
391                                 else()
392                                         add_custom_command(TARGET blender
393                                                 POST_BUILD
394                                                 MAIN_DEPENDENCY blender
395                                                 COMMAND copy /Y \"${LIBDIR}\\python\\lib\\python32.dll\" \"${TARGETDIR}\\\"
396                                                 COMMAND xcopy /E /Y \"${LIBDIR}\\release\\python32\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\python\\lib\\\"
397                                         )
398                                 endif()
399                         endif()
400                 endif()
401
402                 if(WITH_INTERNATIONAL)
403                         if(CMAKE_CL_64)
404                                 # iconv is statically linked on win64
405                                 add_custom_command(TARGET blender
406                                         POST_BUILD
407                                         MAIN_DEPENDENCY blender
408                                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\"
409                                         COMMAND copy /Y \"${CMAKE_SOURCE_DIR}\\release\\bin\\.blender\\.Blanguages\" \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\\" 
410                                         COMMAND xcopy /E /Y \"${CMAKE_SOURCE_DIR}\\release\\bin\\.blender\\locale\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\\\"
411                                 )
412                         else()
413                                 add_custom_command(TARGET blender
414                                         POST_BUILD
415                                         MAIN_DEPENDENCY blender
416                                         COMMAND copy /Y \"${LIBDIR}\\iconv\\lib\\iconv.dll\" \"${TARGETDIR}\\\"
417                                         COMMAND if not exist \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\" mkdir \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\"
418                                         COMMAND copy /Y \"${CMAKE_SOURCE_DIR}\\release\\bin\\.blender\\.Blanguages\" \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\\" 
419                                         COMMAND xcopy /E /Y \"${CMAKE_SOURCE_DIR}\\release\\bin\\.blender\\locale\\*.*\" \"${TARGETDIR}\\${BLENDER_VERSION}\\config\\locale\\\"
420                                 )
421                         endif()
422                 endif()
423
424                 if(WITH_CODEC_FFMPEG)
425                         add_custom_command(TARGET blender
426                                 POST_BUILD
427                                 MAIN_DEPENDENCY blender
428                                 COMMAND copy /Y \"${LIBDIR}\\ffmpeg\\lib\\avcodec-52.dll\" \"${TARGETDIR}\\\"
429                                 COMMAND copy /Y \"${LIBDIR}\\ffmpeg\\lib\\avformat-52.dll\" \"${TARGETDIR}\\\"
430                                 COMMAND copy /Y \"${LIBDIR}\\ffmpeg\\lib\\avdevice-52.dll\" \"${TARGETDIR}\\\"
431                                 COMMAND copy /Y \"${LIBDIR}\\ffmpeg\\lib\\avutil-50.dll\" \"${TARGETDIR}\\\"
432                                 COMMAND copy /Y \"${LIBDIR}\\ffmpeg\\lib\\swscale-0.dll\" \"${TARGETDIR}\\\"
433                         )
434                 endif()
435
436                 if(WITH_CODEC_SNDFILE)
437                         add_custom_command(TARGET blender
438                                 POST_BUILD
439                                 MAIN_DEPENDENCY blender
440                                 COMMAND copy /Y \"${LIBDIR}\\sndfile\\lib\\libsndfile-1.dll\" \"${TARGETDIR}\\\"
441                         )
442                 endif()
443
444                 if(WITH_OPENAL)
445                         add_custom_command(TARGET blender
446                                 POST_BUILD
447                                 MAIN_DEPENDENCY blender
448                                 COMMAND copy /Y \"${LIBDIR}\\openal\\lib\\OpenAL32.dll\" \"${TARGETDIR}\\\"
449                                 COMMAND copy /Y \"${LIBDIR}\\openal\\lib\\wrap_oal.dll\" \"${TARGETDIR}\\\"
450
451                         )
452                 endif()
453
454                 if(WITH_SDL)
455                         if(NOT CMAKE_CL_64)
456                                 add_custom_command(TARGET blender
457                                         POST_BUILD
458                                         MAIN_DEPENDENCY blender
459                                         COMMAND copy /Y \"${LIBDIR}\\sdl\\lib\\SDL.dll\" \"${TARGETDIR}\\\"
460                                 )
461                         endif()
462                 endif()
463
464         elseif(APPLE)
465                 set(SOURCEDIR ${CMAKE_SOURCE_DIR}/source/darwin/blender.app)
466                 set(SOURCEINFO ${SOURCEDIR}/Contents/Info.plist)
467                 set(TARGETINFO ${TARGETDIR}/blender.app/Contents/Info.plist)
468
469                 add_custom_command(
470                         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
471                         COMMAND cp -Rf ${SOURCEINFO} ${TARGETDIR}/blender.app/Contents/
472                         COMMAND cp -Rf ${SOURCEDIR}/Contents/PkgInfo ${TARGETDIR}/blender.app/Contents/
473                         COMMAND cp -Rf ${SOURCEDIR}/Contents/Resources ${TARGETDIR}/blender.app/Contents/
474                         COMMAND cat ${SOURCEINFO} | sed s/VERSION/${BLENDER_VERSION}${BLENDER_VERSION_CHAR}/ | sed s/DATE/`date +'%Y-%b-%d'`/ > ${TARGETINFO}
475                         COMMAND rm -Rf ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}
476                         COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}
477                         COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/datafiles/
478                         COMMAND cp ${CMAKE_SOURCE_DIR}/release/bin/.blender/.bfont.ttf ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/datafiles/
479                 )
480           
481                 if(WITH_INTERNATIONAL)
482                         add_custom_command(
483                                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
484                                 COMMAND cp ${CMAKE_SOURCE_DIR}/release/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/datafiles/
485                                 COMMAND cp -Rf ${CMAKE_SOURCE_DIR}/release/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/datafiles/
486                         )
487                 endif()
488           
489                 if(WITH_PYTHON)
490                         set(PYTHON_ZIP "python_${CMAKE_OSX_ARCHITECTURES}.zip")
491                         add_custom_command(
492                                 TARGET blender POST_BUILD MAIN_DEPENDENCY blender
493                                 COMMAND cp -Rf ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/
494                                 COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/python/
495                                 COMMAND unzip -q ${LIBDIR}/release/${PYTHON_ZIP} -d ${TARGETDIR}/blender.app/Contents/MacOS/${BLENDER_VERSION}/python/
496                                 COMMAND find ${TARGETDIR}/blender.app -name '*.py[co]' -prune -exec rm -rf {} '\;'
497                                 COMMAND find ${TARGETDIR}/blender.app -name '__pycache__' -exec rmdir {} '+'
498                         )
499                 endif()   
500         
501                 add_custom_command(
502                         TARGET blender POST_BUILD MAIN_DEPENDENCY blender       
503                         COMMAND find ${TARGETDIR}/blender.app -name .DS_Store -prune -exec rm -rf {} "\;"
504                         COMMAND find ${TARGETDIR}/blender.app -name .svn -prune -exec rm -rf {} "\;"
505                         COMMAND find ${TARGETDIR}/blender.app -name __MACOSX -prune -exec rm -rf {} "\;"
506                 )
507         endif()
508
509 endif()
510
511 add_dependencies(blender makesdna)
512
513 get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
514
515 set(BLENDER_LINK_LIBS bf_nodes ${BLENDER_LINK_LIBS} bf_windowmanager bf_render)
516
517 if(WITH_MOD_FLUID)
518         list(APPEND BLENDER_LINK_LIBS bf_intern_elbeem)
519 endif()
520
521
522 #if(UNIX)
523         # Sort libraries
524         set(BLENDER_SORTED_LIBS
525                 bf_windowmanager
526
527                 bf_editor_space_api
528                 bf_editor_space_action
529                 bf_editor_space_buttons
530                 bf_editor_space_console
531                 bf_editor_space_file
532                 bf_editor_space_graph
533                 bf_editor_space_image
534                 bf_editor_space_info
535                 bf_editor_space_logic
536                 bf_editor_space_nla
537                 bf_editor_space_node
538                 bf_editor_space_outliner
539                 bf_editor_space_script
540                 bf_editor_space_sequencer
541                 bf_editor_space_sound
542                 bf_editor_space_time
543                 bf_editor_space_userpref
544                 bf_editor_space_view3d
545
546                 bf_editor_text
547                 bf_editor_transform
548                 bf_editor_util
549                 bf_editor_uvedit
550                 bf_editor_curve
551                 bf_editor_armature
552                 bf_editor_gpencil
553                 bf_editor_interface
554                 bf_editor_mesh
555                 bf_editor_metaball
556                 bf_editor_object
557                 bf_editor_physics
558                 bf_editor_render
559                 bf_editor_screen
560                 bf_editor_sculpt_paint
561                 bf_editor_sound
562                 bf_editor_animation
563                 bf_editor_datafiles
564
565                 bf_render 
566                 bf_intern_opennl 
567                 bf_python 
568                 bf_python_ext 
569                 bf_ikplugin
570                 bf_modifiers
571                 bf_blenkernel
572                 bf_nodes
573                 bf_gpu
574                 bf_blenloader
575                 bf_blenlib
576                 bf_intern_ghost
577                 bf_intern_string
578                 bf_blenpluginapi 
579                 bf_imbuf 
580                 bf_avi 
581                 bf_imbuf_cineon 
582                 bf_imbuf_openexr 
583                 bf_imbuf_dds
584                 bf_readblenfile
585                 bf_collada
586                 bf_intern_bsp 
587                 bf_intern_bop 
588                 bf_gen_system 
589                 bf_intern_decimate 
590                 bf_intern_elbeem 
591                 bf_intern_ik 
592                 bf_intern_memutil 
593                 bf_intern_guardedalloc 
594                 bf_intern_ctr 
595                 ge_blen_routines 
596                 ge_converter 
597                 ge_phys_dummy
598                 ge_phys_bullet 
599                 bf_intern_smoke
600                 extern_minilzo
601                 extern_lzma
602                 ge_logic_ketsji 
603                 ge_phys_common
604                 ge_logic 
605                 ge_rasterizer 
606                 ge_oglrasterizer 
607                 ge_logic_expressions 
608                 ge_scenegraph 
609                 ge_logic_network 
610                 bf_gen_system
611                 bf_python # duplicate for BPY_driver_exec
612                 ge_logic_ngnetwork 
613                 extern_bullet 
614                 ge_logic_loopbacknetwork 
615                 bf_intern_moto 
616                 extern_glew
617                 extern_openjpeg
618                 extern_redcode
619                 ge_videotex
620                 bf_rna
621                 bf_dna
622                 bf_blenfont
623                 bf_intern_audaspace
624                 bf_intern_mikktspace
625         )
626
627         if(WITH_BINRELOC)
628                 list(APPEND BLENDER_SORTED_LIBS extern_binreloc)
629         endif()
630
631         if(WITH_CXX_GUARDEDALLOC)
632                 list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
633         endif()
634
635         if(WITH_IK_ITASC)
636                 list(APPEND BLENDER_SORTED_LIBS bf_intern_itasc)
637         endif()
638
639         if(WITH_CODEC_QUICKTIME)
640                 list(APPEND BLENDER_SORTED_LIBS bf_quicktime)
641         endif()
642
643         foreach(SORTLIB ${BLENDER_SORTED_LIBS})
644                 set(REMLIB ${SORTLIB})
645                 foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
646                         if(${SEARCHLIB} STREQUAL ${SORTLIB})
647                                 set(REMLIB "")
648                         endif()
649                 endforeach()
650                 if(REMLIB)
651                         # message(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
652                         list(APPEND REM_MSG ${REMLIB})
653                         list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
654                 endif()
655         endforeach()
656         if(REM_MSG)
657                 list(SORT REM_MSG)
658                 message(STATUS "Blender Skipping: (${REM_MSG})")
659         endif()
660         target_link_libraries(blender ${BLENDER_SORTED_LIBS})
661 #else()
662 #       target_link_libraries(blender ${BLENDER_LINK_LIBS})
663 #endif()
664
665 setup_liblinks(blender)