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