Finally got CMake compilation to work.
[blender-staging.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/python
42   ../blender/makesdna
43   ../blender/gpu
44   ../blender/windowmanager
45   ../kernel/gen_messaging
46   ../kernel/gen_system
47   ../../extern/glew/include
48 )
49
50
51
52 IF(WITH_QUICKTIME)
53   ADD_DEFINITIONS(-DWITH_QUICKTIME)
54 ENDIF(WITH_QUICKTIME)
55
56 IF(WITH_OPENEXR)
57   ADD_DEFINITIONS(-DWITH_OPENEXR)
58 ENDIF(WITH_OPENEXR)
59
60 IF(LINUX)
61   ADD_DEFINITIONS(-DWITH_BINRELOC)
62   INCLUDE_DIRECTORIES(${BINRELOC_INC})
63 endif(LINUX)
64
65 MESSAGE(STATUS "Configuring blender")
66
67 ADD_CUSTOM_COMMAND(
68   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dna.c
69   COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesdna ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_SOURCE_DIR}/source/blender/makesdna/
70   DEPENDS ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesdna
71   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/rna.c
72   COMMAND ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesrna ${CMAKE_CURRENT_BINARY_DIR}/rna.c ${CMAKE_SOURCE_DIR}/source/blender/makesrna/
73   DEPENDS ${CMAKE_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}/makesrna
74 )
75
76 IF(WIN32)
77   ADD_EXECUTABLE(blender ${EXETYPE} creator.c ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_CURRENT_BINARY_DIR}/rna.c ../icons/winblender.rc)
78 ELSE(WIN32)
79   ADD_EXECUTABLE(blender ${EXETYPE} creator.c ${CMAKE_CURRENT_BINARY_DIR}/dna.c ${CMAKE_CURRENT_BINARY_DIR}/rna.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
88 IF(UNIX)
89   ADD_CUSTOM_COMMAND(TARGET blender
90     POST_BUILD
91     MAIN_DEPENDENCY blender
92     #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/plugins ${TARGETDIR}/
93     #COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/text/* ${TARGETDIR}/
94   )
95 ENDIF(UNIX)
96
97 IF(UNIX AND NOT APPLE)
98   ADD_CUSTOM_COMMAND(TARGET blender
99     POST_BUILD
100     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     COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/.blender/
105     COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/.blender/
106     COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/.blender/
107     COMMAND find ${TARGETDIR} -name CVS -prune -exec rm -rf {} "\;"
108   )
109 ENDIF(UNIX AND NOT APPLE)
110
111 IF(APPLE)
112   SET(SOURCEDIR ${CMAKE_SOURCE_DIR}/source/darwin/blender.app)
113   SET(SOURCEINFO ${SOURCEDIR}/Contents/Info.plist)
114   SET(TARGETINFO ${TARGETDIR}/blender.app/Contents/Info.plist)
115
116   ADD_CUSTOM_COMMAND(TARGET blender
117     POST_BUILD
118     MAIN_DEPENDENCY blender
119     COMMAND cp -R ${SOURCEINFO} ${TARGETDIR}/blender.app/Contents/
120     COMMAND cp -R ${SOURCEDIR}/Contents/PkgInfo ${TARGETDIR}/blender.app/Contents/
121     COMMAND cp -R ${SOURCEDIR}/Contents/Resources ${TARGETDIR}/blender.app/Contents/
122     COMMAND cat ${SOURCEINFO} | sed s/VERSION/`cat ${CMAKE_SOURCE_DIR}/release/VERSION`/ | sed s/DATE/`date +'%Y-%b-%d'`/ > ${TARGETINFO}
123     COMMAND rm -Rf ${TARGETDIR}/blender.app/Contents/MacOS/.blender
124     COMMAND mkdir ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
125     COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.bfont.ttf ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
126     COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
127     COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/Resources/
128     COMMAND cp -R ${CMAKE_SOURCE_DIR}/bin/.blender/locale ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
129     COMMAND cp ${CMAKE_SOURCE_DIR}/bin/.blender/.Blanguages ${TARGETDIR}/blender.app/Contents/Resources/
130     COMMAND cp -R ${CMAKE_SOURCE_DIR}/release/scripts ${TARGETDIR}/blender.app/Contents/MacOS/.blender/
131     COMMAND find ${TARGETDIR}/blender.app -name CVS -prune -exec rm -rf {} "\;"
132     COMMAND find ${TARGETDIR}/blender.app -name CVS.sandboxinfo -prune -exec rm -rf {} "\;"
133     COMMAND find ${TARGETDIR}/blender.app -name .DS_Store -prune -exec rm -rf {} "\;"
134   )
135 ENDIF(APPLE)
136
137 IF(WIN32)
138   FILE(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} WIN_SOURCE_DIR)
139   
140   ADD_CUSTOM_COMMAND(TARGET blender
141     POST_BUILD
142     MAIN_DEPENDENCY blender
143     COMMAND if not exist \"${TARGETDIR}\\.blender\" mkdir \"${TARGETDIR}\\.blender\"
144     COMMAND if not exist \"${TARGETDIR}\\.blender\\locale\" mkdir \"${TARGETDIR}\\.blender\\locale\"
145     COMMAND if not exist \"${TARGETDIR}\\.blender\\scripts\" mkdir \"${TARGETDIR}\\.blender\\scripts\"
146     COMMAND if not exist \"${TARGETDIR}\\plugins\" mkdir \"${TARGETDIR}\\plugins\"
147     COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.Blanguages\" \"${TARGETDIR}\\.blender\\\" 
148     COMMAND copy /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\.bfont.ttf\" \"${TARGETDIR}\\.blender\\\"
149     COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\bin\\.blender\\locale\\*.*\" \"${TARGETDIR}\\.blender\\locale\"
150     COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\scripts\\*.*\" \"${TARGETDIR}\\.blender\\scripts\"
151     COMMAND xcopy /E /Y \"${WIN_SOURCE_DIR}\\release\\plugins\\*.*\" \"${TARGETDIR}\\plugins\"
152     COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\text\\*.*\" \"${TARGETDIR}\"
153     COMMAND copy /Y \"${WIN_SOURCE_DIR}\\release\\windows\\extra\\python25.zip\" \"${TARGETDIR}\\\"
154   )
155   
156   FILE(TO_NATIVE_PATH "${LIBDIR}" WIN_LIBDIR)
157   
158   ADD_CUSTOM_COMMAND(TARGET blender
159     POST_BUILD
160     MAIN_DEPENDENCY blender
161     COMMAND copy /Y \"${WIN_LIBDIR}\\gettext\\lib\\gnu_gettext.dll\" \"${TARGETDIR}\\\"
162     COMMAND copy /Y \"${WIN_LIBDIR}\\png\\lib\\libpng.dll\" \"${TARGETDIR}\\\"
163     COMMAND copy /Y \"${WIN_LIBDIR}\\sdl\\lib\\SDL.dll\" \"${TARGETDIR}\\\"
164     COMMAND copy /Y \"${WIN_LIBDIR}\\zlib\\lib\\zlib.dll\" \"${TARGETDIR}\\\"
165     COMMAND copy /Y \"${WIN_LIBDIR}\\tiff\\lib\\libtiff.dll\" \"${TARGETDIR}\\\"
166     COMMAND copy /Y \"${WIN_LIBDIR}\\python\\lib\\python25.dll\" \"${TARGETDIR}\\\"
167     COMMAND copy /Y \"${WIN_LIBDIR}\\pthreads\\lib\\pthreadVC2.dll\" \"${TARGETDIR}\\\"
168   )
169
170   IF(WITH_INTERNATIONAL)
171     ADD_CUSTOM_COMMAND(TARGET blender
172       POST_BUILD
173       MAIN_DEPENDENCY blender
174       COMMAND copy /Y \"${WIN_LIBDIR}\\iconv\\lib\\iconv.dll\" \"${TARGETDIR}\\\"
175     )
176   ENDIF(WITH_INTERNATIONAL)
177
178   IF(WITH_FFMPEG)
179     ADD_CUSTOM_COMMAND(TARGET blender
180       POST_BUILD
181       MAIN_DEPENDENCY blender
182       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avcodec-51.dll\" \"${TARGETDIR}\\\"
183       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avformat-52.dll\" \"${TARGETDIR}\\\"
184       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avdevice-52.dll\" \"${TARGETDIR}\\\"
185       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\avutil-49.dll\" \"${TARGETDIR}\\\"
186       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libfaac-0.dll\" \"${TARGETDIR}\\\"
187       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libfaad-0.dll\" \"${TARGETDIR}\\\"
188       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libmp3lame-0.dll\" \"${TARGETDIR}\\\"
189       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\libx264-59.dll\" \"${TARGETDIR}\\\"
190       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\swscale-0.dll\" \"${TARGETDIR}\\\"
191       COMMAND copy /Y \"${WIN_LIBDIR}\\ffmpeg\\lib\\xvidcore.dll\" \"${TARGETDIR}\\\"
192     )
193   ENDIF(WITH_FFMPEG)
194 ENDIF(WIN32)
195
196 ADD_DEPENDENCIES(blender makesdna)
197
198 FILE(READ ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt BLENDER_LINK_LIBS)
199
200 SET(BLENDER_LINK_LIBS bf_nodes ${BLENDER_LINK_LIBS} bf_windowmanager bf_editors blender_render blender_radiosity)
201
202 IF(WITH_ELBEEM)
203   SET(BLENDER_LINK_LIBS ${BLENDER_LINK_LIBS} bf_elbeem)
204 ENDIF(WITH_ELBEEM)
205
206 IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
207   SET(BLENDER_LINK_LIBS ${BLENDER_LINK_LIBS} extern_binreloc)
208 ENDIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
209
210 IF(UNIX)
211   # Sort libraries
212   SET(BLENDER_SORTED_LIBS
213     bf_windowmanager
214         bf_editors
215     bf_decimation 
216     blender_BSP 
217     bf_soundsystem 
218     bf_ghost 
219     bf_string 
220     blender_render 
221     blender_radiosity 
222     blender_ONL 
223     bf_python 
224     bf_blenkernel 
225     bf_nodes
226         bf_gpu
227     bf_blenloader 
228     bf_blenpluginapi 
229     bf_imbuf 
230     bf_blenlib 
231     bf_avi 
232     bf_cineon 
233     bf_openexr 
234     bf_dds
235     bf_readblenfile 
236     blender_bop 
237     bf_kernel 
238     bf_decimation 
239     bf_elbeem 
240     bf_yafray 
241     bf_IK 
242     bf_memutil 
243     bf_guardedalloc 
244     blender_CTR 
245     bf_moto 
246     bf_bmfont 
247     verse 
248     bf_windowmanager
249         bf_editors
250     bf_ftfont 
251     extern_ftgl 
252     bf_blroutines 
253     bf_converter 
254     bf_dummy 
255     bf_bullet 
256     bf_common 
257     bf_ketsji 
258     bf_logic 
259     bf_rasterizer 
260     bf_oglrasterizer 
261     bf_expressions 
262     bf_scenegraph 
263     bf_moto 
264     bf_blroutines 
265     kx_network 
266     bf_kernel 
267     bf_ngnetwork 
268     extern_bullet 
269     bf_loopbacknetwork 
270     bf_sumo 
271     bf_common 
272     extern_solid 
273     extern_qhull 
274     bf_moto 
275     bf_python
276     bf_quicktime
277     extern_binreloc
278     extern_glew
279     bf_videotex
280     bf_rna
281     bf_dna
282   )
283
284   FOREACH(SORTLIB ${BLENDER_SORTED_LIBS})
285     SET(REMLIB ${SORTLIB})
286     FOREACH(SEARCHLIB ${BLENDER_LINK_LIBS})
287       IF(${SEARCHLIB} STREQUAL ${SORTLIB})
288         SET(REMLIB "")
289       ENDIF(${SEARCHLIB} STREQUAL ${SORTLIB})
290     ENDFOREACH(SEARCHLIB)
291     IF(REMLIB)
292       MESSAGE(STATUS "Removing library ${REMLIB} from blender linking because: not configured")
293       LIST(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
294     ENDIF(REMLIB)
295   ENDFOREACH(SORTLIB)
296   TARGET_LINK_LIBRARIES(blender ${BLENDER_SORTED_LIBS})
297 ELSE(UNIX)
298   TARGET_LINK_LIBRARIES(blender ${BLENDER_LINK_LIBS})
299 ENDIF(UNIX)
300
301 SETUP_LIBLINKS(blender)