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