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