another CMake build fix (contributed by Kevin Cozens)
[blender.git] / CMakeLists.txt
1 # -*- mode: cmake; indent-tabs-mode: t; -*-
2 # $Id$
3 # ***** BEGIN GPL LICENSE BLOCK *****
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # The Original Code is Copyright (C) 2006, Blender Foundation
20 # All rights reserved.
21 #
22 # The Original Code is: all of this file.
23 #
24 # Contributor(s): Jacques Beaurain.
25 #
26 # ***** END GPL LICENSE BLOCK *****
27
28 #-----------------------------------------------------------------------------
29 # We don't allow in-source builds. This causes no end of troubles because 
30 # all out-of-source builds will use the CMakeCache.txt file there and even 
31 # build the libs and objects in it.
32
33 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
34         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
35                 message(FATAL_ERROR
36                         "CMake generation for blender is not allowed within the source directory!"
37                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
38                         "\n "
39                         "\n rm CMakeCache.txt"
40                         "\n cd .."
41                         "\n mkdir cmake-make"
42                         "\n cd cmake-make"
43                         "\n cmake ../blender"
44                         "\n "
45                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
46                 )
47         endif()
48 endif()
49
50 cmake_minimum_required(VERSION 2.8)
51
52 if(NOT EXECUTABLE_OUTPUT_PATH)
53         set(FIRST_RUN "TRUE")
54 endif()
55
56 # this starts out unset
57 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
58
59 # avoid having empty buildtype
60 set(CMAKE_BUILD_TYPE_INIT "Release")
61
62 # quiet output for Makefiles, 'make -s' helps too
63 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
64
65 #-----------------------------------------------------------------------------
66 # Load some macros.
67 include(build_files/cmake/macros.cmake)
68
69
70 #-----------------------------------------------------------------------------
71 # Initialize project.
72
73 blender_project_hack_pre()
74
75 project(Blender)
76
77 blender_project_hack_post()
78
79 enable_testing()
80
81 #-----------------------------------------------------------------------------
82 # Redirect output files
83
84 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
85 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
86
87 #-----------------------------------------------------------------------------
88 # Set default config options
89
90 get_blender_version()
91
92 # Blender internal features
93 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
94 mark_as_advanced(WITH_BLENDER)
95
96 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
97
98 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
99 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
100 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
101 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distrobutions see this as a security issue, rather than have them patch it, make a build option.
102
103 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
104 option(WITH_PYTHON_MODULE "Enable building as a python module (experemental, only enable for development)" OFF)
105 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
106 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
107 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
108 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
109 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
110 option(WITH_PLAYER        "Build Player" OFF)
111
112 # GHOST Windowing Library Options
113 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
114 mark_as_advanced(WITH_GHOST_DEBUG)
115
116 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
117 mark_as_advanced(WITH_GHOST_SDL)
118
119 # Misc...
120 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
121 mark_as_advanced(WITH_HEADLESS)
122
123 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
124 mark_as_advanced(WITH_AUDASPACE)
125
126
127 # (unix defaults to OpenMP On)
128 if(UNIX AND NOT APPLE)
129         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
130 else()
131         option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" OFF)
132 endif()
133
134 if(UNIX AND NOT APPLE)
135         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support)"     ON)
136         option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
137 else()
138         # not an option for other OS's
139         set(WITH_BUILTIN_GLEW ON)
140 endif()
141
142 # Modifiers
143 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
144 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
145 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
146 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
147 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experemental cloth solver" OFF)
148 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
149
150 # Image format support
151 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
152 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
153 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
154 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
155 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
156 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
157 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
158
159 # Audio/Video format support
160 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
161 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
162 if(APPLE OR (WIN32 AND NOT UNIX))
163         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
164 endif()
165
166 # 3D format support
167 # disable opencollada on non-apple unix because opencollada has no package for debian
168 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
169
170 # Sound output
171 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
172 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
173 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
174 option(WITH_SAMPLERATE    "Enable samplerate conversion" ON)
175
176 # Compression
177 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
178 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
179
180 # Misc
181 option(WITH_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
182 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON) 
183 if(UNIX AND NOT APPLE)
184         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
185 endif()
186 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
187
188 # disable for now, but plan to support on all platforms eventually
189 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
190 mark_as_advanced(WITH_MEM_JEMALLOC)
191
192 # Debug
193 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
194 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
195
196 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
197 mark_as_advanced(WITH_ASSERT_ABORT)
198
199 if(APPLE)
200         if(NOT CMAKE_OSX_ARCHITECTURES)
201                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
202                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
203                 FORCE)
204         endif()
205         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
206                 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.5 CACHE STRING
207                 "Choose the minimum OSX version required: 10.4 or 10.5"
208                 FORCE)
209         endif()
210         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
211         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
212         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
213 endif()
214
215 #-----------------------------------------------------------------------------
216 # Check for conflicting/unsupported configurations
217
218 if(NOT WITH_BLENDER AND NOT WITH_PLAYER)
219         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
220 endif()
221
222 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
223         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
224 endif()
225
226 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
227         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
228 endif()
229
230 if(NOT WITH_SDL AND WITH_GHOST_SDL)
231         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
232 endif()
233
234 if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
235         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG")
236 endif()
237
238 # python module, needs some different options
239 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
240         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
241 endif()
242
243 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
244         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
245 endif()
246
247 if(WITH_CODEC_QUICKTIME AND MINGW)
248         message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
249                                                 "because it is currently unsupported, remove this "
250                                                 "line if youre a developer who wants to add support.")
251 endif()
252
253 # may as well build python module without a UI
254 if(WITH_PYTHON_MODULE)
255         set(WITH_HEADLESS ON)
256 endif()
257
258 TEST_SSE_SUPPORT()
259
260 #-----------------------------------------------------------------------------
261 # Initialize un-cached vars, avoid unused warning
262
263 # linux only, not cached
264 set(WITH_BINRELOC OFF)
265
266 # MAXOSX only, set to avoid uninitialized 
267 set(EXETYPE)
268
269 # C/C++ flags
270 set(PLATFORM_CFLAGS)
271
272 # these are added to later on.
273 set(C_WARNINGS)
274 set(CXX_WARNINGS)
275
276 # libraries to link the binary with passed to target_link_libraries()
277 # known as LLIBS to scons
278 set(PLATFORM_LINKLIBS)
279
280 # Added to linker flags in setup_liblinks
281 # - CMAKE_EXE_LINKER_FLAGS
282 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
283 set(PLATFORM_LINKFLAGS)
284 set(PLATFORM_LINKFLAGS_DEBUG)
285
286
287 # disabled for now, not supported
288 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
289
290 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
291 # On Unix: 
292 #   cmake ../blender \
293 #         -D PYTHON_VERSION=3.2 \
294 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
295 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
296 #
297 # On Macs: 
298 #   cmake ../blender \
299 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
300 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
301 #         -G Xcode
302 #
303 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
304
305 #-----------------------------------------------------------------------------
306 #Platform specifics
307
308 if(UNIX AND NOT APPLE)
309         
310         # needed for ubuntu 11.04
311         if(EXISTS "/usr/lib/x86_64-linux-gnu")
312                 set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
313         endif()
314
315         find_package(JPEG REQUIRED)
316         find_package(PNG REQUIRED)
317         find_package(ZLIB REQUIRED)
318         find_package(Freetype REQUIRED)
319
320         if(WITH_PYTHON)
321                 # No way to set py32. remove for now.
322                 # find_package(PythonLibs)
323
324                 # Use our own instead, since wothout py is such a rare case,
325                 # require this package
326                 find_package(PythonLibsUnix REQUIRED)
327         endif()
328
329
330         if(WITH_IMAGE_OPENEXR)
331                 find_package(OpenEXR)  # our own module
332                 if(NOT OPENEXR_FOUND)
333                         set(WITH_IMAGE_OPENEXR OFF)
334                 endif()
335         endif()
336
337         if(WITH_IMAGE_OPENJPEG)
338                 find_package(OpenJPEG)
339                 if(NOT OPENJPEG_FOUND)
340                         set(WITH_IMAGE_OPENJPEG OFF)
341                 endif()
342         endif()
343
344         if(WITH_IMAGE_TIFF)
345                 find_package(TIFF)
346                 if(NOT TIFF_FOUND)
347                         set(WITH_IMAGE_TIFF OFF)
348                 endif()
349         endif()
350
351         # Audio IO
352         if(WITH_OPENAL)
353                 find_package(OpenAL)
354                 if(NOT OPENAL_FOUND)
355                         set(WITH_OPENAL OFF)
356                 endif()
357         endif()
358
359         if(WITH_SDL)
360                 find_package(SDL)
361                 mark_as_advanced(SDLMAIN_LIBRARY)
362                 mark_as_advanced(SDL_INCLUDE_DIR)
363                 mark_as_advanced(SDL_LIBRARY)
364                 mark_as_advanced(SDL_LIBRARY_TEMP)
365                 # unset(SDLMAIN_LIBRARY CACHE)
366                 if(NOT SDL_FOUND)
367                         set(WITH_SDL OFF)
368                 endif()
369         endif()
370
371         if(WITH_JACK)
372                 find_package(Jack)
373                 if(NOT JACK_FOUND)
374                         set(WITH_JACK OFF)
375                 endif()
376         endif()
377
378         # Codecs
379         if(WITH_CODEC_SNDFILE)
380                 find_package(SndFile)
381                 if(NOT SNDFILE_FOUND)
382                         set(WITH_CODEC_SNDFILE OFF)
383                 endif()
384         endif()
385
386         if(WITH_CODEC_FFMPEG)
387                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
388                 mark_as_advanced(FFMPEG)
389                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
390                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
391                 mark_as_advanced(FFMPEG_LIBRARIES)
392                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
393                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
394         endif()
395
396         if(WITH_INTERNATIONAL)
397                 find_library(INTL_LIBRARY
398                         NAMES intl
399                         PATHS
400                         /sw/lib
401                 )
402
403                 find_library(ICONV_LIBRARY
404                         NAMES iconv
405                         PATHS
406                         /sw/lib
407                 )
408                 mark_as_advanced(ICONV_LIBRARY)
409                 mark_as_advanced(INTL_LIBRARY)
410
411                 if(INTL_LIBRARY AND ICONV_LIBRARY)
412                         set(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
413                 endif()
414         endif()
415
416         if(WITH_FFTW3)
417                 find_package(Fftw3)
418                 if(NOT FFTW3_FOUND)
419                         set(WITH_FFTW3 OFF)
420                 endif()
421         endif()
422
423         if(WITH_SAMPLERATE)
424                 find_package(Samplerate)
425                 if(NOT SAMPLERATE_FOUND)
426                         set(WITH_SAMPLERATE OFF)
427                 endif()
428         endif()
429
430         if(WITH_OPENCOLLADA)
431                 set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory")
432                 mark_as_advanced(OPENCOLLADA)
433                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
434                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
435                 set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA})
436
437                 set(PCRE /usr CACHE PATH "PCRE Directory")
438                 mark_as_advanced(PCRE)
439                 set(PCRE_LIBPATH ${PCRE}/lib)
440                 set(PCRE_LIB pcre)
441
442                 set(EXPAT /usr CACHE PATH "Expat Directory")
443                 mark_as_advanced(EXPAT)
444                 set(EXPAT_LIBPATH ${EXPAT}/lib)
445                 set(EXPAT_LIB expat)
446         endif()
447
448         if(WITH_MEM_JEMALLOC)
449                 find_package(JeMalloc)
450                 if(NOT JEMALLOC_FOUND)
451                         set(WITH_MEM_JEMALLOC OFF)
452                 endif()
453         endif()
454
455         if (WITH_NDOF)
456                 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
457                         set(NDOF /usr)
458                         set(NDOF_INC ${NDOF}/include)
459                         set(NDOF_LIBRARY spnav)
460                         set(NDOF_LIBPATH ${NDOF}/lib)
461                 endif()
462         endif()
463
464         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
465         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
466
467         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
468                 find_package(X11 REQUIRED)
469                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
470                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
471
472                 list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
473
474                 if(WITH_X11_XINPUT)
475                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
476                 endif()
477         endif()
478
479         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
480                 if(NOT WITH_PYTHON_MODULE)
481                         # BSD's dont use libdl.so
482                         list(APPEND PLATFORM_LINKLIBS -ldl)
483                         # binreloc is linux only
484                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
485                         set(WITH_BINRELOC ON)
486                 endif()
487         endif()
488
489         set(PLATFORM_LINKFLAGS "-pthread")
490
491         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
492         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
493
494         # GNU Compiler
495         if(CMAKE_COMPILER_IS_GNUCC)
496                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
497         # Intel C++ Compiler
498         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
499                 # think these next two are broken
500                 find_program(XIAR xiar) 
501                 if(XIAR) 
502                         set(CMAKE_AR "${XIAR}")
503                 endif() 
504                 mark_as_advanced(XIAR)
505
506                 find_program(XILD xild) 
507                 if(XILD) 
508                         set(CMAKE_LINKER "${XILD}")
509                 endif() 
510                 mark_as_advanced(XILD)
511
512                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
513                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
514
515                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
516                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
517                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
518         endif()
519
520 elseif(WIN32)
521
522         # this file is included anyway when building under Windows with cl.exe
523         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
524
525         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
526
527         # Setup 64bit and 64bit windows systems
528         if(CMAKE_CL_64)
529                 message("64 bit compiler detected.")
530                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
531         endif()
532         
533         add_definitions(-DWIN32)
534
535         if(WITH_INTERNATIONAL)
536                 set(ICONV ${LIBDIR}/iconv)
537                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
538                 set(ICONV_LIBRARIES iconv)
539                 set(ICONV_LIBPATH ${ICONV}/lib)
540         endif()
541
542         if(WITH_SAMPLERATE)
543                 set(SAMPLERATE ${LIBDIR}/samplerate)
544                 set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
545                 set(SAMPLERATE_LIBRARIES libsamplerate)
546                 set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
547         endif()
548
549         set(PNG "${LIBDIR}/png")
550         set(PNG_INCLUDE_DIR "${PNG}/include")
551         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
552
553         set(JPEG "${LIBDIR}/jpeg")
554         set(JPEG_INCLUDE_DIR "${JPEG}/include")
555         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
556
557         set(WINTAB_INC ${LIBDIR}/wintab/include) 
558
559         if(WITH_OPENAL)
560                 set(OPENAL ${LIBDIR}/openal)
561                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
562                 set(OPENAL_LIBRARY wrap_oal)
563                 set(OPENAL_LIBPATH ${OPENAL}/lib)
564         endif()
565
566         if(WITH_CODEC_SNDFILE)
567                 set(SNDFILE ${LIBDIR}/sndfile)
568                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
569                 set(SNDFILE_LIBRARIES libsndfile-1)
570                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
571         endif()
572
573         if(WITH_SDL)
574                 set(SDL ${LIBDIR}/sdl)
575                 set(SDL_INCLUDE_DIR ${SDL}/include)
576                 set(SDL_LIBRARY SDL)
577                 set(SDL_LIBPATH ${SDL}/lib)
578         endif()
579
580         if(WITH_CODEC_QUICKTIME)
581                 set(QUICKTIME ${LIBDIR}/QTDevWin)
582                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
583                 set(QUICKTIME_LIBRARIES qtmlClient)
584                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
585         endif()
586
587         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
588                 add_definitions(-D__SSE__ -D__MMX__)
589         endif()
590
591         if(MSVC)
592                 if(CMAKE_CL_64)
593                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
594                 else()
595                         set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
596                 endif()
597
598                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
599
600                 set(CMAKE_CXX_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
601                 set(CMAKE_C_FLAGS   "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
602
603                 if(CMAKE_CL_64)
604                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
605                 else()
606                         set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
607                 endif()
608                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
609                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
610                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
611                 if(CMAKE_CL_64)
612                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
613                 else()
614                         set(CMAKE_C_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /ZI /J" CACHE STRING "MSVC MT flags " FORCE)
615                 endif()
616                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
617                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /J" CACHE STRING "MSVC MT flags " FORCE)
618                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /DNDEBUG /EHsc /MT /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
619
620                 if(WITH_INTERNATIONAL)
621                         set(GETTEXT ${LIBDIR}/gettext)
622                         set(GETTEXT_INC ${GETTEXT}/include)
623                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
624                         if(CMAKE_CL_64)
625                                 set(GETTEXT_LIB gettext)
626                         else()
627                                 set(GETTEXT_LIB gnu_gettext)
628                         endif()
629                 endif()
630
631                 if(CMAKE_CL_64)
632                         set(PNG_LIBRARIES libpng)
633                 else()
634                         set(PNG_LIBRARIES libpng_st)
635                 endif()
636                 set(JPEG_LIBRARIES libjpeg)
637
638                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
639                 if(CMAKE_CL_64)
640                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
641                 else()
642                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
643                 endif()
644
645                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
646                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
647
648                 set(FREETYPE ${LIBDIR}/freetype)
649                 set(FREETYPE_INCLUDE_DIRS
650                         ${LIBDIR}/freetype/include
651                         ${LIBDIR}/freetype/include/freetype2
652                 )
653                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
654
655                 if(WITH_FFTW3)
656                         set(FFTW3 ${LIBDIR}/fftw3)
657                         set(FFTW3_LIBRARIES libfftw)
658                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
659                         set(FFTW3_LIBPATH ${FFTW3}/lib)
660                 endif()
661
662                 if(WITH_OPENCOLLADA)
663                         set(OPENCOLLADA_INCLUDE_DIR
664                                 ${LIBDIR}/opencollada/include
665                         )
666                         set(OPENCOLLADA_LIBRARIES
667                                 ${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
668                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
669                                 ${LIBDIR}/opencollada/lib/OpenCOLLADABaseUtils.lib
670                                 ${LIBDIR}/opencollada/lib/OpenCOLLADAStreamWriter.lib
671                                 ${LIBDIR}/opencollada/lib/MathMLSolver.lib
672                                 ${LIBDIR}/opencollada/lib/GeneratedSaxParser.lib
673                                 ${LIBDIR}/opencollada/lib/xml2.lib
674                                 ${LIBDIR}/opencollada/lib/buffer.lib
675                                 ${LIBDIR}/opencollada/lib/ftoa.lib
676                                 ${LIBDIR}/opencollada/lib/UTF.lib
677                         )
678                         set(PCRE_LIB
679                                 ${LIBDIR}/opencollada/lib/pcre.lib
680                         )
681                 endif()
682
683                 if(WITH_CODEC_FFMPEG)
684                         set(FFMPEG_INCLUDE_DIRS
685                                 ${LIBDIR}/ffmpeg/include
686                                 ${LIBDIR}/ffmpeg/include/msvc
687                         )
688                         set(FFMPEG_LIBRARIES
689                                 ${LIBDIR}/ffmpeg/lib/avcodec-52.lib
690                                 ${LIBDIR}/ffmpeg/lib/avformat-52.lib
691                                 ${LIBDIR}/ffmpeg/lib/avdevice-52.lib
692                                 ${LIBDIR}/ffmpeg/lib/avutil-50.lib
693                                 ${LIBDIR}/ffmpeg/lib/swscale-0.lib
694                         )
695                 endif()
696
697                 if(WITH_IMAGE_OPENEXR)
698                         if(MSVC90)
699                                 set(MSVC_LIB _vs2008)
700                                 set(MSVC_INC)
701                         elseif(MSVC10)
702                                 set(MSVC_LIB _vs2010)
703                                 set(MSVC_INC _vs2010)
704                         else()
705                                 set(MSVC_LIB msvc)
706                                 set(MSVC_INC)
707                         endif()
708                         set(OPENEXR ${LIBDIR}/openexr)
709                         set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
710                         set(OPENEXR_LIBRARIES
711                                 ${OPENEXR_LIBPATH}/Iex.lib
712                                 ${OPENEXR_LIBPATH}/Half.lib
713                                 ${OPENEXR_LIBPATH}/IlmImf.lib
714                                 ${OPENEXR_LIBPATH}/Imath.lib
715                                 ${OPENEXR_LIBPATH}/IlmThread.lib
716                         )
717                         set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
718                         set(OPENEXR_INCLUDE_DIRS
719                                 ${OPENEXR_INCUDE}
720                                 ${OPENEXR_INCUDE}/IlmImf
721                                 ${OPENEXR_INCUDE}/Iex
722                                 ${OPENEXR_INCUDE}/Imath
723                         )
724                         unset(OPENEXR_INCUDE)
725                         unset(OPENEXR_LIBPATH)
726                 endif()
727
728                 if(WITH_IMAGE_TIFF)
729                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
730                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
731                 endif()
732
733                 if(WITH_JACK)
734                         set(JACK_INCLUDE_DIRS
735                                 ${LIBDIR}/jack/include/jack
736                                 ${LIBDIR}/jack/include
737                         )
738                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
739                 endif()
740
741                 if(WITH_PYTHON)
742                         # normally cached but not since we include them with blender
743                         set(PYTHON_VERSION 3.2) # CACHE STRING)
744                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}") # CACHE PATH)
745                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32.lib") #CACHE FILEPATH)
746
747                         # uncached vars
748                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
749                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
750                 endif()
751
752                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
753
754                 # MSVC only, Mingw doesnt need
755                 if(CMAKE_CL_64)
756                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
757                 else()
758                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
759                 endif()
760
761                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
762
763         else()
764                 # keep GCC spesific stuff here
765                 if(CMAKE_COMPILER_IS_GNUCC)
766                         set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
767                         set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
768
769                         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
770                 endif()
771
772                 add_definitions(-DFREE_WINDOWS)
773
774                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
775                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
776
777                 if(WITH_INTERNATIONAL)
778                         set(GETTEXT ${LIBDIR}/gcc/gettext)
779                         set(GETTEXT_INC ${GETTEXT}/include)
780                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
781                         set(GETTEXT_LIB intl)
782                 endif()
783
784                 set(JPEG_LIBRARIES libjpeg)
785                 set(PNG_LIBRARIES png)
786
787                 set(ZLIB ${LIBDIR}/zlib)
788                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
789                 set(ZLIB_LIBPATH ${ZLIB}/lib)
790                 set(ZLIB_LIBRARIES z)
791
792                 set(PTHREADS ${LIBDIR}/pthreads)
793                 set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
794                 set(PTHREADS_LIBPATH ${PTHREADS}/lib)
795                 set(PTHREADS_LIBRARIES pthreadGC2)
796                 
797                 set(FREETYPE ${LIBDIR}/gcc/freetype)
798                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
799                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
800                 set(FREETYPE_LIBRARY freetype)
801
802                 if(WITH_FFTW3)
803                         set(FFTW3 ${LIBDIR}/gcc/fftw3)
804                         set(FFTW3_LIBRARIES fftw3)
805                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
806                         set(FFTW3_LIBPATH ${FFTW3}/lib)
807                 endif()
808
809                 if(WITH_OPENCOLLADA)
810                         set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
811                         set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
812                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
813                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
814                         set(PCRE_LIB pcre)
815                 endif()
816                 
817                 if(WITH_CODEC_FFMPEG)
818                         set(FFMPEG ${LIBDIR}/ffmpeg)
819                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
820                         set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
821                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
822                 endif()
823
824                 if(WITH_IMAGE_OPENEXR)
825                         set(OPENEXR ${LIBDIR}/gcc/openexr)
826                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
827                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
828                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
829                 endif()
830
831                 if(WITH_IMAGE_TIFF)
832                         set(TIFF ${LIBDIR}/gcc/tiff)
833                         set(TIFF_LIBRARY tiff)
834                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
835                         set(TIFF_LIBPATH ${TIFF}/lib)
836                 endif()
837
838                 if(WITH_JACK)
839                         set(JACK ${LIBDIR}/jack)
840                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
841                         set(JACK_LIBRARIES jack)
842                         set(JACK_LIBPATH ${JACK}/lib)
843                         
844                         # TODO, gives linking errors, force off
845                         set(WITH_JACK OFF)
846                 endif()
847
848                 if(WITH_PYTHON)
849                         # normally cached but not since we include them with blender
850                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
851                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
852                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
853
854                         # uncached vars
855                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
856                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
857                 endif()
858
859                 set(PLATFORM_LINKFLAGS "--stack,2097152")
860
861         endif()
862
863         # used in many places so include globally, like OpenGL
864         blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
865
866 elseif(APPLE)
867
868         if (${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5")
869                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE)
870         endif()
871
872         if(WITH_LIBS10.5)
873                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
874         else()
875                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
876                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
877                 else()
878                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
879                 endif()
880         endif()
881         
882
883         if(WITH_OPENAL)
884                 find_package(OpenAL)
885                 if(OPENAL_FOUND)
886                         set(WITH_OPENAL ON)
887                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
888                 else()
889                         set(WITH_OPENAL OFF)
890                 endif()
891         endif()
892
893         if(WITH_JACK)
894                 set(JACK /usr)
895                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
896                 set(JACK_LIBRARIES jack)
897                 set(JACK_LIBPATH ${JACK}/lib)
898         endif()
899
900         if(WITH_CODEC_SNDFILE)
901                 set(SNDFILE ${LIBDIR}/sndfile)
902                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
903                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
904                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
905         endif()
906
907         if(WITH_PYTHON)
908                 set(PYTHON_VERSION 3.2)
909                 if(PYTHON_VERSION MATCHES 3.2)
910                         # we use precompiled libraries for py 3.2 and up by default
911
912                         # normally cached but not since we include them with blender
913                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
914                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
915                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
916                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
917                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
918                 else()
919                         # otherwise, use custom system framework
920                         # *not used but maintained incase some dev wants to*
921
922                         set(PYTHON "/System/Library/Frameworks/Python.framework/Versions/" CACHE PATH)
923                         set(PYTHON_INCLUDE_DIR "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}" CACHE PATH)
924                         # set(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
925                         set(PYTHON_LIBRARY "" CACHE FILEPATH)
926                         set(PYTHON_LIBPATH "${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config" CACHE PATH)
927                         set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python" CACHE STRING)
928                         unset(PYTHON)
929                 endif()
930
931                 # uncached vars
932                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
933                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
934         endif()
935
936         if(WITH_INTERNATIONAL)
937                 set(GETTEXT ${LIBDIR}/gettext)
938                 set(GETTEXT_INC "${GETTEXT}/include")
939                 set(GETTEXT_LIB intl iconv)
940                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
941         endif()
942
943         if(WITH_FFTW3)
944                 set(FFTW3 ${LIBDIR}/fftw3)
945                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
946                 set(FFTW3_LIBRARIES fftw3)
947                 set(FFTW3_LIBPATH ${FFTW3}/lib)
948         endif()
949
950         set(PNG_LIBRARIES png)
951         set(JPEG_LIBRARIES jpeg)
952
953         set(ZLIB /usr)
954         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
955         set(ZLIB_LIBRARIES z bz2)
956
957         set(FREETYPE ${LIBDIR}/freetype)
958         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
959         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
960         set(FREETYPE_LIBRARY freetype)
961
962         if(WITH_IMAGE_OPENEXR)
963                 set(OPENEXR ${LIBDIR}/openexr)
964                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
965                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
966                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
967         endif()
968
969         if(WITH_CODEC_FFMPEG)
970                 set(FFMPEG ${LIBDIR}/ffmpeg)
971                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
972                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
973                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
974                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
975         endif()
976
977         if(WITH_SAMPLERATE)
978                 set(SAMPLERATE ${LIBDIR}/samplerate)
979                 set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
980                 set(SAMPLERATE_LIBRARIES samplerate)
981                 set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
982         endif()
983
984         set(PLATFORM_LINKLIBS stdc++ SystemStubs)
985
986         if(WITH_COCOA)
987                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
988                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
989                 if(USE_QTKIT)
990                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
991                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
992                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
993                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
994                                 #libSDL still needs 32bit carbon quicktime 
995                         endif()
996                 elseif(WITH_CODEC_QUICKTIME)
997                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
998                 endif()
999         else()
1000                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1001                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1002         endif()
1003
1004         if(WITH_OPENCOLLADA)
1005                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1006                 set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
1007                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1008                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
1009                 #pcre is bundled with openCollada
1010                 #set(PCRE ${LIBDIR}/pcre)
1011                 #set(PCRE_LIBPATH ${PCRE}/lib)
1012                 set(PCRE_LIB pcre)
1013                 #libxml2 is used
1014                 #set(EXPAT ${LIBDIR}/expat)
1015                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1016                 set(EXPAT_LIB)
1017         endif()
1018
1019         if(WITH_SDL)
1020                 set(SDL ${LIBDIR}/sdl)
1021                 set(SDL_INCLUDE_DIR ${SDL}/include)
1022                 set(SDL_LIBRARY SDL)
1023                 set(SDL_LIBPATH ${SDL}/lib)
1024         endif()
1025
1026         set(PNG "${LIBDIR}/png")
1027         set(PNG_INCLUDE_DIR "${PNG}/include")
1028         set(PNG_LIBPATH ${PNG}/lib)
1029
1030         set(JPEG "${LIBDIR}/jpeg")
1031         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1032         set(JPEG_LIBPATH ${JPEG}/lib)
1033
1034         if(WITH_IMAGE_TIFF)
1035                 set(TIFF ${LIBDIR}/tiff)
1036                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1037                 set(TIFF_LIBRARY tiff)
1038                 set(TIFF_LIBPATH ${TIFF}/lib)
1039         endif()
1040
1041         if (WITH_NDOF)
1042                 # GHOST_NDOFManagerCocoa.mm needs "-fpascal-strings"
1043                 # linker needs "-weak_framework 3DconnexionClient"
1044         endif()
1045
1046         set(EXETYPE MACOSX_BUNDLE)
1047
1048         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1049         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1050         if(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1051                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1052                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -fvariable-expansion-in-unroller")
1053         elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
1054                 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1055                 set(CMAKE_C_FLAGS_RELEASE "-O3 -mdynamic-no-pic -ftree-vectorize -msse -msse2 -msse3 -mssse3 -fvariable-expansion-in-unroller")
1056         else()
1057                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1058                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1059         endif()
1060 endif()
1061
1062 #-----------------------------------------------------------------------------
1063 # Common.
1064
1065 if(APPLE OR WIN32)
1066         if(NOT EXISTS "${LIBDIR}/")
1067                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1068         endif()
1069 endif()
1070
1071 if(WITH_RAYOPTIMIZATION)
1072         if(CMAKE_COMPILER_IS_GNUCC)
1073                 if(SUPPORT_SSE_BUILD)
1074                         set(PLATFORM_CFLAGS " -msse ${PLATFORM_CFLAGS}")
1075                         add_definitions(-D__SSE__ -D__MMX__)
1076                 endif()
1077                 if(SUPPORT_SSE2_BUILD)
1078                         set(PLATFORM_CFLAGS " -msse2 ${PLATFORM_CFLAGS}")
1079                         add_definitions(-D__SSE2__)
1080                         if(NOT SUPPORT_SSE_BUILD) # dont double up
1081                                 add_definitions(-D__MMX__)
1082                         endif()
1083                 endif()
1084         endif()
1085 endif()
1086
1087 if(WITH_IMAGE_OPENJPEG)
1088         if(UNIX AND NOT APPLE)
1089                 # dealt with above
1090         else()
1091                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1092         endif()
1093 endif()
1094
1095 if(WITH_IMAGE_REDCODE)
1096         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1097         set(REDCODE_INC ${REDCODE})
1098 endif()
1099
1100 #-----------------------------------------------------------------------------
1101 # Blender WebPlugin
1102
1103 if(WITH_WEBPLUGIN) 
1104         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1105         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1106
1107         set(WITH_PLAYER ON)
1108 endif()
1109
1110
1111 #-----------------------------------------------------------------------------
1112 # Configure OpenGL.
1113 find_package(OpenGL)
1114 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1115 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
1116 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
1117
1118 #-----------------------------------------------------------------------------
1119 # Configure OpenMP.
1120 if(WITH_OPENMP)
1121         find_package(OpenMP)    
1122         if(OPENMP_FOUND)
1123                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1124                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1125
1126                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1127                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1128                 endif()
1129         else()
1130                 set(WITH_OPENMP OFF)
1131         endif()
1132
1133         mark_as_advanced(OpenMP_C_FLAGS)
1134         mark_as_advanced(OpenMP_CXX_FLAGS)
1135 endif() 
1136
1137 #-----------------------------------------------------------------------------
1138 # Configure GLEW
1139
1140 if(WITH_BUILTIN_GLEW)
1141         # set(GLEW_LIBRARY "")  # unused
1142         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1143 else()
1144         find_package(GLEW)
1145
1146         if(NOT GLEW_FOUND)
1147                 message(FATAL_ERROR "GLEW is required to build blender, install it or use WITH_BUILTIN_GLEW")
1148         endif()
1149
1150         mark_as_advanced(GLEW_LIBRARY)
1151         mark_as_advanced(GLEW_INCLUDE_PATH)
1152 endif()
1153
1154 #-----------------------------------------------------------------------------
1155 # Configure Python.
1156
1157 if(WITH_PYTHON_MODULE)
1158         add_definitions(-DPy_ENABLE_SHARED)
1159 endif() 
1160
1161 #-----------------------------------------------------------------------------
1162 # Extra compile flags
1163
1164 if((NOT WIN32) AND (NOT MSVC))
1165         # used for internal debug checks
1166         set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
1167         set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
1168         
1169         # assert() checks for this.
1170         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
1171         set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -DNDEBUG")
1172         set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1173
1174         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
1175         set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
1176         set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DNDEBUG")
1177 endif()
1178
1179 if(CMAKE_COMPILER_IS_GNUCC)
1180
1181         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1182         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1183         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1184         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1185         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE -Werror=return-type)
1186         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1187         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES -Wstrict-prototypes)
1188         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1189         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1190         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1191         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1192         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1193         # disable because it gives warnings for printf() & friends.
1194         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1195         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1196
1197         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1198         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1199         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1200
1201 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1202
1203         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1204         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1205         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1206
1207         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1208         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1209         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1210
1211 endif()
1212
1213 # MSVC2010 fails to links C++ libs right
1214 if(MSVC10)
1215         if(WITH_IMAGE_OPENEXR)
1216                 message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
1217                 set(WITH_IMAGE_OPENEXR OFF)
1218         endif()
1219         if(WITH_OPENCOLLADA)
1220                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1221                 set(WITH_OPENCOLLADA OFF)
1222         endif()
1223 endif()
1224
1225 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1226         if(WITH_IK_ITASC OR WITH_MOD_FLUID)
1227                 message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
1228                 set(WITH_IK_ITASC OFF)
1229                 set(WITH_MOD_FLUID OFF)
1230         endif()
1231 endif()
1232
1233
1234 # ensure python header is found since detection can fail, this could happen
1235 # with _any_ library but since we used a fixed python version this tends to
1236 # be most problematic.
1237 if(WITH_PYTHON)
1238         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1239                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1240                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1241                                                         "to a valid python include path. Containing "
1242                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1243         endif()
1244 endif()
1245
1246
1247 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1248 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1249
1250 #-------------------------------------------------------------------------------
1251 # Global Defines
1252
1253 # better not set includes here but this debugging option is off by default.
1254 if(WITH_CXX_GUARDEDALLOC)
1255         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1256 endif()
1257
1258 if(WITH_ASSERT_ABORT)
1259         add_definitions(-DWITH_ASSERT_ABORT)
1260 endif()
1261
1262 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1263 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1264
1265 #-----------------------------------------------------------------------------
1266 # Libraries
1267
1268 add_subdirectory(source)
1269 add_subdirectory(intern)
1270 add_subdirectory(extern)
1271
1272
1273 #-----------------------------------------------------------------------------
1274 # Blender Application
1275 if(WITH_BLENDER)
1276         add_subdirectory(source/creator)
1277 endif()
1278
1279
1280 #-----------------------------------------------------------------------------
1281 # Blender Player
1282 if(WITH_PLAYER)
1283         add_subdirectory(source/blenderplayer)
1284 endif()
1285
1286 #-----------------------------------------------------------------------------
1287 # CPack for generating packages
1288 include(build_files/cmake/packaging.cmake)
1289
1290
1291 #-----------------------------------------------------------------------------
1292 # Print Final Configuration
1293
1294 if(FIRST_RUN)
1295         set(_config_msg "\n* Blender Configuration *")
1296         macro(info_cfg_option
1297                 _setting)
1298                 set(_msg "   * ${_setting}")
1299                 string(LENGTH "${_msg}" _len)
1300                 while("28" GREATER "${_len}")
1301                         set(_msg "${_msg} ")
1302                          math(EXPR _len "${_len} + 1")
1303                 endwhile()
1304
1305                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
1306         endmacro()
1307
1308         macro(info_cfg_text
1309                 _text)
1310                 set(_config_msg "${_config_msg}\n\n  ${_text}")
1311                 
1312                 
1313         endmacro()
1314
1315         info_cfg_text("Build Options:")
1316         info_cfg_option(WITH_GAMEENGINE)
1317         info_cfg_option(WITH_PLAYER)
1318         info_cfg_option(WITH_BULLET)
1319         info_cfg_option(WITH_IK_ITASC)
1320         info_cfg_option(WITH_OPENCOLLADA)
1321         info_cfg_option(WITH_FFTW3)
1322         info_cfg_option(WITH_INTERNATIONAL)
1323
1324         info_cfg_text("Compiler Options:")
1325         info_cfg_option(WITH_BUILDINFO)
1326         info_cfg_option(WITH_OPENMP)
1327         info_cfg_option(WITH_RAYOPTIMIZATION)
1328
1329         info_cfg_text("System Options:")
1330         info_cfg_option(WITH_INSTALL_PORTABLE)
1331         info_cfg_option(WITH_X11_XINPUT)
1332         info_cfg_option(WITH_BUILTIN_GLEW)
1333
1334         info_cfg_text("Image Formats:")
1335         info_cfg_option(WITH_IMAGE_CINEON)
1336         info_cfg_option(WITH_IMAGE_DDS)
1337         info_cfg_option(WITH_IMAGE_HDR)
1338         info_cfg_option(WITH_IMAGE_OPENEXR)
1339         info_cfg_option(WITH_IMAGE_OPENJPEG)
1340         info_cfg_option(WITH_IMAGE_REDCODE)
1341         info_cfg_option(WITH_IMAGE_TIFF)
1342
1343         info_cfg_text("Audio:")
1344         info_cfg_option(WITH_OPENAL)
1345         info_cfg_option(WITH_SDL)
1346         info_cfg_option(WITH_JACK)
1347         info_cfg_option(WITH_CODEC_FFMPEG)
1348         info_cfg_option(WITH_CODEC_SNDFILE)
1349         info_cfg_option(WITH_SAMPLERATE)
1350
1351         info_cfg_text("Compression:")
1352         info_cfg_option(WITH_LZMA)
1353         info_cfg_option(WITH_LZO)
1354
1355         info_cfg_text("Python:")
1356         info_cfg_option(WITH_PYTHON_INSTALL)
1357         info_cfg_option(WITH_PYTHON_MODULE)
1358         info_cfg_option(WITH_PYTHON_SAFETY)
1359
1360         info_cfg_text("Modifiers:")
1361         info_cfg_option(WITH_MOD_BOOLEAN)
1362         info_cfg_option(WITH_MOD_DECIMATE)
1363         info_cfg_option(WITH_MOD_FLUID)
1364
1365         info_cfg_text("")
1366
1367         message("${_config_msg}")
1368 endif()