Cycles: Add dedicated nodes to split/combine vectors.
[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 (CMAKE_VERSION VERSION_LESS 3.0))
51         # keep until CMake-3.0 is min requirement
52         cmake_policy(SET CMP0043 OLD)
53 endif()
54
55 if(NOT EXECUTABLE_OUTPUT_PATH)
56         set(FIRST_RUN "TRUE")
57 endif()
58
59 # this starts out unset
60 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
61
62 # avoid having empty buildtype
63 set(CMAKE_BUILD_TYPE_INIT "Release")
64
65 # quiet output for Makefiles, 'make -s' helps too
66 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
67
68 # global compile definitions since add_definitions() adds for all.
69 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
70 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
71 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
72 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
73
74
75 #-----------------------------------------------------------------------------
76 # Set policy
77
78 # see "cmake --help-policy CMP0003"
79 # So library linking is more sane
80 cmake_policy(SET CMP0003 NEW)
81
82 # So BUILDINFO and BLENDERPATH strings are automatically quoted
83 cmake_policy(SET CMP0005 NEW)
84
85 # So syntax problems are errors
86 cmake_policy(SET CMP0010 NEW)
87
88 # Input directories must have CMakeLists.txt
89 cmake_policy(SET CMP0014 NEW)
90
91 #-----------------------------------------------------------------------------
92 # Load some macros.
93 include(build_files/cmake/macros.cmake)
94
95
96 #-----------------------------------------------------------------------------
97 # Initialize project.
98
99 blender_project_hack_pre()
100
101 project(Blender)
102
103 blender_project_hack_post()
104
105 enable_testing()
106
107 #-----------------------------------------------------------------------------
108 # Redirect output files
109
110 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
111 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
112
113 #-----------------------------------------------------------------------------
114 # Set default config options
115
116 get_blender_version()
117
118
119 # Blender internal features
120 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
121 mark_as_advanced(WITH_BLENDER)
122
123 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
124
125 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
126 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
127 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
128 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
129 set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on. 
130
131 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)
132 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)
133 if(APPLE)
134         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
135 endif()
136
137 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
138 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
139 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
140 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ON)
141 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
142 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
143 mark_as_advanced(WITH_SYSTEM_BULLET)
144 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
145 option(WITH_PLAYER        "Build Player" OFF)
146 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
147 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
148
149 # GHOST Windowing Library Options
150 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
151 mark_as_advanced(WITH_GHOST_DEBUG)
152
153 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
154 mark_as_advanced(WITH_GHOST_SDL)
155
156 # Misc...
157 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
158 mark_as_advanced(WITH_HEADLESS)
159
160 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
161 mark_as_advanced(WITH_AUDASPACE)
162
163 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
164
165 if(UNIX AND NOT APPLE)
166         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
167         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
168         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
169
170         option(WITH_GHOST_XDND   "Enable drag'n'drop support on X11 using XDND protocol" ON)
171 else()
172         # not an option for other OS's
173         set(WITH_SYSTEM_GLEW OFF)
174 endif()
175
176
177 # (unix defaults to System OpenJPEG On)
178 if(UNIX AND NOT APPLE)
179         set(PLATFORM_DEFAULT ON)
180 else()
181         set(PLATFORM_DEFAULT OFF)
182 endif()
183 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
184 unset(PLATFORM_DEFAULT)
185
186
187 # Modifiers
188 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
189 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
190 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
191 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
192 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
193 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
194 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
195
196 # Image format support
197 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" OFF)
198 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
199 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
200 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
201 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
202 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
203 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
204 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
205 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
206
207 # Audio/Video format support
208 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
209 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
210 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
211
212 if(APPLE)
213         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ON)
214         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
215 else()
216         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
217 endif()
218
219 # 3D format support
220 # Disable opencollada when we don't have precompiled libs
221 if(APPLE OR WIN32)
222         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" ON)
223 else()
224         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" OFF)
225 endif()
226
227 # Sound output
228 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
229 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
230 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
231 if(UNIX AND NOT APPLE)
232         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
233 endif()
234
235 # Compression
236 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
237 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
238
239 # Camera/motion tracking
240 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
241
242 # Freestyle
243 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
244
245 # Misc
246 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
247 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
248 option(WITH_OPENNL        "Enable use of Open Numerical Library" 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 if(UNIX AND NOT APPLE)
263         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
264 endif()
265
266 # Cycles
267 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
268 option(WITH_CYCLES_STANDALONE           "Build cycles standalone application" OFF)
269 option(WITH_CYCLES_STANDALONE_GUI       "Build cycles standalone with GUI" OFF)
270 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
271 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
272 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 CACHE STRING "CUDA architectures to build binaries for")
273 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
274 unset(PLATFORM_DEFAULT)
275
276 # LLVM
277 option(WITH_LLVM                                        "Use LLVM" OFF)
278 option(LLVM_STATIC                                      "Link with LLVM static libraries" ON)
279 mark_as_advanced(LLVM_STATIC)
280
281 # disable for now, but plan to support on all platforms eventually
282 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
283 mark_as_advanced(WITH_MEM_JEMALLOC)
284
285 # currently only used for BLI_mempool
286 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
287 mark_as_advanced(WITH_MEM_VALGRIND)
288
289 # Debug
290 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
291 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
292
293 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
294 mark_as_advanced(WITH_ASSERT_ABORT)
295
296 option(WITH_BOOST                                       "Enable features depending on boost" ON)
297
298 if(CMAKE_COMPILER_IS_GNUCC)
299         option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
300         mark_as_advanced(WITH_GCC_MUDFLAP)
301 endif()
302
303 if(APPLE)
304         cmake_minimum_required(VERSION 2.8.8)
305         cmake_policy(VERSION 2.8.8)
306
307         if(NOT CMAKE_OSX_ARCHITECTURES)
308                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
309                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
310                 FORCE)
311         endif()
312         
313         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
314         if(${MAC_SYS} MATCHES 13)
315                 set(OSX_SYSTEM 10.9)
316         elseif(${MAC_SYS} MATCHES 12)
317                 set(OSX_SYSTEM 10.8)
318         elseif(${MAC_SYS} MATCHES 11)
319                 set(OSX_SYSTEM 10.7)
320         elseif(${MAC_SYS} MATCHES 10)
321                 set(OSX_SYSTEM 10.6)
322         elseif(${MAC_SYS} MATCHES 9)
323                 set(OSX_SYSTEM 10.5)
324         else()
325                 set(OSX_SYSTEM unsupported)
326         endif()
327         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
328         
329         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
330         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
331         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
332         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
333         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
334         
335         if(${CMAKE_GENERATOR} MATCHES "Xcode")
336         
337                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
338                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
339                         if(${DP_NAME} MATCHES Xcode5)
340                                 set(XCODE_VERSION 5)
341                         endif()
342                 endif()
343
344                 ##### cmake incompatibility with xcode  4.3 and higher #####
345                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
346                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
347                 endif()
348                 ### end cmake incompatibility with xcode 4.3 and higher ###
349                 
350                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
351                         # Xcode 4 defaults to the Apple LLVM Compiler.
352                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
353                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
354                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
355                 endif()
356         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
357                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
358                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
359                 unset(XCODE_VERS_BUILD_NR)
360         endif()
361         
362         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
363
364         if(${XCODE_VERSION} VERSION_LESS 4.3)
365                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
366         else()
367                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
368                 # so i use a selfcomposed bundlepath here  
369                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
370                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
371                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
372                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
373                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
374                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
375                 endif()
376         endif()
377
378         if(OSX_SYSTEM MATCHES 10.9)
379                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
380         endif()
381
382         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
383                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
384         endif()
385         
386         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
387                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
388                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
389                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
390                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
391         endif()
392
393         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
394 endif()
395
396
397 #-----------------------------------------------------------------------------
398 # Check for conflicting/unsupported configurations
399
400 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
401         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
402 endif()
403
404 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
405         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
406 endif()
407
408 if(NOT WITH_AUDASPACE)
409         if(WITH_OPENAL)
410                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
411         endif()
412         if(WITH_JACK)
413                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
414         endif()
415         if(WITH_GAMEENGINE)
416                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
417         endif()
418 endif()
419
420 if(NOT WITH_SDL AND WITH_GHOST_SDL)
421         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
422 endif()
423
424 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
425         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
426 endif()
427
428 # python module, needs some different options
429 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
430         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
431 endif()
432
433 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
434         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
435 endif()
436
437
438 # may as well build python module without a UI
439 if(WITH_PYTHON_MODULE)
440         set(WITH_HEADLESS ON)
441 endif()
442
443 if(NOT WITH_PYTHON)
444         set(WITH_CYCLES OFF)
445 endif()
446
447 # enable boost for cycles, booleans, audaspace or i18n
448 # otherwise if the user disabled
449 if(NOT WITH_BOOST)
450         # Explicitly disabled. so disable all deps.
451         macro(set_and_warn
452                 _setting _val)
453                 if(${${_setting}})
454                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
455                 endif()
456                 set(${_setting} ${_val})
457         endmacro()
458
459         set_and_warn(WITH_CYCLES         OFF)
460         set_and_warn(WITH_MOD_BOOLEAN    OFF)
461         set_and_warn(WITH_AUDASPACE      OFF)
462         set_and_warn(WITH_INTERNATIONAL  OFF)
463
464         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
465         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
466 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
467         # Keep enabled
468 else()
469         # Enabled but we don't need it
470         set(WITH_BOOST OFF)
471 endif()
472
473 # auto enable openimageio for cycles
474 if(WITH_CYCLES)
475         set(WITH_OPENIMAGEIO ON)
476 endif()
477
478 # auto enable openimageio linking dependencies
479 if(WITH_OPENIMAGEIO)
480         set(WITH_IMAGE_OPENEXR ON)
481         set(WITH_IMAGE_TIFF ON)
482 endif()
483
484 # auto enable llvm for cycles_osl
485 if(WITH_CYCLES_OSL)
486         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
487 endif()
488
489 # don't store paths to libs for portable distribution
490 if(WITH_INSTALL_PORTABLE)
491         set(CMAKE_SKIP_BUILD_RPATH TRUE)
492 endif()
493
494 if(WITH_GHOST_SDL OR WITH_HEADLESS)
495         set(WITH_GHOST_XDND OFF)
496         set(WITH_X11_XF86VMODE OFF)
497         set(WITH_X11_XINPUT OFF)
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
507 #-----------------------------------------------------------------------------
508 # Check for valid directories
509 # ... a partial checkout may cause this.
510 #
511 # note: we need to check for a known subdir in both cases.
512 #       since uninitialized git submodules will give blank dirs
513
514 if(WITH_INTERNATIONAL)
515         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
516                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
517                                                 "This is a 'git submodule', 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/modules")
525                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
526                                                 "This is a 'git submodule', 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.4 \
565 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
566 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
567 #
568 # On Macs:
569 #   cmake ../blender \
570 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
571 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/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 py34. 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                         if(WITH_CYCLES_NETWORK)
736                                 list(APPEND __boost_packages serialization)
737                         endif()
738                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
739                         if(NOT Boost_FOUND)
740                                 # try to find non-multithreaded if -mt not found, this flag
741                                 # doesn't matter for us, it has nothing to do with thread
742                                 # safety, but keep it to not disturb build setups
743                                 set(Boost_USE_MULTITHREADED OFF)
744                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
745                         endif()
746                         unset(__boost_packages)
747                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
748                                 find_package(IcuLinux)
749                         endif()
750                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
751                 endif()
752
753                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
754                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
755                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
756                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
757         endif()
758
759         if(WITH_OPENIMAGEIO)
760                 find_package_wrapper(OpenImageIO)
761
762                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
763                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
764                 set(OPENIMAGEIO_DEFINITIONS "")
765
766                 if(WITH_IMAGE_TIFF)
767                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
768                 endif()
769                 if(WITH_IMAGE_OPENEXR)
770                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
771                 endif()
772
773                 if(NOT OPENIMAGEIO_FOUND)
774                         set(WITH_OPENIMAGEIO OFF)
775                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
776                 endif()
777         endif()
778
779         if(WITH_OPENCOLORIO)
780                 find_package_wrapper(OpenColorIO)
781
782                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
783                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
784                 set(OPENCOLORIO_DEFINITIONS)
785
786                 if(NOT OPENCOLORIO_FOUND)
787                         set(WITH_OPENCOLORIO OFF)
788                         message(STATUS "OpenColorIO not found")
789                 endif()
790         endif()
791
792         # XXX Maybe most of this section should go into an llvm module?
793         if(WITH_LLVM)
794                 # Set llvm version if not specified
795                 if(NOT LLVM_VERSION)
796                         set(LLVM_VERSION "3.0")
797                 endif()
798
799                 if(LLVM_DIRECTORY)
800                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
801                         if(NOT LLVM_CONFIG)
802                                 find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
803                         endif()
804                 else()
805                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
806                         if(NOT LLVM_CONFIG)
807                                 find_program(LLVM_CONFIG llvm-config)
808                         endif()
809                 endif()
810
811                 if(NOT DEFINED LLVM_VERSION)
812                         execute_process(COMMAND ${LLVM_CONFIG} --version
813                                                         OUTPUT_VARIABLE LLVM_VERSION
814                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
815                         set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
816                 endif()
817                 if(NOT DEFINED LLVM_DIRECTORY)
818                         execute_process(COMMAND ${LLVM_CONFIG} --prefix
819                                                         OUTPUT_VARIABLE LLVM_DIRECTORY
820                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
821                         set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
822                 endif()
823                 if(NOT DEFINED LLVM_LIBPATH)
824                         execute_process(COMMAND ${LLVM_CONFIG} --libdir
825                                                         OUTPUT_VARIABLE LLVM_LIBPATH
826                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
827                         set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
828                         mark_as_advanced(LLVM_LIBPATH)
829                 endif()
830
831                 if(LLVM_STATIC)
832                         find_library(LLVM_LIBRARY
833                                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
834                                      PATHS ${LLVM_LIBPATH})
835                 else()
836                         find_library(LLVM_LIBRARY
837                                      NAMES LLVM-${LLVM_VERSION}
838                                      PATHS ${LLVM_LIBPATH})
839                 endif()
840
841
842                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
843                         if(LLVM_STATIC)
844                                 # if static LLVM libraries were requested, use llvm-config to generate
845                                 # the list of what libraries we need, and substitute that in the right
846                                 # way for LLVM_LIBRARY.
847                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
848                                                 OUTPUT_VARIABLE LLVM_LIBRARY
849                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
850                                 string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
851                         endif()
852                 else()
853                         message(FATAL_ERROR "LLVM not found.")
854                 endif()
855
856                 # Fix for conflict with Mesa llvmpipe
857                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
858         endif()
859
860         if(WITH_CYCLES_OSL)
861                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
862         
863                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
864         
865                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
866                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
867                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
868                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
869                 # otherwise LLVM is missing the osl_allocate_closure_component function
870                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
871                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
872                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
873         
874                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
875                         set(OSL_FOUND TRUE)
876                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
877                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
878                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
879                 else()
880                         message(STATUS "OSL not found")
881                 endif()
882         endif()
883
884         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
885         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread")
886
887         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
888                 find_package(X11 REQUIRED)
889                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
890                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
891
892                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
893
894                 if(WITH_X11_XINPUT)
895                         if(X11_Xinput_LIB)
896                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
897                         else()
898                                 set(WITH_X11_XINPUT OFF)
899                         endif()
900                 endif()
901
902                 if(WITH_X11_XF86VMODE)
903                         # XXX, why dont cmake make this available?
904                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
905                         mark_as_advanced(X11_Xxf86vmode_LIB)
906                         if(X11_Xxf86vmode_LIB)
907                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
908                         else()
909                                 set(WITH_X11_XF86VMODE OFF)
910                         endif()
911                 endif()
912         endif()
913
914         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
915                 if(NOT WITH_PYTHON_MODULE)
916                         # binreloc is linux only
917                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
918                         set(WITH_BINRELOC ON)
919                 endif()
920         endif()
921
922         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
923         if(CMAKE_DL_LIBS)
924                 list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
925         endif()
926
927         # lfs on glibc, all compilers should use
928         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
929
930         # GNU Compiler
931         if(CMAKE_COMPILER_IS_GNUCC)
932                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
933         # CLang is the same as GCC for now.
934         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
935                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
936         # Solaris CC
937         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
938                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
939                 
940         # Intel C++ Compiler
941         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
942                 # think these next two are broken
943                 find_program(XIAR xiar)
944                 if(XIAR)
945                         set(CMAKE_AR "${XIAR}")
946                 endif()
947                 mark_as_advanced(XIAR)
948
949                 find_program(XILD xild)
950                 if(XILD)
951                         set(CMAKE_LINKER "${XILD}")
952                 endif()
953                 mark_as_advanced(XILD)
954
955                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
956                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
957
958                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
959                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
960                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
961         endif()
962
963 elseif(WIN32)
964
965         add_definitions(-DWIN32)
966
967         if(MSVC)
968
969                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
970
971                 add_definitions(
972                         -D_CRT_NONSTDC_NO_DEPRECATE
973                         -D_CRT_SECURE_NO_DEPRECATE
974                         -D_SCL_SECURE_NO_DEPRECATE
975                         -D_CONSOLE
976                         -D_LIB
977                 )
978
979                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
980                 if(NOT MSVC_VERSION VERSION_LESS 1700)
981                         add_definitions(-D_ALLOW_KEYWORD_MACROS)
982                 endif()
983
984                 if(CMAKE_CL_64)
985                         # We want to support Vista level ABI for x64
986                         if(NOT MSVC_VERSION VERSION_LESS 1700)
987                                 add_definitions(-D_WIN32_WINNT=0x600)
988                         endif()
989                 endif()
990
991                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
992                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
993
994                 if(CMAKE_CL_64)
995                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
996                 else()
997                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
998                 endif()
999                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1000                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1001                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1002                 if(CMAKE_CL_64)
1003                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1004                 else()
1005                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1006                 endif()
1007                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1008                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1009                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1010
1011                 # most msvc warnings are C & C++
1012                 set(_WARNINGS
1013                         # warning level:
1014                         "/W3"
1015                         "/w34062"  # switch statement contains 'default' but no 'case' labels
1016                         # disable:
1017                         "/wd4018"  # signed/unsigned mismatch
1018                         "/wd4065"  # switch statement contains 'default' but no 'case' labels
1019                         "/wd4127"  # conditional expression is constant
1020                         "/wd4181"  # qualifier applied to reference type; ignored
1021                         "/wd4200"  # zero-sized array in struct/union
1022                         "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1023                         "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1024                         "/wd4305"  # truncation from 'type1' to 'type2'
1025                         "/wd4800"  # forcing value to bool 'true' or 'false'
1026                         # errors:
1027                         "/we4013"  # 'function' undefined; assuming extern returning int
1028                         "/we4431"  # missing type specifier - int assumed
1029                 )
1030
1031                 string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1032                 set(C_WARNINGS "${_WARNINGS}")
1033                 set(CXX_WARNINGS "${_WARNINGS}")
1034                 unset(_WARNINGS)
1035
1036                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1037
1038                 # MSVC only, Mingw doesnt need
1039                 if(CMAKE_CL_64)
1040                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1041                 else()
1042                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1043                 endif()
1044
1045                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1046
1047                 if(NOT DEFINED LIBDIR)
1048                         # Setup 64bit and 64bit windows systems
1049                         if(CMAKE_CL_64)
1050                                 message(STATUS "64 bit compiler detected.")
1051                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/win64)
1052                         else()
1053                                 message(STATUS "32 bit compiler detected.")
1054                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/windows)
1055                         endif()
1056                         if(MSVC12)
1057                                 message(STATUS "Visual C++ 2013 detected.")
1058                                 set(LIBDIR ${LIBDIR_BASE}_vc12)
1059                         else()
1060                                 set(LIBDIR ${LIBDIR_BASE})
1061                         endif()
1062                 else()
1063                         message(STATUS using LIBDIR  ${LIBDIR})
1064                 endif()
1065
1066                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1067                 FILE(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1068                 FOREACH(child ${children})
1069                 IF(IS_DIRECTORY ${LIBDIR}/${child})
1070                         LIST(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1071                 ENDIF()
1072                 ENDFOREACH()
1073
1074                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1075                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1076                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1077                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1078                 set(ZLIB_DIR ${LIBDIR}/zlib)
1079                 find_package(zlib) # we want to find before finding things that depend on it like png
1080
1081
1082                 find_package(png)
1083                 if(NOT PNG_FOUND)
1084                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1085                         message(WARNING "Using HARDCODED libpng locations")
1086                         set(PNG_LIBRARIES libpng)
1087                         set(PNG "${LIBDIR}/png")
1088                         set(PNG_INCLUDE_DIR "${PNG}/include")
1089                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1090                 endif()
1091
1092                 if(MSVC90)
1093                         set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
1094                 endif()
1095                 find_package(jpeg REQUIRED)
1096
1097                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1098                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1099
1100                 set(FREETYPE ${LIBDIR}/freetype)
1101                 set(FREETYPE_INCLUDE_DIRS
1102                         ${LIBDIR}/freetype/include
1103                         ${LIBDIR}/freetype/include/freetype2
1104                 )
1105                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1106                 find_package(freetype REQUIRED)
1107
1108                 if(WITH_FFTW3)
1109                         set(FFTW3 ${LIBDIR}/fftw3)
1110                         set(FFTW3_LIBRARIES libfftw)
1111                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1112                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1113                 endif()
1114
1115                 if(WITH_OPENCOLLADA)
1116                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1117
1118                         set(OPENCOLLADA_INCLUDE_DIRS
1119                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1120                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1121                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1122                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1123                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1124                         )
1125
1126                         set(OPENCOLLADA_LIBRARIES
1127                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1128                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1129                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1130                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1131                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1132                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1133                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1134                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1135                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1136                                 ${OPENCOLLADA}/lib/opencollada/UTF.lib
1137                         )
1138                         set(PCRE_LIBRARIES
1139                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1140                         )
1141                 endif()
1142
1143                 if(WITH_CODEC_FFMPEG)
1144                         set(FFMPEG_INCLUDE_DIRS
1145                                 ${LIBDIR}/ffmpeg/include
1146                                 ${LIBDIR}/ffmpeg/include/msvc
1147                         )
1148                         find_package(FFMPEG)
1149                         if(NOT FFMPEG_FOUND)
1150                                 message(WARNING "Using HARDCODED ffmpeg locations")
1151                                 set(FFMPEG_LIBRARY_VERSION 55)
1152                                 set(FFMPEG_LIBRARY_VERSION_AVU 52)
1153                                 set(FFMPEG_LIBRARIES
1154                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1155                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1156                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1157                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1158                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1159                                         )
1160                         endif()
1161                 endif()
1162
1163                 if(WITH_IMAGE_OPENEXR)
1164                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1165                         set(OPENEXR_VERSION "2.1")
1166                         find_package(OPENEXR REQUIRED)
1167                         if(NOT OPENEXR_FOUND)
1168                         message(WARNING "Using HARDCODED OpenEXR locations")
1169                         set(OPENEXR ${LIBDIR}/openexr)
1170                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1171                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1172                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1173                         set(OPENEXR_LIBRARIES
1174                                 ${OPENEXR_LIBPATH}/Iex.lib
1175                                 ${OPENEXR_LIBPATH}/Half.lib
1176                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1177                                 ${OPENEXR_LIBPATH}/Imath.lib
1178                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1179                         )
1180                         endif(NOT OPENEXR_FOUND)
1181                 endif()
1182
1183                 if(WITH_IMAGE_TIFF)
1184                 # Try to find tiff first then complain and set static and maybe wrong paths
1185                 find_package(TIFF)
1186                 if(NOT TIFF_FOUND)
1187                         message(WARNING "Using HARDCODED libtiff locations")
1188                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1189                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1190                 endif()
1191                 endif()
1192
1193                 if(WITH_JACK)
1194                         set(JACK_INCLUDE_DIRS
1195                                 ${LIBDIR}/jack/include/jack
1196                                 ${LIBDIR}/jack/include
1197                         )
1198                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1199                 endif()
1200
1201                 if(WITH_PYTHON)
1202                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1203
1204                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1205                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1206                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1207                         unset(_PYTHON_VERSION_NO_DOTS)
1208
1209                         # Shared includes for both vc2008 and vc2010
1210                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1211
1212                         # uncached vars
1213                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1214                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1215                 endif()
1216
1217                 if(WITH_BOOST)
1218                         if(WITH_CYCLES_OSL)
1219                                 set(boost_extra_libs wave)
1220                         endif(WITH_CYCLES_OSL)
1221                         if(WITH_INTERNATIONAL)
1222                                 list(APPEND boost_extra_libs locale)
1223                         endif(WITH_INTERNATIONAL)
1224                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1225                         IF(NOT Boost_FOUND)
1226                                 message(WARNING "USING HARDCODED boost locations")
1227                                 set(BOOST ${LIBDIR}/boost)
1228                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1229                                 if(MSVC12)
1230                                         set(BOOST_LIBPATH ${BOOST}/lib)
1231                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1232                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1233                                 else()
1234                                         set(BOOST_LIBPATH ${BOOST}/lib)
1235                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1236                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1237                                 endif()
1238                                 set(BOOST_LIBRARIES
1239                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1240                                         optimized libboost_regex-${BOOST_POSTFIX}
1241                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1242                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1243                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1244                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1245                                 if(WITH_CYCLES_OSL)
1246                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1247                                                 optimized libboost_wave-${BOOST_POSTFIX}
1248                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1249                                 endif()
1250                                 if(WITH_INTERNATIONAL)
1251                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1252                                                 optimized libboost_locale-${BOOST_POSTFIX}
1253                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1254                                 endif()
1255                         else() # we found boost using find_package
1256                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1257                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1258                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1259                         endif()
1260                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1261                 endif()
1262                         
1263                 if(WITH_OPENIMAGEIO)
1264                         find_package(OpenImageIO)
1265                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1266                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1267                         set(OPENIMAGEIO_LIBRARIES optimized OpenImageIO debug OpenImageIO_d)
1268                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1269                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1270                 endif()
1271
1272                 if(WITH_LLVM)
1273                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1274                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_DIRECTORY}/lib/*.lib)
1275
1276                         if(EXISTS ${LLVM_DIRECTORY}/debug/lib)
1277                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1278                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1279                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1280                                 endforeach(LLVM_OPTIMIZED_LIB)
1281                         
1282                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_DIRECTORY}/debug/lib/*.lib)
1283
1284                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1285                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1286                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1287                                 endforeach(LLVM_DEBUG_LIB)
1288
1289                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1290                         else()
1291                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1292                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1293                         endif()
1294                         
1295                 endif()
1296         
1297                 if(WITH_OPENCOLORIO)
1298                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1299                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1300                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1301                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1302                         set(OPENCOLORIO_DEFINITIONS)
1303                 endif()
1304                 
1305
1306                 if(WITH_MOD_CLOTH_ELTOPO)
1307                         set(LAPACK ${LIBDIR}/lapack)
1308                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1309                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1310                         set(LAPACK_LIBRARIES
1311                                 ${LIBDIR}/lapack/lib/libf2c.lib
1312                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1313                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1314                         )
1315                 endif()
1316
1317                 # used in many places so include globally, like OpenGL
1318                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1319
1320         elseif(CMAKE_COMPILER_IS_GNUCC)
1321                 # keep GCC specific stuff here
1322                 include(CheckCSourceCompiles)
1323                 # Setup 64bit and 64bit windows systems
1324                 CHECK_C_SOURCE_COMPILES("
1325                         #ifndef __MINGW64__
1326                         #error
1327                         #endif
1328                         int main(void) { return 0; }
1329                         " 
1330                         WITH_MINGW64)
1331                 
1332                 if(WITH_MINGW64)
1333                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1334                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1335                 else()
1336                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1337                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1338                         
1339                         if(WITH_RAYOPTIMIZATION)
1340                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1341                         endif()
1342                 endif()
1343                 
1344                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1345                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1346
1347                 if(WITH_MINGW64)
1348                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1349                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1350                         
1351                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1352                 endif()
1353
1354                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1355
1356                 add_definitions(-DFREE_WINDOWS)
1357
1358                 set(PNG "${LIBDIR}/png")
1359                 set(PNG_INCLUDE_DIR "${PNG}/include")
1360                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1361
1362                 if(WITH_MINGW64)
1363                         set(JPEG_LIBRARIES jpeg)
1364                 else()
1365                         set(JPEG_LIBRARIES libjpeg)
1366                 endif()
1367                 set(PNG_LIBRARIES png)
1368
1369                 set(ZLIB ${LIBDIR}/zlib)
1370                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1371                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1372                 set(ZLIB_LIBRARIES z)
1373
1374                 set(JPEG "${LIBDIR}/jpeg")
1375                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1376                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1377                 
1378                 # comes with own pthread library
1379                 if(NOT WITH_MINGW64)
1380                         set(PTHREADS ${LIBDIR}/pthreads)
1381                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1382                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1383                         set(PTHREADS_LIBRARIES pthreadGC2)
1384                 endif()
1385                 
1386                 set(FREETYPE ${LIBDIR}/freetype)
1387                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1388                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1389                 set(FREETYPE_LIBRARY freetype)
1390
1391                 if(WITH_FFTW3)
1392                         set(FFTW3 ${LIBDIR}/fftw3)
1393                         set(FFTW3_LIBRARIES fftw3)
1394                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1395                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1396                 endif()
1397
1398                 if(WITH_OPENCOLLADA)
1399                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1400                         set(OPENCOLLADA_INCLUDE_DIRS
1401                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1402                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1403                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1404                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1405                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1406                         )
1407                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1408                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1409                         set(PCRE_LIBRARIES pcre)
1410                 endif()
1411
1412                 if(WITH_CODEC_FFMPEG)
1413                         set(FFMPEG ${LIBDIR}/ffmpeg)
1414                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1415                         if(WITH_MINGW64)
1416                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1417                         else()
1418                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1419                         endif()
1420                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1421                 endif()
1422
1423                 if(WITH_IMAGE_OPENEXR)
1424                         set(OPENEXR ${LIBDIR}/openexr)
1425                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1426                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1427                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1428                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1429                 endif()
1430
1431                 if(WITH_IMAGE_TIFF)
1432                         set(TIFF ${LIBDIR}/tiff)
1433                         set(TIFF_LIBRARY tiff)
1434                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1435                         set(TIFF_LIBPATH ${TIFF}/lib)
1436                 endif()
1437
1438                 if(WITH_JACK)
1439                         set(JACK ${LIBDIR}/jack)
1440                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1441                         set(JACK_LIBRARIES jack)
1442                         set(JACK_LIBPATH ${JACK}/lib)
1443
1444                         # TODO, gives linking errors, force off
1445                         set(WITH_JACK OFF)
1446                 endif()
1447
1448                 if(WITH_PYTHON)
1449                         # normally cached but not since we include them with blender
1450                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1451                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1452                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1453                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1454                         unset(_PYTHON_VERSION_NO_DOTS)
1455
1456                         # uncached vars
1457                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1458                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1459                 endif()
1460
1461                 if(WITH_BOOST)
1462                         set(BOOST ${LIBDIR}/boost)
1463                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1464                         if(WITH_MINGW64)
1465                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1466                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1467                         else()
1468                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1469                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1470                         endif()
1471                         set(BOOST_LIBRARIES
1472                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1473                                 boost_regex-${BOOST_POSTFIX}
1474                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1475                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1476                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1477                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1478                         if(WITH_INTERNATIONAL)
1479                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1480                                         optimized boost_locale-${BOOST_POSTFIX}
1481                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1482                         endif()
1483                         if(WITH_CYCLES_OSL)
1484                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1485                                         optimized boost_wave-${BOOST_POSTFIX}
1486                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1487                         endif()
1488                         set(BOOST_LIBPATH ${BOOST}/lib)
1489                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1490                 endif()
1491                         
1492                 if(WITH_OPENIMAGEIO)
1493                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1494                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1495                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1496                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1497                         set(OPENIMAGEIO_DEFINITIONS "")
1498                 endif()
1499                 
1500                 if(WITH_LLVM)
1501                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1502                         set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
1503                         # Explicitly set llvm lib order.
1504                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1505                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1506                                 LLVMAsmParser LLVMAsmPrinter
1507                                 LLVMBitReader LLVMBitWriter
1508                                 LLVMDebugInfo LLVMExecutionEngine
1509                                 LLVMInstCombine LLVMInstrumentation
1510                                 LLVMInterpreter LLVMJIT
1511                                 LLVMLinker LLVMMC
1512                                 LLVMMCDisassembler LLVMMCJIT
1513                                 LLVMMCParser LLVMObject
1514                                 LLVMRuntimeDyld 
1515                                 LLVMSupport
1516                                 LLVMTableGen LLVMTarget
1517                                 LLVMTransformUtils LLVMVectorize
1518                                 LLVMX86AsmParser LLVMX86AsmPrinter
1519                                 LLVMX86CodeGen LLVMX86Desc
1520                                 LLVMX86Disassembler LLVMX86Info
1521                                 LLVMX86Utils LLVMipa
1522                                 LLVMipo LLVMCore)
1523                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1524                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
1525                 endif()
1526                 
1527                 if(WITH_OPENCOLORIO)
1528                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1529                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1530                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1531                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1532                         set(OPENCOLORIO_DEFINITIONS)
1533                 endif()
1534
1535                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1536
1537                 ## DISABLE - causes linking errors 
1538                 ## for re-distribution, so users dont need mingw installed
1539                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1540
1541         endif()
1542         
1543         # Things common to both mingw and MSVC  should go here
1544
1545         set(WINTAB_INC ${LIBDIR}/wintab/include)
1546
1547         if(WITH_OPENAL)
1548                 set(OPENAL ${LIBDIR}/openal)
1549                 set(OPENALDIR ${LIBDIR}/openal)
1550                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1551                 if(MSVC12)
1552                         set(OPENAL_LIBRARY openal32)
1553                 else()
1554                         set(OPENAL_LIBRARY wrap_oal)
1555                 endif()
1556                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1557         endif()
1558
1559         if(WITH_CODEC_SNDFILE)
1560                 set(SNDFILE ${LIBDIR}/sndfile)
1561                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1562                 set(SNDFILE_LIBRARIES libsndfile-1)
1563                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1564         endif()
1565
1566         if(WITH_SDL)
1567                 set(SDL ${LIBDIR}/sdl)
1568                 set(SDL_INCLUDE_DIR ${SDL}/include)
1569                 set(SDL_LIBRARY SDL)
1570                 set(SDL_LIBPATH ${SDL}/lib)
1571         endif()
1572
1573         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1574                 add_definitions(-D__SSE__ -D__MMX__)
1575         endif()
1576
1577         if(WITH_CYCLES_OSL)
1578                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1579         
1580                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1581                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1582                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1583                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1584                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1585                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1586                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1587                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1588                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1589         
1590                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1591                         set(OSL_FOUND TRUE)
1592                 else()
1593                         message(STATUS "OSL not found")
1594                 endif()
1595         endif()
1596
1597 elseif(APPLE)
1598
1599         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1600                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1601         endif()
1602
1603         if(WITH_LIBS10.5)
1604                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1605         else()
1606                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1607                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1608                 else()
1609                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1610                 endif()
1611         endif()
1612
1613
1614         if(WITH_OPENAL)
1615                 find_package(OpenAL)
1616                 if(OPENAL_FOUND)
1617                         set(WITH_OPENAL ON)
1618                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1619                 else()
1620                         set(WITH_OPENAL OFF)
1621                 endif()
1622         endif()
1623
1624         if(WITH_JACK)
1625                 find_library(JACK_FRAMEWORK
1626                         NAMES jackmp
1627                 )
1628                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1629                 if(NOT JACK_FRAMEWORK)
1630                         set(WITH_JACK OFF)
1631                 endif()
1632         endif()
1633
1634         if(WITH_CODEC_SNDFILE)
1635                 set(SNDFILE ${LIBDIR}/sndfile)
1636                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1637                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1638                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1639         endif()
1640
1641         if(WITH_PYTHON)
1642                 # we use precompiled libraries for py 3.4 and up by default
1643                 set(PYTHON_VERSION 3.4)
1644                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1645                         # normally cached but not since we include them with blender
1646                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1647                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1648                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1649                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1650                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1651                 else()
1652                         # module must be compiled against Python framework
1653                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1654                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1655                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1656                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1657                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1658                 endif()
1659                 
1660                 # uncached vars
1661                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1662                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1663         endif()
1664
1665         if(WITH_FFTW3)
1666                 set(FFTW3 ${LIBDIR}/fftw3)
1667                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1668                 set(FFTW3_LIBRARIES fftw3)
1669                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1670         endif()
1671
1672         set(PNG_LIBRARIES png)
1673         set(JPEG_LIBRARIES jpeg)
1674
1675         set(ZLIB /usr)
1676         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1677         set(ZLIB_LIBRARIES z bz2)
1678
1679         set(FREETYPE ${LIBDIR}/freetype)
1680         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1681         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1682         set(FREETYPE_LIBRARY freetype)
1683
1684         if(WITH_IMAGE_OPENEXR)
1685                 set(OPENEXR ${LIBDIR}/openexr)
1686                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1687                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1688                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1689                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1690         endif()
1691
1692         if(WITH_CODEC_FFMPEG)
1693                 set(FFMPEG ${LIBDIR}/ffmpeg)
1694                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1695                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1696                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1697                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1698         endif()
1699
1700         find_library(SYSTEMSTUBS_LIBRARY
1701                 NAMES
1702                 SystemStubs
1703                 PATHS
1704         )
1705         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1706         if(SYSTEMSTUBS_LIBRARY)
1707                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1708         else()
1709                 set(PLATFORM_LINKLIBS stdc++)
1710         endif()
1711
1712         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1713         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1714         if(WITH_CODEC_QUICKTIME)
1715                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1716                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1717                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1718                         # libSDL still needs 32bit carbon quicktime
1719                 endif()
1720         endif()
1721
1722         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1723         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1724         if(WITH_INPUT_NDOF)
1725                 # This thread it *should* work and check the framework - campbell
1726                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1727                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1728                         NAMES 3DconnexionClient
1729                 )
1730                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1731                         set(WITH_INPUT_NDOF OFF)
1732                 endif()
1733
1734                 if(WITH_INPUT_NDOF)
1735                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1736                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1737                 endif()
1738         endif()
1739
1740         if(WITH_JACK)
1741                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1742         endif()
1743         
1744         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1745                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1746         endif()
1747         
1748         if(WITH_OPENCOLLADA)
1749                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1750
1751                 set(OPENCOLLADA_INCLUDE_DIRS
1752                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1753                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1754                         ${LIBDIR}/opencollada/include/COLLADAFramework
1755                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1756                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1757                 )
1758
1759                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1760                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1761                 # pcre is bundled with openCollada
1762                 #set(PCRE ${LIBDIR}/pcre)
1763                 #set(PCRE_LIBPATH ${PCRE}/lib)
1764                 set(PCRE_LIBRARIES pcre)
1765                 #libxml2 is used
1766                 #set(EXPAT ${LIBDIR}/expat)
1767                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1768                 set(EXPAT_LIB)
1769         endif()
1770
1771         if(WITH_SDL)
1772                 set(SDL ${LIBDIR}/sdl)
1773                 set(SDL_INCLUDE_DIR ${SDL}/include)
1774                 set(SDL_LIBRARY SDL)
1775                 set(SDL_LIBPATH ${SDL}/lib)
1776         endif()
1777
1778         set(PNG "${LIBDIR}/png")
1779         set(PNG_INCLUDE_DIR "${PNG}/include")
1780         set(PNG_LIBPATH ${PNG}/lib)
1781
1782         set(JPEG "${LIBDIR}/jpeg")
1783         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1784         set(JPEG_LIBPATH ${JPEG}/lib)
1785
1786         if(WITH_IMAGE_TIFF)
1787                 set(TIFF ${LIBDIR}/tiff)
1788                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1789                 set(TIFF_LIBRARY tiff)
1790                 set(TIFF_LIBPATH ${TIFF}/lib)
1791         endif()
1792
1793         if(WITH_INPUT_NDOF)
1794                 # linker needs "-weak_framework 3DconnexionClient"
1795         endif()
1796
1797         if(WITH_BOOST)
1798                 set(BOOST ${LIBDIR}/boost)
1799                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1800                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1801                 if(WITH_INTERNATIONAL)
1802                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1803                 endif()
1804                 if(WITH_CYCLES_NETWORK)
1805                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
1806                 endif()
1807                 set(BOOST_LIBPATH ${BOOST}/lib)
1808                 set(BOOST_DEFINITIONS)
1809         endif()
1810         
1811         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
1812                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
1813         endif()
1814
1815         if(WITH_OPENIMAGEIO)
1816                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1817                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1818                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1819                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1820                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1821         endif()
1822
1823         if(WITH_OPENCOLORIO)
1824                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1825                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1826                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1827                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1828                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1829         endif()
1830
1831         if(WITH_LLVM)
1832                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1833                 set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
1834                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1835                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1836                 else()
1837                         set(LLVM_CONFIG llvm-config)
1838                 endif()
1839                 execute_process(COMMAND ${LLVM_CONFIG} --version
1840                                 OUTPUT_VARIABLE LLVM_VERSION
1841                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1842                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1843                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1844                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1845                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1846                                 OUTPUT_VARIABLE LLVM_LIBPATH
1847                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1848                 find_library(LLVM_LIBRARY
1849                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1850                              PATHS ${LLVM_LIBPATH})
1851
1852                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
1853                         if(LLVM_STATIC)
1854                                 # if static LLVM libraries were requested, use llvm-config to generate
1855                                 # the list of what libraries we need, and substitute that in the right
1856                                 # way for LLVM_LIBRARY.
1857                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1858                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1859                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1860                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1861                         endif()
1862                 else()
1863                         message(FATAL_ERROR "LLVM not found.")
1864                 endif()
1865         endif()
1866
1867         if(WITH_CYCLES_OSL)
1868                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1869         
1870                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1871                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1872                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1873                 # WARNING! depends on correct order of OSL libs linking
1874                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1875                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1876                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1877         
1878                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1879                         set(OSL_FOUND TRUE)
1880                 else()
1881                         message(STATUS "OSL not found")
1882                 endif()
1883         endif()
1884         
1885         if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
1886                 set(OPENMP_FOUND ON)
1887                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
1888                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
1889                 include_directories(${LIBDIR}/openmp/include)
1890                 LINK_DIRECTORIES(${LIBDIR}/openmp/lib)
1891                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/bin/libiomp5.dylib) # for intermediate binaries, lib id is @loader_path
1892         else()
1893                 set(OpenMP_C_FLAGS "" CACHE STRING "C compiler flags for OpenMP parallization" FORCE) # unset
1894                 set(OpenMP_CXX_FLAGS "" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE) # unset
1895         endif()
1896
1897         set(EXETYPE MACOSX_BUNDLE)
1898
1899         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1900         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1901         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1902                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
1903                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
1904                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
1905                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1906                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1907                 endif()
1908         else()
1909                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1910                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1911         endif()
1912
1913         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
1914                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
1915                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
1916         endif()
1917 endif()
1918
1919 #-----------------------------------------------------------------------------
1920 # Common.
1921
1922 if(APPLE OR WIN32)
1923         if(NOT EXISTS "${LIBDIR}/")
1924                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1925         endif()
1926 endif()
1927
1928 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
1929         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
1930 endif()
1931
1932 if(WITH_CYCLES)
1933         if(NOT WITH_OPENIMAGEIO)
1934                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1935         endif()
1936         if(NOT WITH_BOOST)
1937                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1938         endif()
1939
1940         if(WITH_CYCLES_OSL)
1941                 if(NOT WITH_LLVM)
1942                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
1943                 endif()
1944         endif()
1945 endif()
1946
1947 if(WITH_INTERNATIONAL)
1948         if(NOT WITH_BOOST)
1949                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
1950         endif()
1951 endif()
1952
1953 # See TEST_SSE_SUPPORT() for how this is defined.
1954
1955 if(WITH_RAYOPTIMIZATION)
1956         if(SUPPORT_SSE_BUILD)
1957                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1958                 add_definitions(-D__SSE__ -D__MMX__)
1959         endif()
1960         if(SUPPORT_SSE2_BUILD)
1961                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1962                 add_definitions(-D__SSE2__)
1963                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1964                         add_definitions(-D__MMX__)
1965                 endif()
1966         endif()
1967 endif()
1968
1969
1970 # set the endian define
1971 if(MSVC)
1972         # for some reason this fails on msvc
1973         add_definitions(-D__LITTLE_ENDIAN__)
1974         
1975 # OSX-Note: as we do crosscompiling with specific set architecture,
1976 # endianess-detection and autosetting is counterproductive
1977 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1978
1979 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1980         add_definitions(-D__LITTLE_ENDIAN__)
1981 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1982         add_definitions(-D__BIG_ENDIAN__)
1983         
1984 else()
1985         include(TestBigEndian)
1986         test_big_endian(_SYSTEM_BIG_ENDIAN)
1987         if(_SYSTEM_BIG_ENDIAN)
1988                 add_definitions(-D__BIG_ENDIAN__)
1989         else()
1990                 add_definitions(-D__LITTLE_ENDIAN__)
1991         endif()
1992         unset(_SYSTEM_BIG_ENDIAN)
1993 endif()
1994
1995
1996 if(WITH_IMAGE_OPENJPEG)
1997         if(WITH_SYSTEM_OPENJPEG)
1998                 # dealt with above
1999         else()
2000                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2001                 add_definitions(-DOPJ_STATIC)
2002         endif()
2003 endif()
2004
2005 if(WITH_IMAGE_REDCODE)
2006         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2007         set(REDCODE_INC ${REDCODE})
2008 endif()
2009
2010
2011 #-----------------------------------------------------------------------------
2012 # Configure OpenGL.
2013 find_package(OpenGL)
2014 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2015 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
2016 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
2017
2018 #-----------------------------------------------------------------------------
2019 # Configure OpenMP.
2020 if(WITH_OPENMP)
2021         find_package(OpenMP)
2022         if(OPENMP_FOUND)
2023                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2024                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2025
2026                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
2027                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
2028                 endif()
2029         else()
2030                 set(WITH_OPENMP OFF)
2031         endif()
2032
2033         mark_as_advanced(
2034                 OpenMP_C_FLAGS
2035                 OpenMP_CXX_FLAGS
2036         )
2037 endif()
2038
2039 #-----------------------------------------------------------------------------
2040 # Configure GLEW
2041
2042 if(WITH_SYSTEM_GLEW)
2043         find_package(GLEW)
2044
2045         if(NOT GLEW_FOUND)
2046                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
2047         endif()
2048
2049         mark_as_advanced(
2050                 GLEW_LIBRARY
2051                 GLEW_INCLUDE_PATH
2052         )
2053 else()
2054         # set(GLEW_LIBRARY "")  # unused
2055         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2056 endif()
2057
2058
2059 #-----------------------------------------------------------------------------
2060 # Configure Bullet
2061
2062 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2063         find_package(Bullet)
2064         if(NOT BULLET_FOUND)
2065                 set(WITH_BULLET OFF)
2066         endif()
2067 else()
2068         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2069         # set(BULLET_LIBRARIES "")
2070 endif()
2071
2072 #-----------------------------------------------------------------------------
2073 # Configure Python.
2074
2075 if(WITH_PYTHON_MODULE)
2076         add_definitions(-DPy_ENABLE_SHARED)
2077 endif()
2078
2079 #-----------------------------------------------------------------------------
2080 # Extra compile flags
2081
2082 if(CMAKE_COMPILER_IS_GNUCC)
2083
2084         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2085         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2086         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2087         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2088         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2089         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2090         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2091         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2092         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2093         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2094         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2095         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2096         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2097         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2098         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2099         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2100         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2101         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2102         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2103         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2104
2105         # gcc 4.2 gives annoying warnings on every file with this
2106         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2107                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2108         endif()
2109
2110         # versions before gcc4.6 give many BLI_math warnings
2111         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2112                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2113                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2114         endif()
2115
2116         # disable because it gives warnings for printf() & friends.
2117         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2118
2119         if(NOT APPLE)
2120                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2121         endif()
2122
2123         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2124         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2125         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2126         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2127         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2128         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2129         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2130         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2131
2132         # gcc 4.2 gives annoying warnings on every file with this
2133         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2134                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2135         endif()
2136
2137         # causes too many warnings
2138         if(NOT APPLE)
2139                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2140                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2141         endif()
2142
2143         # flags to undo strict flags
2144         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2145         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2146
2147         if(NOT APPLE)
2148                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2149         endif()
2150
2151 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2152
2153         # strange, clang complains these are not supported, but then yses them.
2154         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2155         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2156         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2157         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2158         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2159         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2160         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2161         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2162         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2163         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2164
2165         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2166         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2167         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2168         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2169         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.
2170         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2171         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2172
2173         # gives too many unfixable warnings
2174         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2175         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2176
2177         # flags to undo strict flags
2178         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2179         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2180
2181         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2182         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2183         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2184         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2185         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2186         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2187         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2188         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2189
2190         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2191         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2192         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2193         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2194         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2195
2196 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2197
2198         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2199         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2200         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2201
2202         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2203         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2204         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2205
2206         # disable numbered, false positives
2207         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2208         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2209
2210 endif()
2211
2212 # ensure python header is found since detection can fail, this could happen
2213 # with _any_ library but since we used a fixed python version this tends to
2214 # be most problematic.
2215 if(WITH_PYTHON)
2216         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2217                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2218                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2219                                                         "to a valid python include path. Containing "
2220                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2221         endif()
2222
2223         if(WIN32)
2224                 # pass, we have this in an archive to extract
2225         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2226                 # set but invalid
2227                 # -- disabled until we make numpy bundled with blender - campbell
2228                 if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
2229 #                       if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
2230 #                               message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
2231 #                                               "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2232 #                               set(WITH_PYTHON_INSTALL_NUMPY OFF)
2233 #                       endif()
2234                 # not set, so initialize
2235                 else()
2236                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
2237                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
2238
2239                         # re-cache
2240                         unset(PYTHON_NUMPY_PATH CACHE)
2241                         find_path(PYTHON_NUMPY_PATH
2242                           NAMES
2243                             numpy
2244                           HINTS
2245                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
2246                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
2247                           PATH_SUFFIXES
2248                             site-packages
2249                             dist-packages
2250                            NO_DEFAULT_PATH
2251                         )
2252
2253                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
2254                                 message(WARNING "'numpy' path could not be found in:\n"
2255                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
2256                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
2257                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
2258                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
2259                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2260                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
2261                         else()
2262                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
2263                         endif()
2264
2265                         unset(_PY_VER_SPLIT)
2266                         unset(_PY_VER_MAJOR)
2267                 endif()
2268         endif()
2269
2270         if(WIN32 OR APPLE)
2271                 # pass, we have this in lib/python/site-packages
2272         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2273                 if(NOT EXISTS ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests)
2274                         # gets annoying otherwise...
2275                         if(FIRST_RUN)
2276                                 message(WARNING "'requests' path could not be found in:\n"
2277                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests'\n"
2278                                                 "WITH_PYTHON_INSTALL_REQUESTS option will be ignored when installing python")
2279                         endif()
2280                         set(WITH_PYTHON_INSTALL_REQUESTS OFF)
2281                 endif()
2282         endif()
2283 endif()
2284
2285 if(WITH_GCC_MUDFLAP)
2286         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2287         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2288         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2289         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2290 endif()
2291
2292 # Include warnings first, so its possible to disable them with user defined flags
2293 # eg: -Wno-uninitialized
2294 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2295 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2296
2297 # defined above, platform spesific but shared names
2298 mark_as_advanced(
2299         CYCLES_OSL
2300         OSL_LIB_EXEC
2301         OSL_COMPILER
2302         OSL_LIB_COMP
2303         OSL_LIB_QUERY
2304         OSL_INCLUDES
2305 )
2306
2307 mark_as_advanced(
2308         LLVM_CONFIG
2309         LLVM_DIRECTORY
2310         LLVM_LIBRARY
2311         LLVM_VERSION
2312 )
2313
2314 #-------------------------------------------------------------------------------
2315 # Global Defines
2316
2317 # better not set includes here but this debugging option is off by default.
2318 if(WITH_CXX_GUARDEDALLOC)
2319         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2320         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2321 endif()
2322
2323 if(WITH_ASSERT_ABORT)
2324         add_definitions(-DWITH_ASSERT_ABORT)
2325 endif()
2326
2327 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2328 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2329
2330 #-----------------------------------------------------------------------------
2331 # Libraries
2332
2333 if(WITH_BLENDER OR WITH_PLAYER)
2334         add_subdirectory(source)
2335         add_subdirectory(intern)
2336         add_subdirectory(extern)
2337 elseif(WITH_CYCLES_STANDALONE)
2338         add_subdirectory(intern/cycles)
2339         if(NOT WITH_SYSTEM_GLEW)
2340                 add_subdirectory(extern/glew)
2341         endif()
2342 endif()
2343
2344 #-----------------------------------------------------------------------------
2345 # Blender Application
2346 if(WITH_BLENDER)
2347         add_subdirectory(source/creator)
2348 endif()
2349
2350
2351 #-----------------------------------------------------------------------------
2352 # Blender Player
2353 if(WITH_PLAYER)
2354         add_subdirectory(source/blenderplayer)
2355 endif()
2356
2357 #-----------------------------------------------------------------------------
2358 # CPack for generating packages
2359 include(build_files/cmake/packaging.cmake)
2360
2361
2362 #-----------------------------------------------------------------------------
2363 # Print Final Configuration
2364
2365 if(FIRST_RUN)
2366         set(_config_msg "\n* Blender Configuration *")
2367         macro(info_cfg_option
2368                 _setting)
2369                 set(_msg "   * ${_setting}")
2370                 string(LENGTH "${_msg}" _len)
2371                 while("32" GREATER "${_len}")
2372                         set(_msg "${_msg} ")
2373                          math(EXPR _len "${_len} + 1")
2374                 endwhile()
2375
2376                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2377         endmacro()
2378
2379         macro(info_cfg_text
2380                 _text)
2381                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2382
2383
2384         endmacro()
2385
2386         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2387         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2388
2389         info_cfg_text("Build Options:")
2390         info_cfg_option(WITH_GAMEENGINE)
2391         info_cfg_option(WITH_PLAYER)
2392         info_cfg_option(WITH_BULLET)
2393         info_cfg_option(WITH_IK_SOLVER)
2394         info_cfg_option(WITH_IK_ITASC)
2395         info_cfg_option(WITH_OPENCOLLADA)
2396         info_cfg_option(WITH_FFTW3)
2397         info_cfg_option(WITH_INTERNATIONAL)
2398         info_cfg_option(WITH_INPUT_NDOF)
2399         info_cfg_option(WITH_CYCLES)
2400         info_cfg_option(WITH_FREESTYLE)
2401         info_cfg_option(WITH_OPENCOLORIO)
2402
2403         info_cfg_text("Compiler Options:")
2404         info_cfg_option(WITH_BUILDINFO)
2405         info_cfg_option(WITH_OPENMP)
2406         info_cfg_option(WITH_RAYOPTIMIZATION)
2407
2408         info_cfg_text("System Options:")
2409         info_cfg_option(WITH_INSTALL_PORTABLE)
2410         info_cfg_option(WITH_X11_XF86VMODE)
2411         info_cfg_option(WITH_X11_XINPUT)
2412         info_cfg_option(WITH_MEM_JEMALLOC)
2413         info_cfg_option(WITH_MEM_VALGRIND)
2414         info_cfg_option(WITH_SYSTEM_GLEW)
2415         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2416
2417         info_cfg_text("Image Formats:")
2418         info_cfg_option(WITH_OPENIMAGEIO)
2419         info_cfg_option(WITH_IMAGE_CINEON)
2420         info_cfg_option(WITH_IMAGE_DDS)
2421         info_cfg_option(WITH_IMAGE_HDR)
2422         info_cfg_option(WITH_IMAGE_OPENEXR)
2423         info_cfg_option(WITH_IMAGE_OPENJPEG)
2424         info_cfg_option(WITH_IMAGE_REDCODE)
2425         info_cfg_option(WITH_IMAGE_TIFF)
2426
2427         info_cfg_text("Audio:")
2428         info_cfg_option(WITH_OPENAL)
2429         info_cfg_option(WITH_SDL)
2430         info_cfg_option(WITH_JACK)
2431         info_cfg_option(WITH_JACK_DYNLOAD)
2432         info_cfg_option(WITH_CODEC_AVI)
2433         info_cfg_option(WITH_CODEC_FFMPEG)
2434         info_cfg_option(WITH_CODEC_SNDFILE)
2435
2436         info_cfg_text("Compression:")
2437         info_cfg_option(WITH_LZMA)
2438         info_cfg_option(WITH_LZO)
2439
2440         info_cfg_text("Python:")
2441         info_cfg_option(WITH_PYTHON_INSTALL)
2442         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2443         info_cfg_option(WITH_PYTHON_MODULE)
2444         info_cfg_option(WITH_PYTHON_SAFETY)
2445         if(APPLE)
2446                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2447         endif()
2448
2449         info_cfg_text("Modifiers:")
2450         info_cfg_option(WITH_MOD_BOOLEAN)
2451         info_cfg_option(WITH_MOD_REMESH)
2452         info_cfg_option(WITH_MOD_FLUID)
2453         info_cfg_option(WITH_MOD_OCEANSIM)
2454
2455         info_cfg_text("Other:")
2456         info_cfg_option(WITH_OPENNL)
2457
2458         # debug
2459         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2460
2461         info_cfg_text("")
2462
2463         message("${_config_msg}")
2464 endif()