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