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