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