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