Freestyle: fix crash unlinking object
[blender.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT EXECUTABLE_OUTPUT_PATH)
51         set(FIRST_RUN "TRUE")
52 endif()
53
54 # this starts out unset
55 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
56
57 # avoid having empty buildtype
58 set(CMAKE_BUILD_TYPE_INIT "Release")
59
60 # quiet output for Makefiles, 'make -s' helps too
61 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
62
63 # global compile definitions since add_definitions() adds for all.
64 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
65 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
66 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
67 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
68
69
70 #-----------------------------------------------------------------------------
71 # Set policy
72
73 # see "cmake --help-policy CMP0003"
74 # So library linking is more sane
75 cmake_policy(SET CMP0003 NEW)
76
77 # So BUILDINFO and BLENDERPATH strings are automatically quoted
78 cmake_policy(SET CMP0005 NEW)
79
80 # So syntax problems are errors
81 cmake_policy(SET CMP0010 NEW)
82
83 # Input directories must have CMakeLists.txt
84 cmake_policy(SET CMP0014 NEW)
85
86 #-----------------------------------------------------------------------------
87 # Load some macros.
88 include(build_files/cmake/macros.cmake)
89
90
91 #-----------------------------------------------------------------------------
92 # Initialize project.
93
94 blender_project_hack_pre()
95
96 project(Blender)
97
98 blender_project_hack_post()
99
100 enable_testing()
101
102 #-----------------------------------------------------------------------------
103 # Redirect output files
104
105 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
106 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
107
108 #-----------------------------------------------------------------------------
109 # Set default config options
110
111 get_blender_version()
112
113
114 # Blender internal features
115 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
116 mark_as_advanced(WITH_BLENDER)
117
118 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
119
120 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
121 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
122 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
123 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
124
125 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)
126 option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development)" OFF)
127 if(APPLE)
128         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
129 endif()
130
131 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
132 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
133 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
134 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ON)
135 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
136 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
137 mark_as_advanced(WITH_SYSTEM_BULLET)
138 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
139 option(WITH_PLAYER        "Build Player" OFF)
140 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
141 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
142
143 # GHOST Windowing Library Options
144 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
145 mark_as_advanced(WITH_GHOST_DEBUG)
146
147 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
148 mark_as_advanced(WITH_GHOST_SDL)
149
150 # Misc...
151 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
152 mark_as_advanced(WITH_HEADLESS)
153
154 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
155 mark_as_advanced(WITH_AUDASPACE)
156
157 option(WITH_BOOL_COMPAT "Continue defining \"TRUE\" and \"FALSE\" until these can be replaced with \"true\" and \"false\" from stdbool.h" ON)
158 mark_as_advanced(WITH_BOOL_COMPAT)
159
160
161 # (unix defaults to OpenMP On)
162 if((UNIX AND NOT APPLE) OR (MINGW))
163         set(PLATFORM_DEFAULT ON)
164 else()
165         set(PLATFORM_DEFAULT OFF)
166 endif()
167 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ${PLATFORM_DEFAULT})
168 unset(PLATFORM_DEFAULT)
169
170
171 if(UNIX AND NOT APPLE)
172         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
173         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
174         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
175
176         # freebsd doesn't seems to support XDND
177         if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
178                 option(WITH_GHOST_XDND   "Enable drag'n'drop support on Linux using XDND protocol" ON)
179         endif()
180 else()
181         # not an option for other OS's
182         set(WITH_SYSTEM_GLEW OFF)
183 endif()
184
185
186 # (unix defaults to System OpenJPEG On)
187 if(UNIX AND NOT APPLE)
188         set(PLATFORM_DEFAULT ON)
189 else()
190         set(PLATFORM_DEFAULT OFF)
191 endif()
192 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
193 unset(PLATFORM_DEFAULT)
194
195
196 # Modifiers
197 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
198 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
199 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
200 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
201 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
202 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
203 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
204
205 # Image format support
206 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
207 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
208 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
209 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
210 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
211 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
212 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
213 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
214
215 # Audio/Video format support
216 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
217 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
218
219 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
220 if(APPLE OR (WIN32 AND NOT UNIX))
221         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
222 endif()
223
224 # 3D format support
225 # disable opencollada on non-apple unix because opencollada has no package for debian
226 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
227
228 # Sound output
229 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
230 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
231 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
232
233 # Compression
234 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
235 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
236
237 # Camera/motion tracking
238 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
239
240 # Freestyle
241 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
242
243 # Misc
244 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
245 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
246 if(UNIX AND NOT APPLE)
247         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
248         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
249         if(WITH_STATIC_LIBS)
250                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
251                 mark_as_advanced(WITH_BOOST_ICU)
252         endif()
253 endif()
254 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
255 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
256 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Python to python site-packages or dist-packages containing 'numpy' module")
257 mark_as_advanced(PYTHON_NUMPY_PATH)
258
259 # Cycles
260 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
261 option(WITH_CYCLES_TEST                         "Build cycles test application" OFF)
262 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
263 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
264 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 CACHE STRING "CUDA architectures to build binaries for")
265 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
266 unset(PLATFORM_DEFAULT)
267
268 # LLVM
269 option(WITH_LLVM                                        "Use LLVM" OFF)
270
271 # disable for now, but plan to support on all platforms eventually
272 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
273 mark_as_advanced(WITH_MEM_JEMALLOC)
274
275 # Debug
276 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
277 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
278
279 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
280 mark_as_advanced(WITH_ASSERT_ABORT)
281
282 option(WITH_BOOST                                       "Enable features depending no boost" ON)
283
284 if(CMAKE_COMPILER_IS_GNUCC)
285         option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
286         mark_as_advanced(WITH_GCC_MUDFLAP)
287 endif()
288
289 if(APPLE)
290         cmake_minimum_required(VERSION 2.8.8)
291         cmake_policy(VERSION 2.8.8)
292
293         if(NOT CMAKE_OSX_ARCHITECTURES)
294                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
295                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
296                 FORCE)
297         endif()
298         
299         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
300         if(${MAC_SYS} MATCHES 12)
301                 set(OSX_SYSTEM 10.8)
302         elseif(${MAC_SYS} MATCHES 11)
303                 set(OSX_SYSTEM 10.7)
304         elseif(${MAC_SYS} MATCHES 10)
305                 set(OSX_SYSTEM 10.6)
306         elseif(${MAC_SYS} MATCHES 9)
307                 set(OSX_SYSTEM 10.5)
308         else()
309                 set(OSX_SYSTEM unsupported)
310         endif()
311         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
312
313         if(${CMAKE_GENERATOR} MATCHES "Xcode")
314         
315                 ##### cmake incompatibility with xcode  4.3 and higher #####
316                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
317                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
318                 endif()
319                 ### end cmake incompatibility with xcode 4.3 and higher ###
320                 
321                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
322                         # Xcode 4 defaults to the Apple LLVM Compiler.
323                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
324                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
325                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
326                 endif()
327         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
328                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
329                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
330                 unset(XCODE_VERS_BUILD_NR)
331         endif()
332         
333         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
334
335         if(${XCODE_VERSION} VERSION_LESS 4.3)
336                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
337         else()
338                 # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
339                 # absolute pathes are more foolproof here !
340                 set(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
341                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
342                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
343         endif()
344         
345         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
346                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our min. target, if you use higher sdk, weak linking happens
347         endif()
348         
349         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
350                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
351                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
352                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
353                 add_definitions ("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
354         endif()
355
356         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
357         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
358         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
359         if(CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
360                 set(USE_QTKIT ON CACHE BOOL "ON" FORCE) # no Quicktime in 64bit
361         endif()
362 endif()
363
364
365 #-----------------------------------------------------------------------------
366 # Check for conflicting/unsupported configurations
367
368 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_TEST)
369         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
370 endif()
371
372 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
373         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
374 endif()
375
376 if(NOT WITH_AUDASPACE)
377         if(WITH_OPENAL)
378                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
379         endif()
380         if(WITH_JACK)
381                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
382         endif()
383         if(WITH_GAMEENGINE)
384                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
385         endif()
386 endif()
387
388 if(NOT WITH_SDL AND WITH_GHOST_SDL)
389         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
390 endif()
391
392 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
393         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
394 endif()
395
396 # python module, needs some different options
397 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
398         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
399 endif()
400
401 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
402         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
403 endif()
404
405
406 # may as well build python module without a UI
407 if(WITH_PYTHON_MODULE)
408         set(WITH_HEADLESS ON)
409 endif()
410
411 # auto enable openimageio for cycles
412 if(WITH_CYCLES)
413         set(WITH_OPENIMAGEIO ON)
414 endif()
415
416 # enable boost for cycles, booleans, audaspace or i18n
417 # otherwise if the user disabled
418 if(NOT WITH_BOOST)
419         # Explicitly disabled. so disable all deps.
420         set(WITH_CYCLES         OFF)
421         set(WITH_MOD_BOOLEAN    OFF)
422         set(WITH_AUDASPACE      OFF)
423         set(WITH_INTERNATIONAL  OFF)
424
425         set(WITH_OPENAL         OFF)  # depends on AUDASPACE
426         set(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
427 elseif(WITH_CYCLES OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
428         # Keep enabled
429 else()
430         # Enabled but we don't need it
431         set(WITH_BOOST OFF)
432 endif()
433
434 # auto enable llvm for cycles_osl
435 if(WITH_CYCLES_OSL)
436         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
437 endif()
438
439 # don't store paths to libs for portable distribution
440 if(WITH_INSTALL_PORTABLE)
441         set(CMAKE_SKIP_BUILD_RPATH TRUE)
442 endif()
443
444 if(WITH_GHOST_SDL OR WITH_HEADLESS)
445         set(WITH_GHOST_XDND OFF)
446         set(WITH_X11_XF86VMODE OFF)
447         set(WITH_X11_XINPUT OFF)
448 endif()
449
450 if(MINGW)
451         if(WITH_CODEC_QUICKTIME)
452                 message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
453                                     "because it is currently unsupported, remove this "
454                                     "line if youre a developer who wants to add support.")
455         endif()
456 endif()
457
458 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
459
460 TEST_STDBOOL_SUPPORT()
461 if(HAVE_STDBOOL_H)
462         add_definitions(-DHAVE_STDBOOL_H)
463 endif()
464 if(WITH_BOOL_COMPAT)
465         add_definitions(-DWITH_BOOL_COMPAT)
466 endif()
467
468 #-----------------------------------------------------------------------------
469 # Check for valid directories
470 # ... svn extern paths can be missing because of svn-git.
471
472 if(WITH_INTERNATIONAL)
473         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
474                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
475                                                 "This is an 'svn external', which are known not to work with bridges to other version "
476                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
477                 set(WITH_INTERNATIONAL OFF)
478         endif()
479 endif()
480
481 if(WITH_PYTHON)
482         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons")
483                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
484                                                 "This is an 'svn external', which are known not to work with bridges to other version "
485                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
486         endif()
487 endif()
488
489 #-----------------------------------------------------------------------------
490 # Initialize un-cached vars, avoid unused warning
491
492 # linux only, not cached
493 set(WITH_BINRELOC OFF)
494
495 # MAXOSX only, set to avoid uninitialized
496 set(EXETYPE "")
497
498 # C/C++ flags
499 set(PLATFORM_CFLAGS)
500
501 # these are added to later on.
502 set(C_WARNINGS)
503 set(CXX_WARNINGS)
504
505 # for gcc -Wno-blah-blah
506 set(CC_REMOVE_STRICT_FLAGS)
507
508 # libraries to link the binary with passed to target_link_libraries()
509 # known as LLIBS to scons
510 set(PLATFORM_LINKLIBS "")
511
512 # Added to linker flags in setup_liblinks
513 # - CMAKE_EXE_LINKER_FLAGS
514 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
515 set(PLATFORM_LINKFLAGS "")
516 set(PLATFORM_LINKFLAGS_DEBUG "")
517
518
519 # disabled for now, not supported
520 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
521
522 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
523 # On Unix:
524 #   cmake ../blender \
525 #         -D PYTHON_VERSION=3.3 \
526 #         -D PYTHON_INCLUDE_DIR=/opt/py33/include/python3.3d \
527 #         -D PYTHON_LIBRARY=/opt/py33/lib/libpython3.3d.so
528 #
529 # On Macs:
530 #   cmake ../blender \
531 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3 \
532 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/config \
533 #         -G Xcode
534 #
535 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
536
537 #-----------------------------------------------------------------------------
538 #Platform specifics
539
540 if(UNIX AND NOT APPLE)
541         macro(find_package_wrapper)
542                 string(TOUPPER ${ARGV0} _NAME_UPPER)
543                 if(${WITH_STATIC_LIBS})
544                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
545                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
546                 endif()
547                 find_package(${ARGV})
548                 if(${WITH_STATIC_LIBS})
549                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
550                         unset(_cmake_find_library_suffixes_back)
551                 endif()
552         endmacro()
553
554         find_package_wrapper(JPEG REQUIRED)
555         find_package_wrapper(PNG REQUIRED)
556         find_package_wrapper(ZLIB REQUIRED)
557         find_package_wrapper(Freetype REQUIRED)
558
559         if(WITH_PYTHON)
560                 # No way to set py33. remove for now.
561                 # find_package(PythonLibs)
562
563                 # Use our own instead, since wothout py is such a rare case,
564                 # require this package
565                 # XXX Linking errors with debian static python :/
566 #               find_package_wrapper(PythonLibsUnix REQUIRED)
567                 find_package(PythonLibsUnix REQUIRED)
568         endif()
569
570         if(WITH_IMAGE_OPENEXR)
571                 find_package_wrapper(OpenEXR)  # our own module
572                 if(NOT OPENEXR_FOUND)
573                         set(WITH_IMAGE_OPENEXR OFF)
574                 endif()
575         endif()
576
577         if(WITH_IMAGE_OPENJPEG)
578                 find_package_wrapper(OpenJPEG)
579                 if(NOT OPENJPEG_FOUND)
580                         set(WITH_IMAGE_OPENJPEG OFF)
581                 endif()
582         endif()
583
584         if(WITH_IMAGE_TIFF)
585                 # XXX Linking errors with debian static tiff :/
586 #               find_package_wrapper(TIFF)
587                 find_package(TIFF)
588                 if(NOT TIFF_FOUND)
589                         set(WITH_IMAGE_TIFF OFF)
590                 endif()
591         endif()
592
593         # Audio IO
594         if(WITH_OPENAL)
595                 find_package_wrapper(OpenAL)
596                 if(NOT OPENAL_FOUND)
597                         set(WITH_OPENAL OFF)
598                 endif()
599         endif()
600
601         if(WITH_SDL)
602                 find_package_wrapper(SDL)
603                 mark_as_advanced(
604                         SDLMAIN_LIBRARY
605                         SDL_INCLUDE_DIR
606                         SDL_LIBRARY
607                         SDL_LIBRARY_TEMP
608                 )
609                 # unset(SDLMAIN_LIBRARY CACHE)
610                 if(NOT SDL_FOUND)
611                         set(WITH_SDL OFF)
612                 endif()
613         endif()
614
615         if(WITH_JACK)
616                 find_package_wrapper(Jack)
617                 if(NOT JACK_FOUND)
618                         set(WITH_JACK OFF)
619                 endif()
620         endif()
621
622         # Codecs
623         if(WITH_CODEC_SNDFILE)
624                 find_package_wrapper(SndFile)
625                 if(NOT SNDFILE_FOUND)
626                         set(WITH_CODEC_SNDFILE OFF)
627                 endif()
628         endif()
629
630         if(WITH_CODEC_FFMPEG)
631                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
632                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
633
634                 mark_as_advanced(FFMPEG)
635
636                 # lame, but until we have proper find module for ffmpeg
637                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
638                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
639                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
640                 endif()
641                 # end lameness
642
643                 mark_as_advanced(FFMPEG_LIBRARIES)
644                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
645                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
646         endif()
647
648         if(WITH_FFTW3)
649                 find_package_wrapper(Fftw3)
650                 if(NOT FFTW3_FOUND)
651                         set(WITH_FFTW3 OFF)
652                 endif()
653         endif()
654
655         if(WITH_OPENCOLLADA)
656                 find_package_wrapper(OpenCOLLADA)
657                 if(OPENCOLLADA_FOUND)
658                         find_package_wrapper(XML2)
659                         find_package_wrapper(PCRE)
660                 else()
661                         set(WITH_OPENCOLLADA OFF)
662                 endif()
663         endif()
664
665         if(WITH_MEM_JEMALLOC)
666                 find_package_wrapper(JeMalloc)
667                 if(NOT JEMALLOC_FOUND)
668                         set(WITH_MEM_JEMALLOC OFF)
669                 endif()
670         endif()
671
672         if(WITH_INPUT_NDOF)
673                 find_package_wrapper(Spacenav)
674                 if(NOT SPACENAV_FOUND)
675                         set(WITH_INPUT_NDOF OFF)
676                 endif()
677
678                 # use generic names within blenders buildsystem.
679                 if(SPACENAV_FOUND)
680                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
681                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
682                 endif()
683         endif()
684
685         if(WITH_BOOST)
686                 # uses in build instructions to override include and library variables
687                 if(NOT BOOST_CUSTOM)
688                         if(${WITH_STATIC_LIBS})
689                                 set(Boost_USE_STATIC_LIBS ON)
690                         endif()
691                         set(Boost_USE_MULTITHREADED ON)
692                         set(__boost_packages filesystem regex system thread date_time)
693                         if(WITH_INTERNATIONAL)
694                                 list(APPEND __boost_packages locale)
695                         endif()
696                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
697                         unset(__boost_packages)
698                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
699                                 find_package(IcuLinux)
700                         endif()
701                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
702                 endif()
703
704                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
705                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
706                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
707                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
708         endif()
709
710         if(WITH_OPENIMAGEIO)
711                 find_package_wrapper(OpenImageIO)
712
713                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
714                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
715                 set(OPENIMAGEIO_DEFINITIONS "")
716
717                 if(WITH_IMAGE_TIFF)
718                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
719                 endif()
720                 if(WITH_IMAGE_OPENEXR)
721                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
722                 endif()
723
724                 if(NOT OPENIMAGEIO_FOUND)
725                         set(WITH_OPENIMAGEIO OFF)
726                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
727                 endif()
728         endif()
729
730         if(WITH_OPENCOLORIO)
731                 find_package_wrapper(OpenColorIO)
732
733                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
734                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
735                 set(OPENCOLORIO_DEFINITIONS)
736
737                 if(NOT OPENCOLORIO_FOUND)
738                         set(WITH_OPENCOLORIO OFF)
739                         message(STATUS "OpenColorIO not found")
740                 endif()
741         endif()
742
743         # XXX Maybe most of this section should go into an llvm module?
744         if(WITH_LLVM)
745                 # Set llvm version if not specified
746                 if(NOT LLVM_VERSION)
747                         set(LLVM_VERSION "3.0")
748                 endif()
749                 set(LLVM_STATIC YES)
750                 if(LLVM_DIRECTORY)
751                         FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
752                         if(NOT LLVM_CONFIG)
753                                 FIND_PROGRAM(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
754                         endif()
755                 else()
756                         FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION})
757                         if(NOT LLVM_CONFIG)
758                                 FIND_PROGRAM(LLVM_CONFIG llvm-config)
759                         endif()
760                 endif()
761                 execute_process(COMMAND ${LLVM_CONFIG} --version
762                                 OUTPUT_VARIABLE LLVM_VERSION
763                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
764                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
765                                 OUTPUT_VARIABLE LLVM_DIRECTORY
766                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
767                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
768                                 OUTPUT_VARIABLE LLVM_LIB_DIR
769                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
770                 find_library(LLVM_LIBRARY
771                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
772                              PATHS ${LLVM_LIB_DIR})
773                 message(STATUS "LLVM version  = ${LLVM_VERSION}")
774                 message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
775                 message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
776                 set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
777                 set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
778
779                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
780                         if(LLVM_STATIC)
781                                 # if static LLVM libraries were requested, use llvm-config to generate
782                                 # the list of what libraries we need, and substitute that in the right
783                                 # way for LLVM_LIBRARY.
784                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
785                                                 OUTPUT_VARIABLE LLVM_LIBRARY
786                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
787                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
788                         endif()
789                 else()
790                         message(FATAL_ERROR "LLVM not found.")
791                 endif()
792
793                 # Fix for conflict with Mesa llvmpipe
794                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
795         endif()
796
797         if(WITH_CYCLES_OSL)
798                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
799         
800                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
801         
802                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
803                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
804                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
805                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
806                 # otherwise LLVM is missing the osl_allocate_closure_component function
807                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
808                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
809                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
810         
811                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
812                         set(OSL_FOUND TRUE)
813                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
814                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
815                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
816                 else()
817                         message(STATUS "OSL not found")
818                 endif()
819         endif()
820
821         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
822         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
823
824         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
825                 find_package(X11 REQUIRED)
826                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
827                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
828
829                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
830
831                 if(WITH_X11_XINPUT)
832                         if(X11_Xinput_LIB)
833                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
834                         else()
835                                 set(WITH_X11_XINPUT OFF)
836                         endif()
837                 endif()
838
839                 if(WITH_X11_XF86VMODE)
840                         # XXX, why dont cmake make this available?
841                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
842                         mark_as_advanced(X11_Xxf86vmode_LIB)
843                         if(X11_Xxf86vmode_LIB)
844                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
845                         else()
846                                 set(WITH_X11_XF86VMODE OFF)
847                         endif()
848                 endif()
849         endif()
850
851         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
852                 if(NOT WITH_PYTHON_MODULE)
853                         # BSD's dont use libdl.so
854                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
855                         # binreloc is linux only
856                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
857                         set(WITH_BINRELOC ON)
858                 endif()
859         endif()
860
861         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
862
863         # lfs on glibc, all compilers should use
864         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
865
866         # GNU Compiler
867         if(CMAKE_COMPILER_IS_GNUCC)
868                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
869         # CLang is the same as GCC for now.
870         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
871                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
872         # Solaris CC
873         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
874                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
875                 
876         # Intel C++ Compiler
877         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
878                 # think these next two are broken
879                 find_program(XIAR xiar)
880                 if(XIAR)
881                         set(CMAKE_AR "${XIAR}")
882                 endif()
883                 mark_as_advanced(XIAR)
884
885                 find_program(XILD xild)
886                 if(XILD)
887                         set(CMAKE_LINKER "${XILD}")
888                 endif()
889                 mark_as_advanced(XILD)
890
891                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
892                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
893
894                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
895                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
896                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
897         endif()
898
899 elseif(WIN32)
900
901         # this file is included anyway when building under Windows with cl.exe
902         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
903
904         if(CMAKE_COMPILER_IS_GNUCC)
905                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
906                 include(CheckCSourceCompiles)
907                 # Setup 64bit and 64bit windows systems
908                 CHECK_C_SOURCE_COMPILES("
909                         #ifndef __MINGW64__
910                         #error
911                         #endif
912                         main(){}
913                         " 
914                         WITH_MINGW64)
915                 
916                 if(WITH_MINGW64)
917                         message("Compiling for 64 bit with MinGW-w64.")
918                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
919                 endif()
920         else()
921                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
922
923                 # Setup 64bit and 64bit windows systems
924                 if(CMAKE_CL_64)
925                         message("64 bit compiler detected.")
926                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
927                 endif()
928         endif()
929                 
930         add_definitions(-DWIN32)
931
932         set(JPEG "${LIBDIR}/jpeg")
933         set(JPEG_INCLUDE_DIR "${JPEG}/include")
934         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
935
936         set(WINTAB_INC ${LIBDIR}/wintab/include)
937
938         if(WITH_OPENAL)
939                 set(OPENAL ${LIBDIR}/openal)
940                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
941                 set(OPENAL_LIBRARY wrap_oal)
942                 set(OPENAL_LIBPATH ${OPENAL}/lib)
943         endif()
944
945         if(WITH_CODEC_SNDFILE)
946                 set(SNDFILE ${LIBDIR}/sndfile)
947                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
948                 set(SNDFILE_LIBRARIES libsndfile-1)
949                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
950         endif()
951
952         if(WITH_SDL)
953                 set(SDL ${LIBDIR}/sdl)
954                 set(SDL_INCLUDE_DIR ${SDL}/include)
955                 set(SDL_LIBRARY SDL)
956                 set(SDL_LIBPATH ${SDL}/lib)
957         endif()
958
959         if(WITH_CODEC_QUICKTIME)
960                 set(QUICKTIME ${LIBDIR}/QTDevWin)
961                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
962                 set(QUICKTIME_LIBRARIES qtmlClient)
963                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
964         endif()
965
966         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
967                 add_definitions(-D__SSE__ -D__MMX__)
968         endif()
969
970         if(WITH_CYCLES_OSL)
971                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
972         
973                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
974                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
975                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
976                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
977                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
978                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
979         
980                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
981                         set(OSL_FOUND TRUE)
982                 else()
983                         message(STATUS "OSL not found")
984                 endif()
985         endif()
986
987         if(MSVC)
988                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
989
990                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
991
992                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
993                 set(CMAKE_C_FLAGS   "/nologo /J /Gd"       CACHE STRING "MSVC MT C++ flags " FORCE)
994
995                 if(CMAKE_CL_64)
996                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
997                 else()
998                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
999                 endif()
1000                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
1001                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
1002                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
1003                 if(CMAKE_CL_64)
1004                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
1005                 else()
1006                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
1007                 endif()
1008                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
1009                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
1010                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
1011
1012                 # most msvc warnings are C & C++
1013                 set(_WARNINGS "/W3 /wd4018 /wd4244 /wd4305 /wd4800 /wd4181 /wd4065 /wd4267 /we4013 /wd4200")
1014                 set(C_WARNINGS "${_WARNINGS}")
1015                 set(CXX_WARNINGS "${_WARNINGS}")
1016                 unset(_WARNINGS)
1017
1018                 if(WITH_MOD_CLOTH_ELTOPO)
1019                         set(LAPACK ${LIBDIR}/lapack)
1020                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1021                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1022                         set(LAPACK_LIBRARIES
1023                                 ${LIBDIR}/lapack/lib/libf2c.lib
1024                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1025                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1026                         )
1027                 endif()
1028
1029                 set(PNG_LIBRARIES libpng)
1030                 set(JPEG_LIBRARIES libjpeg)
1031                 
1032                 set(PNG "${LIBDIR}/png")
1033                 set(PNG_INCLUDE_DIR "${PNG}/include")
1034                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1035
1036                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1037                 if(CMAKE_CL_64)
1038                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
1039                 else()
1040                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
1041                 endif()
1042
1043                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1044                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1045
1046                 set(FREETYPE ${LIBDIR}/freetype)
1047                 set(FREETYPE_INCLUDE_DIRS
1048                         ${LIBDIR}/freetype/include
1049                         ${LIBDIR}/freetype/include/freetype2
1050                 )
1051                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1052
1053                 if(WITH_FFTW3)
1054                         set(FFTW3 ${LIBDIR}/fftw3)
1055                         set(FFTW3_LIBRARIES libfftw)
1056                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1057                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1058                 endif()
1059
1060                 if(WITH_OPENCOLLADA)
1061                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1062
1063                         set(OPENCOLLADA_INCLUDE_DIRS
1064                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
1065                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
1066                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
1067                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
1068                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
1069                         )
1070                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada")
1071
1072                         set(OPENCOLLADA_LIBRARIES
1073                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADASaxFrameworkLoader.lib
1074                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAFramework.lib
1075                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADABaseUtils.lib
1076                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAStreamWriter.lib
1077                                 ${OPENCOLLADA_LIBPATH}/lib/MathMLSolver.lib
1078                                 ${OPENCOLLADA_LIBPATH}/lib/GeneratedSaxParser.lib
1079                                 ${OPENCOLLADA_LIBPATH}/lib/xml2.lib
1080                                 ${OPENCOLLADA_LIBPATH}/lib/buffer.lib
1081                                 ${OPENCOLLADA_LIBPATH}/lib/ftoa.lib
1082                                 ${OPENCOLLADA_LIBPATH}/lib/UTF.lib
1083                         )
1084                         set(PCRE_LIBRARIES
1085                                 ${OPENCOLLADA_LIBPATH}/lib/pcre.lib
1086                         )
1087                         
1088                         unset(OPENCOLLADA_LIBPATH)
1089                         
1090                 endif()
1091
1092                 if(WITH_CODEC_FFMPEG)
1093                         set(FFMPEG_INCLUDE_DIRS
1094                                 ${LIBDIR}/ffmpeg/include
1095                                 ${LIBDIR}/ffmpeg/include/msvc
1096                         )
1097                         set(FFMPEG_LIBRARIES
1098                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
1099                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
1100                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
1101                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
1102                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1103                         )
1104                 endif()
1105
1106                 if(WITH_IMAGE_OPENEXR)
1107                         set_lib_path(OPENEXR "openexr")
1108                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1109                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1110                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1111                         set(OPENEXR_LIBRARIES
1112                                 ${OPENEXR_LIBPATH}/Iex.lib
1113                                 ${OPENEXR_LIBPATH}/Half.lib
1114                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1115                                 ${OPENEXR_LIBPATH}/Imath.lib
1116                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1117                         )
1118                 endif()
1119
1120                 if(WITH_IMAGE_TIFF)
1121                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1122                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1123                 endif()
1124
1125                 if(WITH_JACK)
1126                         set(JACK_INCLUDE_DIRS
1127                                 ${LIBDIR}/jack/include/jack
1128                                 ${LIBDIR}/jack/include
1129                         )
1130                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
1131                 endif()
1132
1133                 if(WITH_PYTHON)
1134                         # normally cached but not since we include them with blender
1135                         if(MSVC10)
1136                                 set(PYTHON_VERSION 3.3) # CACHE STRING)
1137                         else()
1138                                 set(PYTHON_VERSION 3.3) # CACHE STRING)
1139                         endif()
1140
1141                         set_lib_path(PYTHON "python")
1142                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1143                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1144                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1145                         # set(PYTHON_LIBRARY ${PYTHON}/lib/python${_PYTHON_VERSION_NO_DOTS}.lib) #CACHE FILEPATH
1146                         unset(_PYTHON_VERSION_NO_DOTS)
1147
1148                         #Shared includes for both vc2008 and vc2010
1149                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1150
1151                         # uncached vars
1152                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1153                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1154                 endif()
1155
1156                 if(WITH_BOOST)
1157                         set(BOOST ${LIBDIR}/boost)
1158                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1159                         if(MSVC10)
1160                                 set(BOOST_LIBPATH ${BOOST}/vc2010/lib)
1161                                 set(BOOST_POSTFIX "vc100-mt-s-1_49.lib")
1162                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_49.lib")
1163                         else()
1164                                 set(BOOST_LIBPATH ${BOOST}/lib)
1165                                 set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1166                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1167                         endif()
1168                         set(BOOST_LIBRARIES
1169                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1170                                 optimized libboost_regex-${BOOST_POSTFIX}
1171                                 optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1172                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1173                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1174                                 debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1175                         if(WITH_CYCLES_OSL)
1176                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1177                                         optimized libboost_wave-${BOOST_POSTFIX}
1178                                         debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1179                         endif()
1180                         if(WITH_INTERNATIONAL)
1181                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1182                                         optimized libboost_locale-${BOOST_POSTFIX}
1183                                         debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1184                         endif()
1185                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1186                 endif()
1187                         
1188                 if(WITH_OPENIMAGEIO)
1189                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1190                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1191                         set(OPENIMAGEIO_LIBRARIES optimized OpenImageIO debug OpenImageIO_d)
1192                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1193                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1194                 endif()
1195
1196                 if(WITH_LLVM)
1197                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1198                         file(GLOB LLVM_LIBRARY ${LLVM_DIRECTORY}/lib/*.lib)
1199                         set(LLVM_STATIC YES)
1200                 endif()
1201         
1202                 if(WITH_OPENCOLORIO)
1203                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1204                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1205                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1206                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1207                         set(OPENCOLORIO_DEFINITIONS)
1208                 endif()
1209
1210
1211                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1212
1213                 # MSVC only, Mingw doesnt need
1214                 if(CMAKE_CL_64)
1215                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1216                 else()
1217                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1218                 endif()
1219
1220                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1221
1222                 # used in many places so include globally, like OpenGL
1223                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1224
1225         elseif(CMAKE_COMPILER_IS_GNUCC)
1226         # keep GCC specific stuff here
1227                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1228                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1229
1230                 if(WITH_MINGW64)
1231                         #We need to take care though not to have these on debug builds because they may play funky with gdb
1232                         if(CMAKE_BUILD_TYPE MATCHES "Release")
1233                                 set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -ftree-vectorize")
1234                         endif()
1235                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1236                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1237                         
1238                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1239                         #Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
1240                         set(WITH_OPENMP OFF)
1241                 endif()
1242
1243                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1244
1245                 add_definitions(-DFREE_WINDOWS)
1246
1247                 set(PNG "${LIBDIR}/png")
1248                 set(PNG_INCLUDE_DIR "${PNG}/include")
1249                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1250
1251                 if(WITH_MINGW64)
1252                         set(JPEG_LIBRARIES jpeg)
1253                 else()
1254                         set(JPEG_LIBRARIES libjpeg)
1255                 endif()
1256                 set(PNG_LIBRARIES png)
1257
1258                 set(ZLIB ${LIBDIR}/zlib)
1259                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1260                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1261                 set(ZLIB_LIBRARIES z)
1262
1263                 #comes with own pthread library
1264                 if(NOT WITH_MINGW64)
1265                         set(PTHREADS ${LIBDIR}/pthreads)
1266                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1267                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1268                         set(PTHREADS_LIBRARIES pthreadGC2)
1269                 endif()
1270                 
1271                 set(FREETYPE ${LIBDIR}/freetype)
1272                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1273                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1274                 set(FREETYPE_LIBRARY freetype)
1275
1276                 if(WITH_FFTW3)
1277                         set(FFTW3 ${LIBDIR}/fftw3)
1278                         set(FFTW3_LIBRARIES fftw3)
1279                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1280                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1281                 endif()
1282
1283                 if(WITH_OPENCOLLADA)
1284                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1285                         set(OPENCOLLADA_INCLUDE_DIRS
1286                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
1287                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
1288                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
1289                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
1290                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
1291                         )
1292                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
1293                         if(WITH_MINGW64)
1294                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre buffer ftoa xml)
1295                         else()
1296                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
1297                         endif()
1298                         set(PCRE_LIBRARIES pcre)
1299                 endif()
1300
1301                 if(WITH_CODEC_FFMPEG)
1302                         set(FFMPEG ${LIBDIR}/ffmpeg)
1303                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1304                         if(WITH_MINGW64)
1305                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1306                         else()
1307                                 set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
1308                         endif()
1309                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1310                 endif()
1311
1312                 if(WITH_IMAGE_OPENEXR)
1313                         set(OPENEXR ${LIBDIR}/openexr)
1314                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1315                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1316                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1317                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1318                 endif()
1319
1320                 if(WITH_IMAGE_TIFF)
1321                         set(TIFF ${LIBDIR}/tiff)
1322                         set(TIFF_LIBRARY tiff)
1323                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1324                         set(TIFF_LIBPATH ${TIFF}/lib)
1325                 endif()
1326
1327                 if(WITH_JACK)
1328                         set(JACK ${LIBDIR}/jack)
1329                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1330                         set(JACK_LIBRARIES jack)
1331                         set(JACK_LIBPATH ${JACK}/lib)
1332
1333                         # TODO, gives linking errors, force off
1334                         set(WITH_JACK OFF)
1335                 endif()
1336
1337                 if(WITH_PYTHON)
1338                         # normally cached but not since we include them with blender
1339                         set(PYTHON_VERSION 3.3) #  CACHE STRING)
1340                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1341                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python33mw.lib")  # CACHE FILEPATH)
1342
1343                         # uncached vars
1344                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1345                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1346                 endif()
1347
1348                 if(WITH_BOOST)
1349                         set(BOOST ${LIBDIR}/boost)
1350                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1351                         if(WITH_MINGW64)
1352                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1353                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1354                         else()
1355                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1356                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1357                         endif()
1358                         set(BOOST_LIBRARIES
1359                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1360                                 boost_regex-${BOOST_POSTFIX}
1361                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1362                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1363                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1364                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1365                         if(WITH_INTERNATIONAL)
1366                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1367                                         optimized boost_locale-${BOOST_POSTFIX}
1368                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1369                         endif()
1370                         if(WITH_CYCLES_OSL)
1371                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1372                                         optimized boost_wave-${BOOST_POSTFIX}
1373                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1374                         endif()
1375                         set(BOOST_LIBPATH ${BOOST}/lib)
1376                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1377                 endif()
1378                         
1379                 if(WITH_OPENIMAGEIO)
1380                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1381                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1382                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1383                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1384                         set(OPENIMAGEIO_DEFINITIONS "")
1385                 endif()
1386                 
1387                 if(WITH_LLVM)
1388                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1389                         set(LLVM_LIB_DIR ${LLVM_DIRECTORY}/lib)
1390                         #Explicitly set llvm lib order.
1391                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1392                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1393                                 LLVMAsmParser LLVMAsmPrinter
1394                                 LLVMBitReader LLVMBitWriter
1395                                 LLVMDebugInfo LLVMExecutionEngine
1396                                 LLVMInstCombine LLVMInstrumentation
1397                                 LLVMInterpreter LLVMJIT
1398                                 LLVMLinker LLVMMC
1399                                 LLVMMCDisassembler LLVMMCJIT
1400                                 LLVMMCParser LLVMObject
1401                                 LLVMRuntimeDyld 
1402                                 LLVMSupport
1403                                 LLVMTableGen LLVMTarget
1404                                 LLVMTransformUtils LLVMVectorize
1405                                 LLVMX86AsmParser LLVMX86AsmPrinter
1406                                 LLVMX86CodeGen LLVMX86Desc
1407                                 LLVMX86Disassembler LLVMX86Info
1408                                 LLVMX86Utils LLVMipa
1409                                 LLVMipo LLVMCore)
1410                                 #imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1411                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
1412                         set(LLVM_STATIC YES)
1413                 endif()
1414                 
1415                 if(WITH_OPENCOLORIO)
1416                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1417                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1418                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1419                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1420                         set(OPENCOLORIO_DEFINITIONS)
1421                 endif()
1422
1423                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1424
1425                 ## DISABLE - causes linking errors 
1426                 ## for re-distribution, so users dont need mingw installed
1427                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1428
1429         endif()
1430
1431 elseif(APPLE)
1432
1433         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1434                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/10.7
1435         endif()
1436
1437         if(WITH_LIBS10.5)
1438                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1439         else()
1440                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1441                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1442                 else()
1443                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1444                 endif()
1445         endif()
1446
1447
1448         if(WITH_OPENAL)
1449                 find_package(OpenAL)
1450                 if(OPENAL_FOUND)
1451                         set(WITH_OPENAL ON)
1452                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1453                 else()
1454                         set(WITH_OPENAL OFF)
1455                 endif()
1456         endif()
1457
1458         if(WITH_JACK)
1459                 find_library(JACK_FRAMEWORK
1460                         NAMES jackmp
1461                 )
1462                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1463                 if(NOT JACK_FRAMEWORK)
1464                         set(WITH_JACK OFF)
1465                 endif()
1466         endif()
1467
1468         if(WITH_CODEC_SNDFILE)
1469                 set(SNDFILE ${LIBDIR}/sndfile)
1470                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1471                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1472                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1473         endif()
1474
1475         if(WITH_PYTHON)
1476                 # we use precompiled libraries for py 3.3 and up by default
1477                 set(PYTHON_VERSION 3.3)
1478                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1479                         # normally cached but not since we include them with blender
1480                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1481                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1482                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1483                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1484                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1485                 else()
1486                         # module must be compiled against Python framework
1487                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1488                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1489                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1490                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1491                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1492                 endif()
1493                 
1494                 # uncached vars
1495                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1496                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1497         endif()
1498
1499         if(WITH_FFTW3)
1500                 set(FFTW3 ${LIBDIR}/fftw3)
1501                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1502                 set(FFTW3_LIBRARIES fftw3)
1503                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1504         endif()
1505
1506         set(PNG_LIBRARIES png)
1507         set(JPEG_LIBRARIES jpeg)
1508
1509         set(ZLIB /usr)
1510         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1511         set(ZLIB_LIBRARIES z bz2)
1512
1513         set(FREETYPE ${LIBDIR}/freetype)
1514         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1515         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1516         set(FREETYPE_LIBRARY freetype)
1517
1518         if(WITH_IMAGE_OPENEXR)
1519                 set(OPENEXR ${LIBDIR}/openexr)
1520                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1521                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1522                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1523                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1524         endif()
1525
1526         if(WITH_CODEC_FFMPEG)
1527                 set(FFMPEG ${LIBDIR}/ffmpeg)
1528                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1529                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1530                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1531                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1532         endif()
1533
1534         find_library(SYSTEMSTUBS_LIBRARY
1535                 NAMES
1536                 SystemStubs
1537                 PATHS
1538         )
1539         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1540         if(SYSTEMSTUBS_LIBRARY)
1541                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1542         else()
1543                 set(PLATFORM_LINKLIBS stdc++)
1544         endif()
1545
1546         if(WITH_COCOA)
1547                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1548                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1549                 if(USE_QTKIT)
1550                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1551                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1552                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1553                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1554                                 #libSDL still needs 32bit carbon quicktime
1555                         endif()
1556                 elseif(WITH_CODEC_QUICKTIME)
1557                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1558                 endif()
1559
1560                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1561                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1562                 if(WITH_INPUT_NDOF)
1563                         # This thread it *should* work and check the framework - campbell
1564                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1565                         find_library(3DCONNEXION_CLIENT_FRAMEWORK
1566                                 NAMES 3DconnexionClient
1567                         )
1568                         if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1569                                 set(WITH_INPUT_NDOF OFF)
1570                         endif()
1571
1572                         if(WITH_INPUT_NDOF)
1573                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1574                                 set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1575                         endif()
1576                 endif()
1577
1578         if(WITH_JACK)
1579                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework jackmp")
1580         endif()
1581
1582         else()
1583                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1584                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1585                 set(WITH_INPUT_NDOF OFF)  # unsupported
1586         endif()
1587         
1588         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1589                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1590         endif()
1591         
1592         if(WITH_OPENCOLLADA)
1593                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1594
1595                 set(OPENCOLLADA_INCLUDE_DIRS
1596                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1597                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1598                         ${LIBDIR}/opencollada/include/COLLADAFramework
1599                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1600                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1601                 )
1602
1603                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1604                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1605                 #pcre is bundled with openCollada
1606                 #set(PCRE ${LIBDIR}/pcre)
1607                 #set(PCRE_LIBPATH ${PCRE}/lib)
1608                 set(PCRE_LIBRARIES pcre)
1609                 #libxml2 is used
1610                 #set(EXPAT ${LIBDIR}/expat)
1611                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1612                 set(EXPAT_LIB)
1613         endif()
1614
1615         if(WITH_SDL)
1616                 set(SDL ${LIBDIR}/sdl)
1617                 set(SDL_INCLUDE_DIR ${SDL}/include)
1618                 set(SDL_LIBRARY SDL)
1619                 set(SDL_LIBPATH ${SDL}/lib)
1620         endif()
1621
1622         set(PNG "${LIBDIR}/png")
1623         set(PNG_INCLUDE_DIR "${PNG}/include")
1624         set(PNG_LIBPATH ${PNG}/lib)
1625
1626         set(JPEG "${LIBDIR}/jpeg")
1627         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1628         set(JPEG_LIBPATH ${JPEG}/lib)
1629
1630         if(WITH_IMAGE_TIFF)
1631                 set(TIFF ${LIBDIR}/tiff)
1632                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1633                 set(TIFF_LIBRARY tiff)
1634                 set(TIFF_LIBPATH ${TIFF}/lib)
1635         endif()
1636
1637         if(WITH_INPUT_NDOF)
1638                 # linker needs "-weak_framework 3DconnexionClient"
1639         endif()
1640
1641         if(WITH_BOOST)
1642                 set(BOOST ${LIBDIR}/boost)
1643                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1644                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1645                 if(WITH_INTERNATIONAL)
1646                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1647                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale needs it !
1648                 endif()
1649                 set(BOOST_LIBPATH ${BOOST}/lib)
1650                 set(BOOST_DEFINITIONS)
1651         endif()
1652
1653         if(WITH_OPENIMAGEIO)
1654                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1655                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1656                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1657                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1658                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1659         endif()
1660
1661         if(WITH_OPENCOLORIO)
1662                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1663                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1664                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1665                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1666                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1667         endif()
1668
1669         if(WITH_LLVM)
1670                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1671                 set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
1672                 set(LLVM_STATIC YES)
1673                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1674                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1675                 else()
1676                         set(LLVM_CONFIG llvm-config)
1677                 endif()
1678                 execute_process(COMMAND ${LLVM_CONFIG} --version
1679                                 OUTPUT_VARIABLE LLVM_VERSION
1680                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1681                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1682                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1683                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1684                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1685                                 OUTPUT_VARIABLE LLVM_LIB_DIR
1686                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1687                 find_library(LLVM_LIBRARY
1688                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1689                              PATHS ${LLVM_LIB_DIR})
1690
1691                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
1692                         if(LLVM_STATIC)
1693                                 # if static LLVM libraries were requested, use llvm-config to generate
1694                                 # the list of what libraries we need, and substitute that in the right
1695                                 # way for LLVM_LIBRARY.
1696                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1697                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1698                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1699                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1700                         endif()
1701                 else()
1702                         message(FATAL_ERROR "LLVM not found.")
1703                 endif()
1704         endif()
1705
1706         if(WITH_CYCLES_OSL)
1707                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1708         
1709                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1710                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1711                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1712                 # WARNING! depends on correct order of OSL libs linking
1713                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1714                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1715                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1716         
1717                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1718                         set(OSL_FOUND TRUE)
1719                 else()
1720                         message(STATUS "OSL not found")
1721                 endif()
1722         endif()
1723
1724         set(EXETYPE MACOSX_BUNDLE)
1725
1726         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1727         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1728         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1729                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
1730                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
1731                 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1732                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1733                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1734                 endif()
1735         else()
1736                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1737                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1738         endif()
1739 endif()
1740
1741 #-----------------------------------------------------------------------------
1742 # Common.
1743
1744 if(APPLE OR WIN32)
1745         if(NOT EXISTS "${LIBDIR}/")
1746                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1747         endif()
1748 endif()
1749
1750 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
1751         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
1752 endif()
1753
1754 if(WITH_CYCLES)
1755         if(NOT WITH_OPENIMAGEIO)
1756                 message(FATAL_ERROR "Cycles reqires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1757         endif()
1758         if(NOT WITH_BOOST)
1759                 message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1760         endif()
1761
1762         if(WITH_CYCLES_OSL)
1763                 if(NOT WITH_LLVM)
1764                         message(FATAL_ERROR "Cycles OSL reqires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
1765                 endif()
1766         endif()
1767 endif()
1768
1769 if(WITH_INTERNATIONAL)
1770         if(NOT WITH_BOOST)
1771                 message(FATAL_ERROR "Internationalization reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
1772         endif()
1773 endif()
1774
1775 # See TEST_SSE_SUPPORT() for how this is defined.
1776
1777 if(WITH_RAYOPTIMIZATION)
1778         if(SUPPORT_SSE_BUILD)
1779                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1780                 add_definitions(-D__SSE__ -D__MMX__)
1781         endif()
1782         if(SUPPORT_SSE2_BUILD)
1783                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1784                 add_definitions(-D__SSE2__)
1785                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1786                         add_definitions(-D__MMX__)
1787                 endif()
1788         endif()
1789 endif()
1790
1791
1792 # set the endian define
1793 if(MSVC)
1794         # for some reason this fails on msvc
1795         add_definitions(-D__LITTLE_ENDIAN__)
1796         
1797 # OSX-Note: as we do crosscompiling with specific set architecture,
1798 # endianess-detection and autosetting is counterproductive
1799 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1800
1801 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1802         add_definitions(-D__LITTLE_ENDIAN__)
1803 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1804         add_definitions(-D__BIG_ENDIAN__)
1805         
1806 else()
1807         include(TestBigEndian)
1808         test_big_endian(_SYSTEM_BIG_ENDIAN)
1809         if(_SYSTEM_BIG_ENDIAN)
1810                 add_definitions(-D__BIG_ENDIAN__)
1811         else()
1812                 add_definitions(-D__LITTLE_ENDIAN__)
1813         endif()
1814         unset(_SYSTEM_BIG_ENDIAN)
1815 endif()
1816
1817
1818 if(WITH_IMAGE_OPENJPEG)
1819         if(WITH_SYSTEM_OPENJPEG)
1820                 # dealt with above
1821         else()
1822                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1823                 add_definitions(-DOPJ_STATIC)
1824         endif()
1825 endif()
1826
1827 if(WITH_IMAGE_REDCODE)
1828         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1829         set(REDCODE_INC ${REDCODE})
1830 endif()
1831
1832 #-----------------------------------------------------------------------------
1833 # Blender WebPlugin
1834
1835 if(WITH_WEBPLUGIN)
1836         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1837         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1838
1839         set(WITH_PLAYER ON)
1840 endif()
1841
1842
1843 #-----------------------------------------------------------------------------
1844 # Configure OpenGL.
1845 find_package(OpenGL)
1846 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1847 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1848 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1849
1850 #-----------------------------------------------------------------------------
1851 # Configure OpenMP.
1852 if(WITH_OPENMP)
1853         find_package(OpenMP)
1854         if(OPENMP_FOUND)
1855                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1856                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1857
1858                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1859                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1860                 endif()
1861         else()
1862                 set(WITH_OPENMP OFF)
1863         endif()
1864
1865         mark_as_advanced(
1866                 OpenMP_C_FLAGS
1867                 OpenMP_CXX_FLAGS
1868         )
1869 endif()
1870
1871 #-----------------------------------------------------------------------------
1872 # Configure GLEW
1873
1874 if(WITH_SYSTEM_GLEW)
1875         find_package(GLEW)
1876
1877         if(NOT GLEW_FOUND)
1878                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
1879         endif()
1880
1881         mark_as_advanced(
1882                 GLEW_LIBRARY
1883                 GLEW_INCLUDE_PATH
1884         )
1885 else()
1886         # set(GLEW_LIBRARY "")  # unused
1887         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1888 endif()
1889
1890
1891 #-----------------------------------------------------------------------------
1892 # Configure Bullet
1893
1894 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1895         find_package(Bullet)
1896         if(NOT BULLET_FOUND)
1897                 set(WITH_BULLET OFF)
1898         endif()
1899 else()
1900         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1901         # set(BULLET_LIBRARIES "")
1902 endif()
1903
1904 #-----------------------------------------------------------------------------
1905 # Configure Python.
1906
1907 if(WITH_PYTHON_MODULE)
1908         add_definitions(-DPy_ENABLE_SHARED)
1909 endif()
1910
1911 #-----------------------------------------------------------------------------
1912 # Extra compile flags
1913
1914 if(CMAKE_COMPILER_IS_GNUCC)
1915
1916         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1917         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1918         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1919         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1920         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1921         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1922         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1923         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1924         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1925         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1926         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1927         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1928         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1929         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1930         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1931         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1932         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1933         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1934         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1935
1936         # gcc 4.2 gives annoying warnings on every file with this
1937         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1938                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1939         endif()
1940
1941         # versions before gcc4.6 give many BLI_math warnings
1942         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1943                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1944                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1945         endif()
1946
1947         # disable because it gives warnings for printf() & friends.
1948         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1949
1950         if(NOT APPLE)
1951                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1952         endif()
1953
1954         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1955         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1956         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1957         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1958         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1959         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1960         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1961
1962         # gcc 4.2 gives annoying warnings on every file with this
1963         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1964                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1965         endif()
1966
1967         # causes too many warnings
1968         if(NOT APPLE)
1969                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1970                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1971         endif()
1972
1973         # flags to undo strict flags
1974         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1975         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1976
1977         if(NOT APPLE)
1978                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1979         endif()
1980
1981 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1982
1983         # strange, clang complains these are not supported, but then yses them.
1984         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1985         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1986         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1987         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1988         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1989         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1990         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1991         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1992         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1993         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1994
1995         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1996         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1997         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1998         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1999         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_OVERLOADED_VIRTUAL  -Wno-overloaded-virtual)  # we get a lot of these, if its a problem a dev needs to look into it.
2000         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2001         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2002
2003         # gives too many unfixable warnings
2004         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2005         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2006
2007         # flags to undo strict flags
2008         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2009         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2010
2011 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2012
2013         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2014         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2015         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2016
2017         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2018         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2019         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2020
2021         # disable numbered, false positives
2022         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2023         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2024
2025 endif()
2026
2027 # MSVC2010 fails to links C++ libs right
2028 if(MSVC10)
2029         if(WITH_OPENCOLLADA)
2030                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
2031         endif()
2032 endif()
2033
2034 # ensure python header is found since detection can fail, this could happen
2035 # with _any_ library but since we used a fixed python version this tends to
2036 # be most problematic.
2037 if(WITH_PYTHON)
2038         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2039                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2040                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2041                                                         "to a valid python include path. Containing "
2042                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2043         endif()
2044
2045         if(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2046                 # set but invalid
2047                 # -- disabled until we make numpy bundled with blender - campbell
2048                 if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
2049 #                       if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
2050 #                               message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
2051 #                                               "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2052 #                               set(WITH_PYTHON_INSTALL_NUMPY OFF)
2053 #                       endif()
2054                 # not set, so initialize
2055                 else()
2056                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
2057                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
2058
2059                         # re-cache
2060                         unset(PYTHON_NUMPY_PATH CACHE)
2061                         find_path(PYTHON_NUMPY_PATH
2062                           NAMES
2063                             numpy
2064                           HINTS
2065                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
2066                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
2067                           PATH_SUFFIXES
2068                             site-packages
2069                             dist-packages
2070                            NO_DEFAULT_PATH
2071                         )
2072
2073                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
2074                                 message(WARNING "'numpy' path could not be found in:\n"
2075                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
2076                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
2077                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
2078                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
2079                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2080                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
2081                         else()
2082                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
2083                         endif()
2084
2085                         unset(_PY_VER_SPLIT)
2086                         unset(_PY_VER_MAJOR)
2087                 endif()
2088         endif()
2089 endif()
2090
2091 if(WITH_GCC_MUDFLAP)
2092         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2093         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2094         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2095         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2096 endif()
2097
2098 # Include warnings first, so its possible to disable them with user defined flags
2099 # eg: -Wno-uninitialized
2100 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2101 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2102
2103 #-------------------------------------------------------------------------------
2104 # Global Defines
2105
2106 # better not set includes here but this debugging option is off by default.
2107 if(WITH_CXX_GUARDEDALLOC)
2108         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2109         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2110 endif()
2111
2112 if(WITH_ASSERT_ABORT)
2113         add_definitions(-DWITH_ASSERT_ABORT)
2114 endif()
2115
2116 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2117 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2118
2119 #-----------------------------------------------------------------------------
2120 # Libraries
2121
2122 add_subdirectory(source)
2123 add_subdirectory(intern)
2124 add_subdirectory(extern)
2125
2126
2127 #-----------------------------------------------------------------------------
2128 # Blender Application
2129 if(WITH_BLENDER)
2130         add_subdirectory(source/creator)
2131 endif()
2132
2133
2134 #-----------------------------------------------------------------------------
2135 # Blender Player
2136 if(WITH_PLAYER)
2137         add_subdirectory(source/blenderplayer)
2138 endif()
2139
2140 #-----------------------------------------------------------------------------
2141 # CPack for generating packages
2142 include(build_files/cmake/packaging.cmake)
2143
2144
2145 #-----------------------------------------------------------------------------
2146 # Print Final Configuration
2147
2148 if(FIRST_RUN)
2149         set(_config_msg "\n* Blender Configuration *")
2150         macro(info_cfg_option
2151                 _setting)
2152                 set(_msg "   * ${_setting}")
2153                 string(LENGTH "${_msg}" _len)
2154                 while("32" GREATER "${_len}")
2155                         set(_msg "${_msg} ")
2156                          math(EXPR _len "${_len} + 1")
2157                 endwhile()
2158
2159                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2160         endmacro()
2161
2162         macro(info_cfg_text
2163                 _text)
2164                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2165
2166
2167         endmacro()
2168
2169         info_cfg_text("Build Options:")
2170         info_cfg_option(WITH_GAMEENGINE)
2171         info_cfg_option(WITH_PLAYER)
2172         info_cfg_option(WITH_BULLET)
2173         info_cfg_option(WITH_IK_SOLVER)
2174         info_cfg_option(WITH_IK_ITASC)
2175         info_cfg_option(WITH_OPENCOLLADA)
2176         info_cfg_option(WITH_FFTW3)
2177         info_cfg_option(WITH_INTERNATIONAL)
2178         info_cfg_option(WITH_INPUT_NDOF)
2179         info_cfg_option(WITH_CYCLES)
2180         info_cfg_option(WITH_OPENCOLORIO)
2181
2182         info_cfg_text("Compiler Options:")
2183         info_cfg_option(WITH_BUILDINFO)
2184         info_cfg_option(WITH_OPENMP)
2185         info_cfg_option(WITH_RAYOPTIMIZATION)
2186
2187         info_cfg_text("System Options:")
2188         info_cfg_option(WITH_INSTALL_PORTABLE)
2189         info_cfg_option(WITH_X11_XF86VMODE)
2190         info_cfg_option(WITH_X11_XINPUT)
2191         info_cfg_option(WITH_MEM_JEMALLOC)
2192         info_cfg_option(WITH_SYSTEM_GLEW)
2193         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2194
2195         info_cfg_text("Image Formats:")
2196         info_cfg_option(WITH_IMAGE_CINEON)
2197         info_cfg_option(WITH_IMAGE_DDS)
2198         info_cfg_option(WITH_IMAGE_HDR)
2199         info_cfg_option(WITH_IMAGE_OPENEXR)
2200         info_cfg_option(WITH_IMAGE_OPENJPEG)
2201         info_cfg_option(WITH_IMAGE_REDCODE)
2202         info_cfg_option(WITH_IMAGE_TIFF)
2203
2204         info_cfg_text("Audio:")
2205         info_cfg_option(WITH_OPENAL)
2206         info_cfg_option(WITH_SDL)
2207         info_cfg_option(WITH_JACK)
2208         info_cfg_option(WITH_CODEC_AVI)
2209         info_cfg_option(WITH_CODEC_FFMPEG)
2210         info_cfg_option(WITH_CODEC_SNDFILE)
2211
2212         info_cfg_text("Compression:")
2213         info_cfg_option(WITH_LZMA)
2214         info_cfg_option(WITH_LZO)
2215
2216         info_cfg_text("Python:")
2217         info_cfg_option(WITH_PYTHON_INSTALL)
2218         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2219         info_cfg_option(WITH_PYTHON_MODULE)
2220         info_cfg_option(WITH_PYTHON_SAFETY)
2221         if(APPLE)
2222                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2223         endif()
2224
2225         info_cfg_text("Modifiers:")
2226         info_cfg_option(WITH_MOD_BOOLEAN)
2227         info_cfg_option(WITH_MOD_REMESH)
2228         info_cfg_option(WITH_MOD_FLUID)
2229         info_cfg_option(WITH_MOD_OCEANSIM)
2230
2231         # debug
2232         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2233
2234         info_cfg_text("")
2235
2236         message("${_config_msg}")
2237 endif()