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