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