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