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