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