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