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