CMake: Give error on attempts to generate within the sources with
[blender.git] / CMakeLists.txt
1 # $Id$
2 # ***** BEGIN GPL/BL DUAL 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. The Blender
8 # Foundation also sells licenses for use in proprietary software under
9 # the Blender License.  See http://www.blender.org/BL/ for information
10 # about this.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software Foundation,
19 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 #
21 # The Original Code is Copyright (C) 2006, Blender Foundation
22 # All rights reserved.
23 #
24 # The Original Code is: all of this file.
25 #
26 # Contributor(s): Jacques Beaurain.
27 #
28 # ***** END GPL/BL DUAL LICENSE BLOCK *****
29
30 #-----------------------------------------------------------------------------
31 # We don't allow in-source builds. This causes no end of troubles because 
32 # all out-of-source builds will use the CMakeCache.txt file there and even 
33 # build the libs and objects in it. It will also conflict with the current 
34 # Makefile system for Blender
35
36 IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
37 MESSAGE(FATAL_ERROR "CMake generation for blender is not allowed within the source directory! 
38 Remove the CMakeCache.txt file and try again from another folder, e.g.: 
39
40    rm CMakeCache.txt 
41    cd ..
42    mkdir cmake-make 
43    cd cmake-make
44    cmake -G \"Unix Makefiles\" ../blender
45 ")
46 ENDIF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
47
48 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
49 PROJECT(Blender)
50
51 #-----------------------------------------------------------------------------
52 # Redirect output files
53
54 SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
55 SET(LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)
56
57 #-----------------------------------------------------------------------------
58 # Set default config options
59 OPTION(WITH_PLAYER              "Build Player"                                          OFF)
60 OPTION(WITH_GAMEENGINE          "Enable Game Engine"                                    ON)
61 OPTION(WITH_BULLET              "Enable Bullet (Physics Engine)"                        ON)
62 OPTION(WITH_INTERNATIONAL       "Enable I18N   (International fonts and text)"          ON)
63 OPTION(WITH_VERSE               "Enable Verse  (http://verse.blender.org)"              OFF)
64 OPTION(WITH_ELBEEM              "Enable Elbeem (Fluid Simulation)"                      ON)
65 OPTION(WITH_QUICKTIME           "Enable Quicktime Support"                              OFF)
66 OPTION(WITH_OPENEXR             "Enable OpenEXR Support (http://www.openexr.com)"       OFF)
67 OPTION(WITH_FFMPEG              "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu/)"   OFF)
68
69 IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
70   MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE")
71 ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
72
73 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
74 # On Unix: 
75 #   cmake -D PYTHON_LIB=/usr/local/lib/python2.3/config/libpython2.3.so -D PYTHON_INC=/usr/local/include/python2.3 -D PYTHON_BINARY=/usr/local/bin/python2.3 -G "Unix Makefiles" ../blender
76 # On Macs: 
77 #   cmake -D PYTHON_INC=/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config -D PYTHON_BINARY=/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 -G Xcode ../blender
78 #
79 # When changing any of this remember to update the notes in doc/blender-cmake.txt
80
81 #-----------------------------------------------------------------------------
82 # Load some macros.
83 INCLUDE(CMake/macros.cmake)
84
85 #-----------------------------------------------------------------------------
86 #Platform specifics
87
88 IF(UNIX)
89   INCLUDE(${CMAKE_ROOT}/Modules/FindOpenAL.cmake)
90   IF(OPENAL_FOUND)
91     SET(WITH_OPENAL ON)
92     SET(OPENAL_LIB ${OPENAL_LIBRARY})
93     SET(OPENAL_INC ${OPENAL_INCLUDE_DIR})
94   ELSE(OPENAL_FOUND)
95     SET(WITH_OPENAL OFF)
96   ENDIF(OPENAL_FOUND)
97
98   FIND_LIBRARY(ALUT_LIBRARY
99     NAMES alut
100     PATHS
101     /usr/local/lib
102     /usr/lib
103     /sw/lib
104     /opt/local/lib
105     /opt/csw/lib
106     /opt/lib
107   )
108   IF(ALUT_LIBRARY)
109     SET(OPENAL_LIB ${OPENAL_LIB} ${ALUT_LIBRARY})
110   ENDIF(ALUT_LIBRARY)
111
112   FIND_LIBRARY(INTL_LIBRARY
113     NAMES intl
114     PATHS
115     /usr/local/lib
116     /usr/lib
117     /sw/lib
118     /opt/local/lib
119     /opt/csw/lib
120     /opt/lib
121   )
122   FIND_LIBRARY(ICONV_LIBRARY
123     NAMES iconv
124     PATHS
125     /usr/local/lib
126     /usr/lib
127     /sw/lib
128     /opt/local/lib
129     /opt/csw/lib
130     /opt/lib
131   )
132   IF(INTL_LIBRARY AND ICONV_LIBRARY)
133     SET(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
134   ENDIF(INTL_LIBRARY AND ICONV_LIBRARY)
135   
136   FIND_PATH(FREETYPE_INC
137     freetype
138     PATHS
139     /usr/local/include/freetype2
140     /usr/include/freetype2
141     /sw/include/freetype2
142     /opt/local/include/freetype2
143     /opt/csw/include/freetype2
144     /opt/include/freetype2
145   )
146   SET(FREETYPE_LIB freetype)
147
148   INCLUDE(${CMAKE_ROOT}/Modules/FindPythonLibs.cmake)
149   SET(PYTHON_INC "${PYTHON_INCLUDE_PATH}" CACHE STRING "")
150   SET(PYTHON_LIB "${PYTHON_LIBRARIES}" CACHE STRING "")
151   INCLUDE(${CMAKE_ROOT}/Modules/FindPythonInterp.cmake)
152   SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
153   SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
154
155   INCLUDE(${CMAKE_ROOT}/Modules/FindSDL.cmake)
156   SET(SDL_INC ${SDL_INCLUDE_DIR})
157   SET(SDL_LIB ${SDL_LIBRARY})
158
159   FIND_PATH(OPENEXR_INC
160     ImfXdr.h
161     PATHS
162     /usr/local/include/OpenEXR
163     /usr/include/OpenEXR
164     /sw/include/OpenEXR
165     /opt/local/include/OpenEXR
166     /opt/csw/include/OpenEXR
167     /opt/include/OpenEXR
168   )
169   SET(OPENEXR_LIB Half IlmImf Iex Imath)
170
171   SET(FFMPEG /usr)
172   SET(FFMPEG_INC ${FFMPEG}/include)
173   SET(FFMPEG_LIB avformat avcodec avutil)
174   SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
175
176   SET(JPEG_LIB jpeg)
177
178   SET(PNG_LIB png)
179
180   SET(ZLIB_LIB z)
181
182   SET(LLIBS "-lXi -lutil -lc -lm -lpthread -lstdc++")
183
184   SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing -DXP_UNIX -Wno-char-subscripts")
185
186   SET(PLATFORM_LINKFLAGS "-pthread")
187
188   INCLUDE_DIRECTORIES(/usr/include /usr/local/include)
189 ENDIF(UNIX)
190
191 IF(WIN32)
192   INCLUDE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
193
194   SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
195
196   SET(PYTHON ${LIBDIR}/python)
197   SET(PYTHON_VERSION 2.4)
198   SET(PYTHON_INC "${PYTHON}/include/python${PYTHON_VERSION}")
199   SET(PYTHON_BINARY python)
200   SET(PYTHON_LIB python24)
201   SET(PYTHON_LIBPATH ${PYTHON}/lib)
202
203   SET(WITH_OPENAL ON)
204   SET(OPENAL ${LIBDIR}/openal)
205   SET(OPENAL_INC ${OPENAL}/include ${OPENAL}/include/AL)
206   SET(OPENAL_LIB openal_static)
207   SET(OPENAL_LIBPATH ${OPENAL}/lib)
208
209   SET(PNG_LIB libpng_st)
210   SET(JPEG_LIB libjpeg)
211
212   SET(ZLIB ${LIBDIR}/zlib)
213   SET(ZLIB_INC ${ZLIB}/include)
214   SET(ZLIB_LIB libz)
215   SET(ZLIB_LIBPATH ${ZLIB}/lib)
216   
217   SET(PTHREADS ${LIBDIR}/pthreads)
218   SET(PTHREADS_INC ${PTHREADS}/include)
219   SET(PTHREADS_LIB pthreadVC2)
220   SET(PTHREADS_LIBPATH ${PTHREADS}/lib)
221   
222   SET(ICONV ${LIBDIR}/iconv)
223   SET(ICONV_INC ${ICONV}/include)
224   SET(ICONV_LIB iconv)
225   SET(ICONV_LIBPATH ${ICONV}/lib)
226   
227   SET(GETTEXT ${LIBDIR}/gettext)
228   SET(GETTEXT_INC ${GETTEXT}/include)
229   SET(GETTEXT_LIB gnu_gettext)
230   SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
231
232   SET(FREETYPE ${LIBDIR}/freetype)
233   SET(FREETYPE_INC ${FREETYPE}/include ${FREETYPE}/include/freetype2)
234   SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
235   SET(FREETYPE_LIB freetype2ST)
236   
237   SET(OPENEXR ${LIBDIR}/openexr)
238   SET(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/IlmImf ${OPENEXR}/include/Iex ${OPENEXR}/include/Imath)
239   SET(OPENEXR_LIB Iex Half IlmImf Imath)
240   SET(OPENEXR_LIBPATH ${OPENEXR}/lib_msvc)
241   
242   SET(QUICKTIME ${LIBDIR}/QTDevWin)
243   SET(QUICKTIME_INC ${QUICKTIME}/CIncludes)
244   SET(QUICKTIME_LIB qtmlClient)
245   SET(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
246
247   SET(FFMPEG ${LIBDIR}/ffmpeg)
248   SET(FFMPEG_INC ${FFMPEG}/include)
249   SET(FFMPEG_LIB avcodec-51 avformat-51 avutil-49)
250   SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
251
252   SET(LLIBS kernel32 user32 gdi32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32 vfw32 winmm dxguid)
253
254   SET(CMAKE_CXX_FLAGS_DEBUG "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
255   SET(CMAKE_CXX_FLAGS_RELEASE "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
256   SET(CMAKE_CXX_FLAGS_MINSIZEREL "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
257   SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
258   SET(CMAKE_C_FLAGS_DEBUG "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
259   SET(CMAKE_C_FLAGS_RELEASE "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
260   SET(CMAKE_C_FLAGS_MINSIZEREL "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
261   SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /wd4800 /wd4244 /wd4305 /O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
262
263   SET(SDL ${LIBDIR}/sdl)
264   SET(SDL_INC ${SDL}/include)
265   SET(SDL_LIB SDL)
266   SET(SDL_LIBPATH ${SDL}/lib)
267
268   SET(PNG "${LIBDIR}/png")
269   SET(PNG_INC "${PNG}/include")
270   SET(PNG_LIBPATH ${PNG}/lib)
271
272   SET(JPEG "${LIBDIR}/jpeg")
273   SET(JPEG_INC "${JPEG}/include")
274   SET(JPEG_LIBPATH ${JPEG}/lib)
275
276   SET(TIFF ${LIBDIR}/tiff)
277   SET(TIFF_INC ${TIFF}/include)
278   
279   SET(WINTAB_INC ${LIBDIR}/wintab/include) 
280
281   SET(PLATFORM_LINKFLAGS "/NODEFAULTLIB:libc.lib")
282   SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib ")
283 ENDIF(WIN32)
284
285 IF(APPLE)
286   IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
287     SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
288   ELSE(CMAKE_OSX_ARCHITECTURES MATCHES i386)
289     SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-6.1-powerpc)
290   ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
291
292   INCLUDE(${CMAKE_ROOT}/Modules/FindOpenAL.cmake)
293   IF(OPENAL_FOUND)
294     SET(WITH_OPENAL ON)
295     SET(OPENAL_LIB ${OPENAL_LIBRARY})
296     SET(OPENAL_INC ${OPENAL_INCLUDE_DIR})
297   ELSE(OPENAL_FOUND)
298     SET(WITH_OPENAL OFF)
299   ENDIF(OPENAL_FOUND)
300
301   SET(PYTHON /System/Library/Frameworks/Python.framework/Versions/)
302   SET(PYTHON_VERSION 2.3)
303   SET(PYTHON_INC "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}" CACHE STRING "")
304   SET(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION} CACHE STRING "")
305   SET(PYTHON_LIB "")
306   SET(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config CACHE STRING "")
307   SET(PYTHON_LINKFLAGS "-u __dummy -u _PyMac_Error -framework System -framework Python")
308
309   SET(GETTEXT ${LIBDIR}/gettext)
310   SET(GETTEXT_INC "${GETTEXT}/include")
311   SET(GETTEXT_LIB intl iconv)
312   SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
313
314   SET(PNG_LIB png)
315   SET(JPEG_LIB jpeg)
316
317   SET(ZLIB /usr)
318   SET(ZLIB_INC "${ZLIB}/include")
319   SET(ZLIB_LIB z)
320
321   SET(FREETYPE ${LIBDIR}/freetype)
322   SET(FREETYPE_INC ${FREETYPE}/include ${FREETYPE}/include/freetype2)
323   SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
324   SET(FREETYPE_LIB freetype)
325
326   SET(OPENEXR ${LIBDIR}/openexr)
327   SET(OPENEXR_INC ${OPENEXR}/include/OpenEXR)
328   IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
329     SET(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
330   ELSE(CMAKE_OSX_ARCHITECTURES MATCHES i386)
331     SET(OPENEXR_LIB Iex Half IlmImf Imath)
332   ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
333   SET(OPENEXR_LIBPATH ${OPENEXR}/lib)
334
335   SET(LLIBS stdc++ SystemStubs)
336
337   SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
338   SET(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
339
340   SET(SDL ${LIBDIR}/sdl)
341   SET(SDL_INC ${SDL}/include)
342   SET(SDL_LIB SDL)
343   SET(SDL_LIBPATH ${SDL}/lib)
344
345   SET(PNG "${LIBDIR}/png")
346   SET(PNG_INC "${PNG}/include")
347   SET(PNG_LIBPATH ${PNG}/lib)
348
349   SET(JPEG "${LIBDIR}/jpeg")
350   SET(JPEG_INC "${JPEG}/include")
351   SET(JPEG_LIBPATH ${JPEG}/lib)
352
353   SET(TIFF ${LIBDIR}/tiff)
354   SET(TIFF_INC ${TIFF}/include)
355
356   SET(EXETYPE MACOSX_BUNDLE)
357 ENDIF(APPLE)
358
359 #-----------------------------------------------------------------------------
360 # Common.
361 SET(VERSE_INC ${CMAKE_SOURCE_DIR}/extern/verse/dist)
362
363 SET(FTGL ${CMAKE_SOURCE_DIR}/extern/bFTGL)
364 SET(FTGL_INC ${FTGL}/include)
365 SET(FTGL_LIB extern_ftgl)
366
367
368 #-----------------------------------------------------------------------------
369 # Configure OpenGL.
370 INCLUDE(${CMAKE_ROOT}/Modules/FindOpenGL.cmake)
371 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
372 #-----------------------------------------------------------------------------
373 # Extra compile flags
374 IF(WITH_GAMEENGINE)
375   SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DGAMEBLENDER ")
376 ENDIF(WITH_GAMEENGINE)
377 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ")
378 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ")
379
380 #-----------------------------------------------------------------------------
381 # Libraries
382 FILE(WRITE ${CMAKE_BINARY_DIR}/cmake_blender_libs.txt "")
383 SUBDIRS(
384   intern
385   extern
386   source
387 )
388
389
390 #-----------------------------------------------------------------------------
391 # Blender Application
392 SUBDIRS(source/creator)
393
394 #-----------------------------------------------------------------------------
395 # Blender Player
396 IF(WITH_PLAYER)
397   SUBDIRS(blenderplayer)
398 ENDIF(WITH_PLAYER)