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