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