CMake: Provide better control over Python versions and library locations for both...
[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 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
31 PROJECT(Blender)
32
33 #-----------------------------------------------------------------------------
34 # Redirect output files
35
36 SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
37 SET(LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)
38
39 #-----------------------------------------------------------------------------
40 # Set default config options
41 OPTION(WITH_PLAYER              "Build Player"                                          OFF)
42 OPTION(WITH_GAMEENGINE          "Enable Game Engine"                                    ON)
43 OPTION(WITH_BULLET              "Enable Bullet (Physics Engine)"                        ON)
44 OPTION(WITH_INTERNATIONAL       "Enable I18N   (International fonts and text)"          ON)
45 OPTION(WITH_VERSE               "Enable Verse  (http://verse.blender.org)"              OFF)
46 OPTION(WITH_ELBEEM              "Enable Elbeem (Fluid Simulation)"                      ON)
47 OPTION(WITH_QUICKTIME           "Enable Quicktime Support"                              OFF)
48 OPTION(WITH_OPENEXR             "Enable OpenEXR Support (http://www.openexr.com)"       OFF)
49 OPTION(WITH_FFMPEG              "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu/)"   OFF)
50
51 IF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
52   MESSAGE("WARNING: WITH_PLAYER needs WITH_GAMEENGINE")
53 ENDIF(NOT WITH_GAMEENGINE AND WITH_PLAYER)
54
55 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
56 # On Unix: 
57 #   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
58 # On Macs: 
59 #   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
60 #
61 # When changing any of this remember to update the notes in doc/blender-cmake.txt
62
63 #-----------------------------------------------------------------------------
64 # Load some macros.
65 INCLUDE(CMake/macros.cmake)
66
67 #-----------------------------------------------------------------------------
68 #Platform specifics
69
70 IF(UNIX)
71   INCLUDE(${CMAKE_ROOT}/Modules/FindOpenAL.cmake)
72   IF(OPENAL_FOUND)
73     SET(WITH_OPENAL ON)
74     SET(OPENAL_LIB ${OPENAL_LIBRARY})
75     SET(OPENAL_INC ${OPENAL_INCLUDE_DIR})
76   ELSE(OPENAL_FOUND)
77     SET(WITH_OPENAL OFF)
78   ENDIF(OPENAL_FOUND)
79
80   FIND_LIBRARY(ALUT_LIBRARY
81     NAMES alut
82     PATHS
83     /usr/local/lib
84     /usr/lib
85     /sw/lib
86     /opt/local/lib
87     /opt/csw/lib
88     /opt/lib
89   )
90   IF(ALUT_LIBRARY)
91     SET(OPENAL_LIB ${OPENAL_LIB} ${ALUT_LIBRARY})
92   ENDIF(ALUT_LIBRARY)
93
94   FIND_LIBRARY(INTL_LIBRARY
95     NAMES intl
96     PATHS
97     /usr/local/lib
98     /usr/lib
99     /sw/lib
100     /opt/local/lib
101     /opt/csw/lib
102     /opt/lib
103   )
104   FIND_LIBRARY(ICONV_LIBRARY
105     NAMES iconv
106     PATHS
107     /usr/local/lib
108     /usr/lib
109     /sw/lib
110     /opt/local/lib
111     /opt/csw/lib
112     /opt/lib
113   )
114   IF(INTL_LIBRARY AND ICONV_LIBRARY)
115     SET(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
116   ENDIF(INTL_LIBRARY AND ICONV_LIBRARY)
117   
118   FIND_PATH(FREETYPE_INC
119     freetype
120     PATHS
121     /usr/local/include/freetype2
122     /usr/include/freetype2
123     /sw/include/freetype2
124     /opt/local/include/freetype2
125     /opt/csw/include/freetype2
126     /opt/include/freetype2
127   )
128   SET(FREETYPE_LIB freetype)
129
130   INCLUDE(${CMAKE_ROOT}/Modules/FindPythonLibs.cmake)
131   SET(PYTHON_INC "${PYTHON_INCLUDE_PATH}" CACHE STRING "")
132   SET(PYTHON_LIB "${PYTHON_LIBRARIES}" CACHE STRING "")
133   INCLUDE(${CMAKE_ROOT}/Modules/FindPythonInterp.cmake)
134   SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
135   SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
136
137   INCLUDE(${CMAKE_ROOT}/Modules/FindSDL.cmake)
138   SET(SDL_INC ${SDL_INCLUDE_DIR})
139   SET(SDL_LIB ${SDL_LIBRARY})
140
141   FIND_PATH(OPENEXR_INC
142     ImfXdr.h
143     PATHS
144     /usr/local/include/OpenEXR
145     /usr/include/OpenEXR
146     /sw/include/OpenEXR
147     /opt/local/include/OpenEXR
148     /opt/csw/include/OpenEXR
149     /opt/include/OpenEXR
150   )
151   SET(OPENEXR_LIB Half IlmImf Iex Imath)
152
153   SET(FFMPEG /usr)
154   SET(FFMPEG_INC ${FFMPEG}/include)
155   SET(FFMPEG_LIB avformat avcodec avutil)
156   SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
157
158   SET(JPEG_LIB jpeg)
159
160   SET(PNG_LIB png)
161
162   SET(ZLIB_LIB z)
163
164   SET(LLIBS "-lXi -lutil -lc -lm -lpthread -lstdc++")
165
166   SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing -DXP_UNIX -Wno-char-subscripts")
167
168   SET(PLATFORM_LINKFLAGS "-pthread")
169
170   INCLUDE_DIRECTORIES(/usr/include /usr/local/include)
171 ENDIF(UNIX)
172
173 IF(WIN32)
174   INCLUDE(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
175
176   SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
177
178   SET(PYTHON ${LIBDIR}/python)
179   SET(PYTHON_VERSION 2.4)
180   SET(PYTHON_INC "${PYTHON}/include/python${PYTHON_VERSION}")
181   SET(PYTHON_BINARY python)
182   SET(PYTHON_LIB python24)
183   SET(PYTHON_LIBPATH ${PYTHON}/lib)
184
185   SET(WITH_OPENAL ON)
186   SET(OPENAL ${LIBDIR}/openal)
187   SET(OPENAL_INC ${OPENAL}/include ${OPENAL}/include/AL)
188   SET(OPENAL_LIB openal_static)
189   SET(OPENAL_LIBPATH ${OPENAL}/lib)
190
191   SET(PNG_LIB libpng_st)
192   SET(JPEG_LIB libjpeg)
193
194   SET(ZLIB ${LIBDIR}/zlib)
195   SET(ZLIB_INC ${ZLIB}/include)
196   SET(ZLIB_LIB libz)
197   SET(ZLIB_LIBPATH ${ZLIB}/lib)
198   
199   SET(PTHREADS ${LIBDIR}/pthreads)
200   SET(PTHREADS_INC ${PTHREADS}/include)
201   SET(PTHREADS_LIB pthreadVC2)
202   SET(PTHREADS_LIBPATH ${PTHREADS}/lib)
203   
204   SET(ICONV ${LIBDIR}/iconv)
205   SET(ICONV_INC ${ICONV}/include)
206   SET(ICONV_LIB iconv)
207   SET(ICONV_LIBPATH ${ICONV}/lib)
208   
209   SET(GETTEXT ${LIBDIR}/gettext)
210   SET(GETTEXT_INC ${GETTEXT}/include)
211   SET(GETTEXT_LIB gnu_gettext)
212   SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
213
214   SET(FREETYPE ${LIBDIR}/freetype)
215   SET(FREETYPE_INC ${FREETYPE}/include ${FREETYPE}/include/freetype2)
216   SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
217   SET(FREETYPE_LIB freetype2ST)
218   
219   SET(OPENEXR ${LIBDIR}/openexr)
220   SET(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/IlmImf ${OPENEXR}/include/Iex ${OPENEXR}/include/Imath)
221   SET(OPENEXR_LIB Iex Half IlmImf Imath)
222   SET(OPENEXR_LIBPATH ${OPENEXR}/lib_msvc)
223   
224   SET(QUICKTIME ${LIBDIR}/QTDevWin)
225   SET(QUICKTIME_INC ${QUICKTIME}/CIncludes)
226   SET(QUICKTIME_LIB qtmlClient)
227   SET(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
228
229   SET(FFMPEG ${LIBDIR}/ffmpeg)
230   SET(FFMPEG_INC ${FFMPEG}/include)
231   SET(FFMPEG_LIB avcodec-51 avformat-51 avutil-49)
232   SET(FFMPEG_LIBPATH ${FFMPEG}/lib)
233
234   SET(LLIBS kernel32 user32 gdi32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid odbc32 odbccp32 ws2_32 vfw32 winmm dxguid)
235
236   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)
237   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)
238   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)
239   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)
240   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)
241   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)
242   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)
243   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)
244
245   SET(SDL ${LIBDIR}/sdl)
246   SET(SDL_INC ${SDL}/include)
247   SET(SDL_LIB SDL)
248   SET(SDL_LIBPATH ${SDL}/lib)
249
250   SET(PNG "${LIBDIR}/png")
251   SET(PNG_INC "${PNG}/include")
252   SET(PNG_LIBPATH ${PNG}/lib)
253
254   SET(JPEG "${LIBDIR}/jpeg")
255   SET(JPEG_INC "${JPEG}/include")
256   SET(JPEG_LIBPATH ${JPEG}/lib)
257
258   SET(TIFF ${LIBDIR}/tiff)
259   SET(TIFF_INC ${TIFF}/include)
260   
261   SET(WINTAB_INC ${LIBDIR}/wintab/include) 
262
263   SET(PLATFORM_LINKFLAGS "/NODEFAULTLIB:libc.lib")
264   SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib ")
265 ENDIF(WIN32)
266
267 IF(APPLE)
268   IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
269     SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
270   ELSE(CMAKE_OSX_ARCHITECTURES MATCHES i386)
271     SET(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-6.1-powerpc)
272   ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
273
274   INCLUDE(${CMAKE_ROOT}/Modules/FindOpenAL.cmake)
275   IF(OPENAL_FOUND)
276     SET(WITH_OPENAL ON)
277     SET(OPENAL_LIB ${OPENAL_LIBRARY})
278     SET(OPENAL_INC ${OPENAL_INCLUDE_DIR})
279   ELSE(OPENAL_FOUND)
280     SET(WITH_OPENAL OFF)
281   ENDIF(OPENAL_FOUND)
282
283   SET(PYTHON /System/Library/Frameworks/Python.framework/Versions/)
284   SET(PYTHON_VERSION 2.3)
285   SET(PYTHON_INC "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}" CACHE STRING "")
286   SET(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION} CACHE STRING "")
287   SET(PYTHON_LIB "")
288   SET(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config CACHE STRING "")
289   SET(PYTHON_LINKFLAGS "-u __dummy -u _PyMac_Error -framework System -framework Python")
290
291   SET(GETTEXT ${LIBDIR}/gettext)
292   SET(GETTEXT_INC "${GETTEXT}/include")
293   SET(GETTEXT_LIB intl iconv)
294   SET(GETTEXT_LIBPATH ${GETTEXT}/lib)
295
296   SET(PNG_LIB png)
297   SET(JPEG_LIB jpeg)
298
299   SET(ZLIB /usr)
300   SET(ZLIB_INC "${ZLIB}/include")
301   SET(ZLIB_LIB z)
302
303   SET(FREETYPE ${LIBDIR}/freetype)
304   SET(FREETYPE_INC ${FREETYPE}/include ${FREETYPE}/include/freetype2)
305   SET(FREETYPE_LIBPATH ${FREETYPE}/lib)
306   SET(FREETYPE_LIB freetype)
307
308   SET(OPENEXR ${LIBDIR}/openexr)
309   SET(OPENEXR_INC ${OPENEXR}/include/OpenEXR)
310   IF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
311     SET(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
312   ELSE(CMAKE_OSX_ARCHITECTURES MATCHES i386)
313     SET(OPENEXR_LIB Iex Half IlmImf Imath)
314   ENDIF(CMAKE_OSX_ARCHITECTURES MATCHES i386)
315   SET(OPENEXR_LIBPATH ${OPENEXR}/lib)
316
317   SET(LLIBS stdc++ SystemStubs)
318
319   SET(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
320   SET(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
321
322   SET(SDL ${LIBDIR}/sdl)
323   SET(SDL_INC ${SDL}/include)
324   SET(SDL_LIB SDL)
325   SET(SDL_LIBPATH ${SDL}/lib)
326
327   SET(PNG "${LIBDIR}/png")
328   SET(PNG_INC "${PNG}/include")
329   SET(PNG_LIBPATH ${PNG}/lib)
330
331   SET(JPEG "${LIBDIR}/jpeg")
332   SET(JPEG_INC "${JPEG}/include")
333   SET(JPEG_LIBPATH ${JPEG}/lib)
334
335   SET(TIFF ${LIBDIR}/tiff)
336   SET(TIFF_INC ${TIFF}/include)
337
338   SET(EXETYPE MACOSX_BUNDLE)
339 ENDIF(APPLE)
340
341 #-----------------------------------------------------------------------------
342 # Common.
343 SET(VERSE_INC ${CMAKE_SOURCE_DIR}/extern/verse/dist)
344
345 SET(FTGL ${CMAKE_SOURCE_DIR}/extern/bFTGL)
346 SET(FTGL_INC ${FTGL}/include)
347 SET(FTGL_LIB extern_ftgl)
348
349
350 #-----------------------------------------------------------------------------
351 # Configure OpenGL.
352 INCLUDE(${CMAKE_ROOT}/Modules/FindOpenGL.cmake)
353 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
354 #-----------------------------------------------------------------------------
355 # Extra compile flags
356 IF(WITH_GAMEENGINE)
357   SET(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DGAMEBLENDER ")
358 ENDIF(WITH_GAMEENGINE)
359 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ")
360 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ")
361
362 #-----------------------------------------------------------------------------
363 # Libraries
364 FILE(WRITE ${CMAKE_SOURCE_DIR}/cmake_blender_libs.txt "")
365 SUBDIRS(
366   intern
367   extern
368   source
369 )
370
371
372 #-----------------------------------------------------------------------------
373 # Blender Application
374 SUBDIRS(source/creator)
375
376 #-----------------------------------------------------------------------------
377 # Blender Player
378 IF(WITH_PLAYER)
379   SUBDIRS(blenderplayer)
380 ENDIF(WITH_PLAYER)