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