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