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