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