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