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