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