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