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