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