copy the systems python to the install dir for re-distrobution (non-osx unix), remove...
[blender.git] / source / creator / CMakeLists.txt
1 # $Id$
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 INCLUDE_DIRECTORIES(../../intern/guardedalloc
30   ../blender/blenlib
31   ../blender/blenkernel
32   ../blender/editors/include
33   ../blender/makesrna
34   ../blender/makesrna/intern
35   ../blender/nodes
36   ../blender/include
37   ../blender/blenloader
38   ../blender/imbuf
39   ../blender/renderconverter
40   ../blender/render/extern/include
41   ../blender/makesdna
42   ../blender/gpu
43   ../blender/windowmanager
44   ../kernel/gen_messaging
45   ../kernel/gen_system
46   ../../extern/glew/include
47 )
48
49
50
51 IF(WITH_QUICKTIME)
52   ADD_DEFINITIONS(-DWITH_QUICKTIME)
53 ENDIF(WITH_QUICKTIME)
54
55 IF(WITH_OPENEXR)
56   ADD_DEFINITIONS(-DWITH_OPENEXR)
57 ENDIF(WITH_OPENEXR)
58
59 IF(WITH_PYTHON)
60   INCLUDE_DIRECTORIES(../blender/python)
61 ELSE(WITH_PYTHON)
62   ADD_DEFINITIONS(-DDISABLE_PYTHON)
63 ENDIF(WITH_PYTHON)
64
65 IF(NOT WITH_SDL)
66   ADD_DEFINITIONS(-DDISABLE_SDL)
67 ENDIF(NOT WITH_SDL)
68
69 IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
70   ADD_DEFINITIONS(-DWITH_BINRELOC)
71   INCLUDE_DIRECTORIES(${BINRELOC_INC})
72 ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
73
74 MESSAGE(STATUS "Configuring blender")
75
76 IF(WIN32)
77   ADD_EXECUTABLE(blender ${EXETYPE} creator.c ../icons/winblender.rc)
78 ELSE(WIN32)
79   ADD_EXECUTABLE(blender ${EXETYPE} creator.c)
80 ENDIF(WIN32)
81
82
83 # Post build steps for bundling/packaging.
84
85 SET(TARGETDIR ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
86
87 IF(WITH_INSTALL)
88
89   IF(UNIX)
90     ADD_CUSTOM_COMMAND(TARGET blender
91       POST_BUILD
92       MAIN_DEPENDENCY blender
93       #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/plugins ${TARGETDIR}/
94       #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/text/* ${TARGETDIR}/
95     )
96   ENDIF(UNIX)
97
98   IF(UNIX AND NOT APPLE)
99     ADD_CUSTOM_COMMAND(
100       TARGET blender POST_BUILD MAIN_DEPENDENCY blender
101       COMMAND rm -Rf ${TARGETDIR}/.blender
102       COMMAND mkdir ${TARGETDIR}/.blender/
103       COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.bfont.ttf ${TARGETDIR}/.blender/
104     )
105     
106     IF(WITH_INTERNATIONAL)
107       ADD_CUSTOM_COMMAND(
108         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
109         COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/.blender/
110         COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/.blender/
111       )
112     ENDIF(WITH_INTERNATIONAL)
113     
114     IF(WITH_PYTHON)
115       ADD_CUSTOM_COMMAND(
116         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
117         COMMENT "copying blender scripts..."
118         COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/ui ${TARGETDIR}/.blender/
119         COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/io ${TARGETDIR}/.blender/
120         COMMAND find ${TARGETDIR} -name "*.py?" -prune -exec rm -rf {} "\;"
121       )
122       
123       # Copy the systems python into the install directory
124       ADD_CUSTOM_COMMAND(
125         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
126         COMMENT "copying a subset of the systems python..."
127         
128         COMMAND mkdir ${TARGETDIR}/.blender/python # PYTHONPATH and PYTHONHOME is set here
129         COMMAND mkdir ${TARGETDIR}/.blender/python/lib/
130         COMMAND cp -R ${PYTHON_LIBPATH}/python${PYTHON_VERSION} ${TARGETDIR}/.blender/python/lib/
131         
132         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/distutils
133         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/lib2to3
134         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/idlelib
135         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/tkinter
136         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/config
137         
138         COMMAND rm -rf ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/site-packages
139         COMMAND mkdir ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/site-packages    # python needs it.
140
141         COMMAND rm ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION}/lib-dynload/_tkinter.so
142         COMMAND find ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION} -name "test" -prune -exec rm -rf {} "\;"
143         COMMAND find ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION} -name "*.py?" -exec rm -rf {} "\;"
144         COMMAND find ${TARGETDIR}/.blender/python/lib/python${PYTHON_VERSION} -name "*.so"-exec strip -s {} "\;"
145       )
146      
147     ENDIF(WITH_PYTHON)
148       
149     ADD_CUSTOM_COMMAND(
150       TARGET blender POST_BUILD MAIN_DEPENDENCY blender
151       COMMAND find ${TARGETDIR} -name .svn -prune -exec rm -rf {} "\;"
152     )
153     
154   ENDIF(UNIX AND NOT APPLE)
155
156   IF(APPLE)
157     SET(SOURCEDIR ${CMAKE_SOURCE_DIR}/source/darwin/blender.app)
158     SET(SOURCEINFO ${SOURCEDIR}/Contents/Info.plist)
159     SET(TARGETINFO ${TARGETDIR}/blender.app/Contents/Info.plist)
160
161     ADD_CUSTOM_COMMAND(
162       TARGET blender POST_BUILD MAIN_DEPENDENCY blender
163       COMMAND cp -R ${SOURCEINFO} ${TARGETDIR}/blender.app/Contents/
164       COMMAND cp -R ${SOURCEDIR}/Contents/PkgInfo ${TARGETDIR}/blender.app/Contents/
165       COMMAND cp -R ${SOURCEDIR}/Contents/Resources ${TARGETDIR}/blender.app/Contents/
166       COMMAND cat ${SOURCEINFO} | sed s/VERSION/`cat ${CMAKE_SOURCE_DIR}/release/VERSION`/ | sed s/DATE/`date +'%Y-%b-%d'`/ > ${TARGETINFO}
167       COMMAND rm -Rf ${TARGETDIR}/blender.app/Contents/MacOS/.blender
168       COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
169       COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.bfont.ttf ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
170     )
171       
172     IF(WITH_INTERNATIONAL)
173       ADD_CUSTOM_COMMAND(
174         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
175         COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
176         COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/Resources/
177         COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
178         COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/Resources/
179       )
180     ENDIF(WITH_INTERNATIONAL)
181       
182     IF(WITH_PYTHON)
183       ADD_CUSTOM_COMMAND(
184         TARGET blender POST_BUILD MAIN_DEPENDENCY blender
185         COMMAND cp -Rf ${CMAKE_SOURCE_DIR}/release/ui ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
186         COMMAND cp -Rf ${CMAKE_SOURCE_DIR}/release/io ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
187         COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/.blender/python/
188         COMMAND unzip -q ${LIBDIR}/release/python.zip -d ${TARGETDIR}/blender.app/Contents/MacOS/.blender/python/
189         COMMAND find ${TARGETDIR}/blender.app -name "*.py?" -prune -exec rm -rf {} "\;"
190       )
191     ENDIF(WITH_PYTHON)      
192     
193     ADD_CUSTOM_COMMAND(
194       TARGET blender POST_BUILD MAIN_DEPENDENCY blender    
195       COMMAND find ${TARGETDIR}/blender.app -name .DS_Store -prune -exec rm -rf {} "\;"
196       COMMAND find ${TARGETDIR}/blender.app -name .svn -prune -exec rm -rf {} "\;"
197     )
198   ENDIF(APPLE)
199
200   IF(WIN32)
201     FILE(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} WIN_SOURCE_DIR)
202     
203     ADD_CUSTOM_COMMAND(TARGET blender
204       POST_BUILD
205       MAIN_DEPENDENCY blender
206       COMMAND if not exist \"${TARGETDIR}\\.blender\" mkdir \"${TARGETDIR}\\.blender\"
207       COMMAND if not exist \"${TARGETDIR}\\.blender\\locale\" mkdir \"${TARGETDIR}\\.blender\\locale\"
208       COMMAND if not exist \"${TARGETDIR}\\.blender\\ui\" mkdir \"${TARGETDIR}\\.blender\\ui\"
209       COMMAND if not exist \"${TARGETDIR}\\.blender\\io\" mkdir \"${TARGETDIR}\\.blender\\io\"
210       COMMAND if not exist \"${TARGETDIR}\\plugins\" mkdir \"${TARGETDIR}\\plugins\"
211       COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.Blanguages\" \"${TARGETDIR}\\.blender\\\" 
212       COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.bfont.ttf\" \"${TARGETDIR}\\.blender\\\"
213       COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\locale\\*.*\" \"${TARGETDIR}\\.blender\\locale\"
214       COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\scripts\\*.*\" \"${TARGETDIR}\\.blender\\scripts\"
215       COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\ui\\*.*\" \"${TARGETDIR}\\.blender\\ui\"
216       COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\io\\*.*\" \"${TARGETDIR}\\.blender\\io\"
217       COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\plugins\\*.*\" \"${TARGETDIR}\\plugins\"
218       COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\text\\*.*\" \"${TARGETDIR}\"
219       COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\windows\\extra\\python26.zip\" \"${TARGETDIR}\\\"
220     )
221     
222     FILE(TO_NATIVE_PATH "${LIBDIR}" WIN_LIBDIR)
223     
224     ADD_CUSTOM_COMMAND(TARGET blender
225       POST_BUILD
226       MAIN_DEPENDENCY blender
227       COMMAND copy /Y \"${WIN_LIBDIR}\\release\\python31.zip\" \"${TARGETDIR}\\\"
228       COMMAND copy /Y \"${WIN_LIBDIR}\\gettext\\lib\\gnu_gettext.dll\" \"${TARGETDIR}\\\"
229       COMMAND copy /Y \"${WIN_LIBDIR}\\png\\lib\\libpng.dll\" \"${TARGETDIR}\\\"
230       COMMAND copy /Y \"${WIN_LIBDIR}\\sdl\\lib\\SDL.dll\" \"${TARGETDIR}\\\"
231       COMMAND copy /Y \"${WIN_LIBDIR}\\zlib\\lib\\zlib.dll\" \"${TARGETDIR}\\\"
232       COMMAND copy /Y \"${WIN_LIBDIR}\\tiff\\lib\\libtiff.dll\" \"${TARGETDIR}\\\"
233       COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python31.dll\" \"${TARGETDIR}\\\"
234       COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python31_d.dll\" \"${TARGETDIR}\\\"
235       COMMAND copy /Y \"${WIN_LIBDIR}\\pthreads\\lib\\pthreadVC2.dll\" \"${TARGETDIR}\\\"
236       COMMAND copy /Y \"${WIN_LIBDIR}\\samplerate\\lib\\libsamplerate-0.dll\" \"${TARGETDIR}\\\"
237     )
238
239     IF(WITH_INTERNATIONAL)
240       ADD_CUSTOM_COMMAND(TARGET blender
241         POST_BUILD
242         MAIN_DEPENDENCY blender
243         COMMAND copy /Y \"${WIN_LIBDIR}\\iconv\\lib\\iconv.dll\" \"${TARGETDIR}\\\"
244       )
245     ENDIF(WITH_INTERNATIONAL)
246
247     IF(WITH_FFMPEG)
248       ADD_CUSTOM_COMMAND(TARGET blender
249         POST_BUILD
250         MAIN_DEPENDENCY blender
251         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avcodec-52.dll\" \"${TARGETDIR}\\\"
252         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avformat-52.dll\" \"${TARGETDIR}\\\"
253         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avdevice-52.dll\" \"${TARGETDIR}\\\"
254         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avutil-50.dll\" \"${TARGETDIR}\\\"
255         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libfaac-0.dll\" \"${TARGETDIR}\\\"
256         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libfaad-2.dll\" \"${TARGETDIR}\\\"
257         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libmp3lame-0.dll\" \"${TARGETDIR}\\\"
258         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libx264-67.dll\" \"${TARGETDIR}\\\"
259         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\swscale-0.dll\" \"${TARGETDIR}\\\"
260         COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\xvidcore.dll\" \"${TARGETDIR}\\\"
261       )
262     ENDIF(WITH_FFMPEG)
263   ENDIF(WIN32)
264 ENDIF(WITH_INSTALL)
265
266 ADD_DEPENDENCIES(blender makesdna)
267
268 FILE(READ ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt BLENDER_LINK_LIBS)
269
270 SET(BLENDER_LINK_LIBS bf_nodes ${BLENDER_LINK_LIBS} bf_windowmanager bf_editors blender_render)
271
272 IF(WITH_ELBEEM)
273   SET(BLENDER_LINK_LIBS ${BLENDER_LINK_LIBS} bf_elbeem)
274 ENDIF(WITH_ELBEEM)
275
276 IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
277   SET(BLENDER_LINK_LIBS ${BLENDER_LINK_LIBS} extern_binreloc)
278 ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
279
280 IF(UNIX)
281   # Sort libraries
282   SET(BLENDER_SORTED_LIBS
283     bf_windowmanager
284     bf_editors
285     bf_decimation 
286     blender_BSP 
287     bf_ghost 
288     bf_string 
289     blender_render 
290     blender_ONL 
291     bf_python 
292     bf_gen_python 
293     bf_blenkernel 
294     bf_nodes
295     bf_gpu
296     bf_blenloader 
297     bf_blenpluginapi 
298     bf_imbuf 
299     bf_blenlib 
300     bf_avi 
301     bf_cineon 
302     bf_openexr 
303     bf_dds
304     bf_readblenfile 
305     blender_bop 
306     bf_kernel 
307     bf_decimation 
308     bf_elbeem 
309     bf_IK 
310     bf_memutil 
311     bf_guardedalloc 
312     blender_CTR 
313     bf_moto 
314     bf_windowmanager
315     bf_editors
316     bf_blroutines 
317     bf_converter 
318     bf_dummy 
319     bf_bullet 
320     bf_smoke
321     bf_common 
322     bf_ketsji 
323     bf_logic 
324     bf_rasterizer 
325     bf_oglrasterizer 
326     bf_expressions 
327     bf_scenegraph 
328     bf_moto 
329     bf_blroutines 
330     kx_network 
331     bf_kernel 
332     bf_ngnetwork 
333     extern_bullet 
334     bf_loopbacknetwork 
335     bf_common 
336     bf_moto 
337     bf_python
338     bf_gen_python
339     bf_quicktime
340     extern_binreloc
341     extern_glew
342     extern_libopenjpeg
343     bf_videotex
344     bf_rna
345     bf_dna
346     bf_blenfont
347     bf_audaspace
348   )
349
350   FOREACH(SORTLIB ${BLENDER_SORTED_LIBS})
351     SET(REMLIB ${SORTLIB})
352     FOREACH(SEARCHLIB ${BLENDER_LINK_LIBS})
353       IF(${SEARCHLIB} STREQUAL ${SORTLIB})
354         SET(REMLIB "")
355       ENDIF(${SEARCHLIB} STREQUAL ${SORTLIB})
356     ENDFOREACH(SEARCHLIB)
357     IF(REMLIB)
358       MESSAGE(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
359       LIST(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
360     ENDIF(REMLIB)
361   ENDFOREACH(SORTLIB)
362   TARGET_LINK_LIBRARIES(blender ${BLENDER_SORTED_LIBS})
363 ELSE(UNIX)
364   TARGET_LINK_LIBRARIES(blender ${BLENDER_LINK_LIBS})
365 ENDIF(UNIX)
366
367 SETUP_LIBLINKS(blender)