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