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