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