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