Cleanup: cmake
[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 SDL)
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         set(CPACK_PACKAGE_INSTALL_DIRECTORY "Blender Foundation/Blender")
1707         set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "Blender Foundation/Blender")
1708         set(CPACK_WIX_LICENSE_RTF ${CMAKE_SOURCE_DIR}/release/text/GPL-license.rtf)
1709         set(CPACK_WIX_PRODUCT_ICON ${CMAKE_SOURCE_DIR}/source/icons/winblender.ico)
1710         set(CPACK_WIX_UPGRADE_GUID "B767E4FD-7DE7-4094-B051-3AE62E13A17A")
1711
1712 elseif(APPLE)
1713
1714         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1715                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1716         endif()
1717
1718         if(WITH_LIBS10.5)
1719                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1720         else()
1721                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1722                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1723                 else()
1724                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1725                 endif()
1726         endif()
1727
1728
1729         if(WITH_OPENAL)
1730                 find_package(OpenAL)
1731                 if(OPENAL_FOUND)
1732                         set(WITH_OPENAL ON)
1733                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1734                 else()
1735                         set(WITH_OPENAL OFF)
1736                 endif()
1737         endif()
1738
1739         if(WITH_JACK)
1740                 find_library(JACK_FRAMEWORK
1741                         NAMES jackmp
1742                 )
1743                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1744                 if(NOT JACK_FRAMEWORK)
1745                         set(WITH_JACK OFF)
1746                 endif()
1747         endif()
1748
1749         if(WITH_CODEC_SNDFILE)
1750                 set(SNDFILE ${LIBDIR}/sndfile)
1751                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1752                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1753                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1754         endif()
1755
1756         if(WITH_PYTHON)
1757                 # we use precompiled libraries for py 3.4 and up by default
1758                 set(PYTHON_VERSION 3.4)
1759                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1760                         # normally cached but not since we include them with blender
1761                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1762                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1763                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1764                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1765                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1766                 else()
1767                         # module must be compiled against Python framework
1768                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1769                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1770                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1771                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1772                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1773                 endif()
1774                 
1775                 # uncached vars
1776                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1777                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1778         endif()
1779
1780         if(WITH_FFTW3)
1781                 set(FFTW3 ${LIBDIR}/fftw3)
1782                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1783                 set(FFTW3_LIBRARIES fftw3)
1784                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1785         endif()
1786
1787         set(PNG_LIBRARIES png)
1788         set(JPEG_LIBRARIES jpeg)
1789
1790         set(ZLIB /usr)
1791         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1792         set(ZLIB_LIBRARIES z bz2)
1793
1794         set(FREETYPE ${LIBDIR}/freetype)
1795         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1796         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1797         set(FREETYPE_LIBRARY freetype)
1798
1799         if(WITH_IMAGE_OPENEXR)
1800                 set(OPENEXR ${LIBDIR}/openexr)
1801                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1802                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1803                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1804                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1805         endif()
1806
1807         if(WITH_CODEC_FFMPEG)
1808                 set(FFMPEG ${LIBDIR}/ffmpeg)
1809                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1810                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1811                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1812         endif()
1813
1814         find_library(SYSTEMSTUBS_LIBRARY
1815                 NAMES
1816                 SystemStubs
1817                 PATHS
1818         )
1819         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1820         if(SYSTEMSTUBS_LIBRARY)
1821                 list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
1822         else()
1823                 list(APPEND PLATFORM_LINKLIBS stdc++)
1824         endif()
1825
1826         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1827         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1828         if(WITH_CODEC_QUICKTIME)
1829                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1830                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1831                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1832                         # libSDL still needs 32bit carbon quicktime
1833                 endif()
1834         endif()
1835
1836         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1837         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1838         if(WITH_INPUT_NDOF)
1839                 # This thread it *should* work and check the framework - campbell
1840                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1841                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1842                         NAMES 3DconnexionClient
1843                 )
1844                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1845                         set(WITH_INPUT_NDOF OFF)
1846                 endif()
1847
1848                 if(WITH_INPUT_NDOF)
1849                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1850                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1851                 endif()
1852         endif()
1853
1854         if(WITH_JACK)
1855                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1856         endif()
1857         
1858         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1859                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1860         endif()
1861         
1862         if(WITH_OPENCOLLADA)
1863                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1864
1865                 set(OPENCOLLADA_INCLUDE_DIRS
1866                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1867                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1868                         ${LIBDIR}/opencollada/include/COLLADAFramework
1869                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1870                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1871                 )
1872
1873                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1874                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
1875                 # Use UTF functions from collada if LLVM is not enabled
1876                 if(NOT WITH_LLVM)
1877                         set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
1878                 endif()
1879                 # pcre is bundled with openCollada
1880                 #set(PCRE ${LIBDIR}/pcre)
1881                 #set(PCRE_LIBPATH ${PCRE}/lib)
1882                 set(PCRE_LIBRARIES pcre)
1883                 #libxml2 is used
1884                 #set(EXPAT ${LIBDIR}/expat)
1885                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1886                 set(EXPAT_LIB)
1887         endif()
1888
1889         if(WITH_SDL)
1890                 set(SDL ${LIBDIR}/sdl)
1891                 set(SDL_INCLUDE_DIR ${SDL}/include)
1892                 set(SDL_LIBRARY SDL)
1893                 set(SDL_LIBPATH ${SDL}/lib)
1894         endif()
1895
1896         set(PNG "${LIBDIR}/png")
1897         set(PNG_INCLUDE_DIRS "${PNG}/include")
1898         set(PNG_LIBPATH ${PNG}/lib)
1899
1900         set(JPEG "${LIBDIR}/jpeg")
1901         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1902         set(JPEG_LIBPATH ${JPEG}/lib)
1903
1904         if(WITH_IMAGE_TIFF)
1905                 set(TIFF ${LIBDIR}/tiff)
1906                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1907                 set(TIFF_LIBRARY tiff)
1908                 set(TIFF_LIBPATH ${TIFF}/lib)
1909         endif()
1910
1911         if(WITH_INPUT_NDOF)
1912                 # linker needs "-weak_framework 3DconnexionClient"
1913         endif()
1914
1915         if(WITH_BOOST)
1916                 set(BOOST ${LIBDIR}/boost)
1917                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1918                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1919                 if(WITH_INTERNATIONAL)
1920                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1921                 endif()
1922                 if(WITH_CYCLES_NETWORK)
1923                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
1924                 endif()
1925                 set(BOOST_LIBPATH ${BOOST}/lib)
1926                 set(BOOST_DEFINITIONS)
1927         endif()
1928         
1929         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
1930                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
1931         endif()
1932
1933         if(WITH_OPENIMAGEIO)
1934                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1935                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1936                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1937                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1938                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1939         endif()
1940
1941         if(WITH_OPENCOLORIO)
1942                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1943                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1944                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1945                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1946                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1947         endif()
1948
1949         if(WITH_LLVM)
1950                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1951                 set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
1952                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1953                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1954                 else()
1955                         set(LLVM_CONFIG llvm-config)
1956                 endif()
1957                 execute_process(COMMAND ${LLVM_CONFIG} --version
1958                                 OUTPUT_VARIABLE LLVM_VERSION
1959                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1960                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1961                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1962                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1963                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1964                                 OUTPUT_VARIABLE LLVM_LIBPATH
1965                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1966                 find_library(LLVM_LIBRARY
1967                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1968                              PATHS ${LLVM_LIBPATH})
1969
1970                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
1971                         if(LLVM_STATIC)
1972                                 # if static LLVM libraries were requested, use llvm-config to generate
1973                                 # the list of what libraries we need, and substitute that in the right
1974                                 # way for LLVM_LIBRARY.
1975                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1976                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1977                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1978                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1979                         else()
1980                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
1981                         endif()
1982                 else()
1983                         message(FATAL_ERROR "LLVM not found.")
1984                 endif()
1985         endif()
1986
1987         if(WITH_CYCLES_OSL)
1988                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1989         
1990                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1991                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1992                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1993                 # WARNING! depends on correct order of OSL libs linking
1994                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1995                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1996                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1997         
1998                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1999                         set(OSL_FOUND TRUE)
2000                 else()
2001                         message(STATUS "OSL not found")
2002                 endif()
2003         endif()
2004         
2005         if(WITH_OPENMP)
2006                 execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
2007                 string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
2008                 if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
2009                         set(WITH_OPENMP OFF)
2010                 else() # vanilla gcc or clang_omp support OpenMP
2011                         message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
2012                         if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
2013                                 set(OPENMP_FOUND ON)
2014                                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
2015                                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
2016                                 include_directories(${LIBDIR}/openmp/include)
2017                                 link_directories(${LIBDIR}/openmp/lib)
2018                                 # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
2019                                 # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
2020                                 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
2021                         endif()
2022                 endif()
2023         endif()
2024
2025         set(EXETYPE MACOSX_BUNDLE)
2026
2027         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
2028         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
2029         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
2030                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
2031                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
2032                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
2033                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2034                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2035                 endif()
2036         else()
2037                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2038                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2039         endif()
2040
2041         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
2042                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
2043                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
2044         endif()
2045         # Get rid of eventually clashes, we export some symbols explicite as local
2046         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
2047 endif()
2048
2049 #-----------------------------------------------------------------------------
2050 # Common.
2051
2052 if(APPLE OR WIN32)
2053         if(NOT EXISTS "${LIBDIR}/")
2054                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
2055         endif()
2056 endif()
2057
2058 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
2059         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
2060 endif()
2061
2062 if(WITH_CYCLES)
2063         if(NOT WITH_OPENIMAGEIO)
2064                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
2065         endif()
2066         if(NOT WITH_BOOST)
2067                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
2068         endif()
2069
2070         if(WITH_CYCLES_OSL)
2071                 if(NOT WITH_LLVM)
2072                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
2073                 endif()
2074         endif()
2075 endif()
2076
2077 if(WITH_INTERNATIONAL)
2078         if(NOT WITH_BOOST)
2079                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
2080         endif()
2081 endif()
2082
2083 # See TEST_SSE_SUPPORT() for how this is defined.
2084
2085 if(WITH_RAYOPTIMIZATION)
2086         if(SUPPORT_SSE_BUILD)
2087                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
2088                 add_definitions(-D__SSE__ -D__MMX__)
2089         endif()
2090         if(SUPPORT_SSE2_BUILD)
2091                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
2092                 add_definitions(-D__SSE2__)
2093                 if(NOT SUPPORT_SSE_BUILD) # dont double up
2094                         add_definitions(-D__MMX__)
2095                 endif()
2096         endif()
2097 endif()
2098
2099
2100 # set the endian define
2101 if(MSVC)
2102         # for some reason this fails on msvc
2103         add_definitions(-D__LITTLE_ENDIAN__)
2104         
2105 # OSX-Note: as we do crosscompiling with specific set architecture,
2106 # endianess-detection and autosetting is counterproductive
2107 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
2108
2109 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
2110         add_definitions(-D__LITTLE_ENDIAN__)
2111 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
2112         add_definitions(-D__BIG_ENDIAN__)
2113         
2114 else()
2115         include(TestBigEndian)
2116         test_big_endian(_SYSTEM_BIG_ENDIAN)
2117         if(_SYSTEM_BIG_ENDIAN)
2118                 add_definitions(-D__BIG_ENDIAN__)
2119         else()
2120                 add_definitions(-D__LITTLE_ENDIAN__)
2121         endif()
2122         unset(_SYSTEM_BIG_ENDIAN)
2123 endif()
2124
2125
2126 if(WITH_IMAGE_OPENJPEG)
2127         if(WITH_SYSTEM_OPENJPEG)
2128                 # dealt with above
2129         else()
2130                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2131                 add_definitions(-DOPJ_STATIC)
2132         endif()
2133 endif()
2134
2135 if(WITH_IMAGE_REDCODE)
2136         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2137         set(REDCODE_INC ${REDCODE})
2138 endif()
2139
2140
2141 #-----------------------------------------------------------------------------
2142 # Configure OpenGL.
2143
2144 find_package(OpenGL)
2145 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2146
2147 if(WITH_GLU)
2148         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
2149         list(APPEND GL_DEFINITIONS -DWITH_GLU)
2150 endif()
2151
2152 if(WITH_SYSTEM_GLES)
2153         find_package_wrapper(OpenGLES)
2154 endif()
2155
2156 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
2157         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
2158
2159 elseif(WITH_GL_PROFILE_ES20)
2160         if(WITH_SYSTEM_GLES)
2161                 if(NOT OPENGLES_LIBRARY)
2162                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2163                 endif()
2164
2165                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
2166
2167         else()
2168                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
2169                 mark_as_advanced(OPENGLES_LIBRARY)
2170
2171                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
2172
2173                 if(NOT OPENGLES_LIBRARY)
2174                         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.")
2175                 endif()
2176
2177         endif()
2178
2179         if(WIN32)
2180                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2181
2182                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
2183                 mark_as_advanced(OPENGLES_DLL)
2184
2185                 if(NOT OPENGLES_DLL)
2186                         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).")
2187                 endif()
2188
2189                 if(WITH_GL_ANGLE)
2190                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
2191
2192                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
2193
2194                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
2195                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
2196
2197                         mark_as_advanced(D3DCOMPILER_DLL)
2198
2199                         if(D3DCOMPILER_DLL STREQUAL "")
2200                                 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")
2201                         endif()
2202
2203                 endif()
2204
2205         endif()
2206
2207 endif()
2208
2209 if(WITH_GL_EGL)
2210         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
2211
2212         if(WITH_SYSTEM_GLES)
2213                 if(NOT OPENGLES_EGL_LIBRARY)
2214                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2215                 endif()
2216
2217                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
2218
2219         else()
2220                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
2221                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
2222
2223                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
2224
2225                 if(NOT OPENGLES_EGL_LIBRARY)
2226                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
2227                 endif()
2228
2229         endif()
2230
2231         if(WIN32)
2232                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2233
2234                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
2235                 mark_as_advanced(OPENGLES_EGL_DLL)
2236
2237                 if(NOT OPENGLES_EGL_DLL)
2238                         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).")
2239                 endif()
2240
2241         endif()
2242
2243 endif()
2244
2245 if(WITH_GL_PROFILE_COMPAT)
2246         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
2247 endif()
2248
2249 if(WITH_GL_PROFILE_CORE)
2250         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
2251 endif()
2252
2253 if(WITH_GL_PROFILE_ES20)
2254         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
2255 endif()
2256
2257 if(WITH_GL_EGL)
2258         list(APPEND GL_DEFINITIONS -DWITH_EGL)
2259 endif()
2260
2261 #-----------------------------------------------------------------------------
2262 # Configure OpenMP.
2263 if(WITH_OPENMP)
2264         find_package(OpenMP)
2265         if(OPENMP_FOUND)
2266                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2267                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2268         else()
2269                 set(WITH_OPENMP OFF)
2270         endif()
2271
2272         mark_as_advanced(
2273                 OpenMP_C_FLAGS
2274                 OpenMP_CXX_FLAGS
2275         )
2276 endif()
2277
2278 #-----------------------------------------------------------------------------
2279 # Configure GLEW
2280
2281 if(WITH_GLEW_MX)
2282         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
2283 endif()
2284
2285 if(WITH_SYSTEM_GLEW)
2286         find_package(GLEW)
2287
2288         # Note: There is an assumption here that the system GLEW is not a static library.
2289
2290         if(NOT GLEW_FOUND)
2291                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
2292         endif()
2293
2294         if(WITH_GLEW_MX)
2295                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
2296         else()
2297                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
2298         endif()
2299 else()
2300         if(WITH_GLEW_ES)
2301                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
2302
2303                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
2304
2305                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
2306                 if(NOT WITH_GL_PROFILE_ES20)
2307                         # No ES functions are needed
2308                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2309                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
2310                         # ES is enabled, but the other functions are all disabled
2311                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
2312                 endif()
2313
2314                 if(WITH_GL_PROFILE_ES20)
2315                         if(WITH_GL_EGL)
2316                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
2317                         endif()
2318
2319                         # ToDo: This is an experiment to eliminate ES 1 symbols,
2320                         # GLEW doesn't really properly provide this level of control
2321                         # (for example, without modification it eliminates too many symbols)
2322                         # so there are lots of modifications to GLEW to make this work,
2323                         # and no attempt to make it work beyond Blender at this point.
2324                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
2325                 endif()
2326
2327                 if(WITH_GL_EGL)
2328                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
2329                 endif()
2330
2331                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
2332
2333         else()
2334                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2335
2336                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
2337
2338                 # This won't affect the non-experimental glew library, 
2339                 # but is used for conditional compilation elsewhere.
2340                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2341
2342                 set(BLENDER_GLEW_LIBRARIES extern_glew)
2343
2344         endif()
2345
2346 endif()
2347
2348 if(NOT WITH_GLU)
2349         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
2350 endif()
2351
2352 #-----------------------------------------------------------------------------
2353 # Configure Bullet
2354
2355 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2356         find_package(Bullet)
2357         if(NOT BULLET_FOUND)
2358                 set(WITH_BULLET OFF)
2359         endif()
2360 else()
2361         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2362         # set(BULLET_LIBRARIES "")
2363 endif()
2364
2365 #-----------------------------------------------------------------------------
2366 # Configure Python.
2367
2368 if(WITH_PYTHON_MODULE)
2369         add_definitions(-DPy_ENABLE_SHARED)
2370 endif()
2371
2372 #-----------------------------------------------------------------------------
2373 # Extra compile flags
2374
2375 if(CMAKE_COMPILER_IS_GNUCC)
2376
2377         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2378         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2379         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2380         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2381         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2382         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2383         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2384         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2385         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2386         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2387         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2388         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2389         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2390         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2391         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2392         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2393         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2394         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2395         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2396         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2397
2398         # gcc 4.2 gives annoying warnings on every file with this
2399         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2400                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2401         endif()
2402
2403         # versions before gcc4.6 give many BLI_math warnings
2404         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2405                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2406                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2407         endif()
2408
2409         # disable because it gives warnings for printf() & friends.
2410         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2411
2412         if(NOT APPLE)
2413                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2414         endif()
2415
2416         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2417         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2418         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2419         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2420         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2421         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2422         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2423         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2424
2425         # gcc 4.2 gives annoying warnings on every file with this
2426         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2427                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2428         endif()
2429
2430         # causes too many warnings
2431         if(NOT APPLE)
2432                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2433                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2434         endif()
2435
2436         # flags to undo strict flags
2437         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2438         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2439
2440         if(NOT APPLE)
2441                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2442         endif()
2443
2444 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2445
2446         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
2447                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
2448         endif()
2449
2450         # strange, clang complains these are not supported, but then yses them.
2451         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2452         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2453         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2454         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2455         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2456         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2457         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2458         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2459         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2460         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2461
2462         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2463         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2464         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2465         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2466         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.
2467         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2468         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2469
2470         # gives too many unfixable warnings
2471         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2472         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2473
2474         # flags to undo strict flags
2475         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2476         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2477
2478         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2479         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2480         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2481         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2482         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2483         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2484         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2485         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2486
2487         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2488         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2489         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2490         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2491         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2492
2493 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2494
2495         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2496         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2497         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2498
2499         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2500         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2501         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2502
2503         # disable numbered, false positives
2504         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2505         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2506 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
2507         # most msvc warnings are C & C++
2508         set(_WARNINGS
2509                 # warning level:
2510                 "/W3"
2511                 "/w34062"  # switch statement contains 'default' but no 'case' labels
2512                 # disable:
2513                 "/wd4018"  # signed/unsigned mismatch
2514                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
2515                 "/wd4127"  # conditional expression is constant
2516                 "/wd4181"  # qualifier applied to reference type; ignored
2517                 "/wd4200"  # zero-sized array in struct/union
2518                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
2519                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
2520                 "/wd4305"  # truncation from 'type1' to 'type2'
2521                 "/wd4800"  # forcing value to bool 'true' or 'false'
2522                 # errors:
2523                 "/we4013"  # 'function' undefined; assuming extern returning int
2524                 "/we4431"  # missing type specifier - int assumed
2525         )
2526
2527         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
2528         set(C_WARNINGS "${_WARNINGS}")
2529         set(CXX_WARNINGS "${_WARNINGS}")
2530         unset(_WARNINGS)
2531 endif()
2532
2533 # ensure python header is found since detection can fail, this could happen
2534 # with _any_ library but since we used a fixed python version this tends to
2535 # be most problematic.
2536 if(WITH_PYTHON)
2537         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2538                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2539                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2540                                                         "to a valid python include path. Containing "
2541                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2542         endif()
2543
2544         if(WIN32)
2545                 # pass, we have this in an archive to extract
2546         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2547                 find_python_package(numpy)
2548         endif()
2549
2550         if(WIN32 OR APPLE)
2551                 # pass, we have this in lib/python/site-packages
2552         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2553                 find_python_package(requests)
2554         endif()
2555 endif()
2556
2557 if(WITH_GCC_MUDFLAP)
2558         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2559         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2560         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2561         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2562 endif()
2563
2564 # Include warnings first, so its possible to disable them with user defined flags
2565 # eg: -Wno-uninitialized
2566 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2567 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2568
2569 # defined above, platform spesific but shared names
2570 mark_as_advanced(
2571         CYCLES_OSL
2572         OSL_LIB_EXEC
2573         OSL_COMPILER
2574         OSL_LIB_COMP
2575         OSL_LIB_QUERY
2576         OSL_INCLUDES
2577 )
2578
2579 mark_as_advanced(
2580         LLVM_CONFIG
2581         LLVM_DIRECTORY
2582         LLVM_LIBRARY
2583         LLVM_VERSION
2584 )
2585
2586 #-------------------------------------------------------------------------------
2587 # Global Defines
2588
2589 # better not set includes here but this debugging option is off by default.
2590 if(WITH_CXX_GUARDEDALLOC)
2591         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2592         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2593 endif()
2594
2595 if(WITH_ASSERT_ABORT)
2596         add_definitions(-DWITH_ASSERT_ABORT)
2597 endif()
2598
2599 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2600 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2601
2602 #-----------------------------------------------------------------------------
2603 # Libraries
2604
2605 if(WITH_GTESTS)
2606         include(GTestTesting)
2607 endif()
2608
2609 if(WITH_BLENDER OR WITH_PLAYER)
2610         add_subdirectory(intern)
2611         add_subdirectory(extern)
2612
2613         # source after intern and extern to gather all
2614         # internal and external library information first, for test linking
2615         add_subdirectory(source)
2616 elseif(WITH_CYCLES_STANDALONE)
2617         add_subdirectory(intern/cycles)
2618         add_subdirectory(extern/clew)
2619         add_subdirectory(extern/cuew)
2620         if(NOT WITH_SYSTEM_GLEW)
2621                 add_subdirectory(extern/glew)
2622         endif()
2623 endif()
2624
2625 #-----------------------------------------------------------------------------
2626 # Blender Application
2627 if(WITH_BLENDER)
2628         add_subdirectory(source/creator)
2629 endif()
2630
2631
2632 #-----------------------------------------------------------------------------
2633 # Blender Player
2634 if(WITH_PLAYER)
2635         add_subdirectory(source/blenderplayer)
2636 endif()
2637
2638
2639 #-----------------------------------------------------------------------------
2640 # Testing
2641 add_subdirectory(tests)
2642
2643
2644 #-----------------------------------------------------------------------------
2645 # CPack for generating packages
2646 include(build_files/cmake/packaging.cmake)
2647
2648
2649 #-----------------------------------------------------------------------------
2650 # Print Final Configuration
2651
2652 if(FIRST_RUN)
2653         set(_config_msg "\n* Blender Configuration *")
2654         macro(info_cfg_option
2655                 _setting)
2656                 set(_msg "   * ${_setting}")
2657                 string(LENGTH "${_msg}" _len)
2658                 while("32" GREATER "${_len}")
2659                         set(_msg "${_msg} ")
2660                          math(EXPR _len "${_len} + 1")
2661                 endwhile()
2662
2663                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2664         endmacro()
2665
2666         macro(info_cfg_text
2667                 _text)
2668                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2669
2670
2671         endmacro()
2672
2673         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2674         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2675
2676         info_cfg_text("Build Options:")
2677         info_cfg_option(WITH_GAMEENGINE)
2678         info_cfg_option(WITH_PLAYER)
2679         info_cfg_option(WITH_BULLET)
2680         info_cfg_option(WITH_IK_SOLVER)
2681         info_cfg_option(WITH_IK_ITASC)
2682         info_cfg_option(WITH_OPENCOLLADA)
2683         info_cfg_option(WITH_FFTW3)
2684         info_cfg_option(WITH_INTERNATIONAL)
2685         info_cfg_option(WITH_INPUT_NDOF)
2686         info_cfg_option(WITH_CYCLES)
2687         info_cfg_option(WITH_FREESTYLE)
2688         info_cfg_option(WITH_OPENCOLORIO)
2689
2690         info_cfg_text("Compiler Options:")
2691         info_cfg_option(WITH_BUILDINFO)
2692         info_cfg_option(WITH_OPENMP)
2693         info_cfg_option(WITH_RAYOPTIMIZATION)
2694
2695         info_cfg_text("System Options:")
2696         info_cfg_option(WITH_INSTALL_PORTABLE)
2697         info_cfg_option(WITH_X11_XF86VMODE)
2698         info_cfg_option(WITH_X11_XINPUT)
2699         info_cfg_option(WITH_MEM_JEMALLOC)
2700         info_cfg_option(WITH_MEM_VALGRIND)
2701         info_cfg_option(WITH_SYSTEM_GLEW)
2702         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2703
2704         info_cfg_text("Image Formats:")
2705         info_cfg_option(WITH_OPENIMAGEIO)
2706         info_cfg_option(WITH_IMAGE_CINEON)
2707         info_cfg_option(WITH_IMAGE_DDS)
2708         info_cfg_option(WITH_IMAGE_HDR)
2709         info_cfg_option(WITH_IMAGE_OPENEXR)
2710         info_cfg_option(WITH_IMAGE_OPENJPEG)
2711         info_cfg_option(WITH_IMAGE_REDCODE)
2712         info_cfg_option(WITH_IMAGE_TIFF)
2713
2714         info_cfg_text("Audio:")
2715         info_cfg_option(WITH_OPENAL)
2716         info_cfg_option(WITH_SDL)
2717         info_cfg_option(WITH_JACK)
2718         info_cfg_option(WITH_JACK_DYNLOAD)
2719         info_cfg_option(WITH_CODEC_AVI)
2720         info_cfg_option(WITH_CODEC_FFMPEG)
2721         info_cfg_option(WITH_CODEC_SNDFILE)
2722
2723         info_cfg_text("Compression:")
2724         info_cfg_option(WITH_LZMA)
2725         info_cfg_option(WITH_LZO)
2726
2727         info_cfg_text("Python:")
2728         info_cfg_option(WITH_PYTHON_INSTALL)
2729         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2730         info_cfg_option(WITH_PYTHON_MODULE)
2731         info_cfg_option(WITH_PYTHON_SAFETY)
2732         if(APPLE)
2733                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2734         endif()
2735
2736         info_cfg_text("Modifiers:")
2737         info_cfg_option(WITH_MOD_BOOLEAN)
2738         info_cfg_option(WITH_MOD_REMESH)
2739         info_cfg_option(WITH_MOD_FLUID)
2740         info_cfg_option(WITH_MOD_OCEANSIM)
2741
2742         info_cfg_text("OpenGL:")
2743         info_cfg_option(WITH_GLEW_ES)
2744         info_cfg_option(WITH_GLU)
2745         info_cfg_option(WITH_GL_EGL)
2746         info_cfg_option(WITH_GL_PROFILE_COMPAT)
2747         info_cfg_option(WITH_GL_PROFILE_CORE)
2748         info_cfg_option(WITH_GL_PROFILE_ES20)
2749         if(WIN32)
2750                 info_cfg_option(WITH_GL_ANGLE)
2751         endif()
2752
2753         info_cfg_text("Other:")
2754         info_cfg_option(WITH_OPENNL)
2755
2756         # debug
2757         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2758
2759         info_cfg_text("")
2760
2761         message("${_config_msg}")
2762 endif()