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