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