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