Cycles OSL: some build system tweaks to avoid global includes and definitions,
[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 (recommend to leave off)" OFF)
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
125 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)
126 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)
127 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
128 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
129 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
130 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" OFF)
131 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
132 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
133 option(WITH_PLAYER        "Build Player" OFF)
134 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
135 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
136 option(WITH_COMPOSITOR_LEGACY "Enable legacy compositor" OFF)
137
138 # GHOST Windowing Library Options
139 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
140 mark_as_advanced(WITH_GHOST_DEBUG)
141
142 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
143 mark_as_advanced(WITH_GHOST_SDL)
144
145 # Misc...
146 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
147 mark_as_advanced(WITH_HEADLESS)
148
149 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
150 mark_as_advanced(WITH_AUDASPACE)
151
152
153 # (unix defaults to OpenMP On)
154 if((UNIX AND NOT APPLE) OR (MINGW))
155         set(PLATFORM_DEFAULT ON)
156 else()
157         set(PLATFORM_DEFAULT OFF)
158 endif()
159 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ${PLATFORM_DEFAULT})
160 unset(PLATFORM_DEFAULT)
161
162
163 if(UNIX AND NOT APPLE)
164         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
165         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
166         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
167
168         # freebsd doesn't seems to support XDND
169         if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
170                 option(WITH_GHOST_XDND   "Enable drag'n'drop support on Linux using XDND protocol" ON)
171         endif()
172 else()
173         # not an option for other OS's
174         set(WITH_SYSTEM_GLEW OFF)
175 endif()
176
177
178 # (unix defaults to System OpenJPEG On)
179 if(UNIX AND NOT APPLE)
180         set(PLATFORM_DEFAULT ON)
181 else()
182         set(PLATFORM_DEFAULT OFF)
183 endif()
184 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
185 unset(PLATFORM_DEFAULT)
186
187
188 # Modifiers
189 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
190 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
191 option(WITH_MOD_DECIMATE        "Enable Decimate Modifier" ON)
192 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
193 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
194 option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)
195 mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
196 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
197
198 # Image format support
199 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
200 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
201 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
202 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
203 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
204 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
205 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
206 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
207
208 # Audio/Video format support
209 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
210 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
211
212 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
213 if(APPLE OR (WIN32 AND NOT UNIX))
214         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
215 endif()
216
217 # 3D format support
218 # disable opencollada on non-apple unix because opencollada has no package for debian
219 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
220
221 # Sound output
222 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
223 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
224 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
225
226 # Compression
227 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
228 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
229
230 # Camera/motion tracking
231 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
232
233 # Misc
234 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
235 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
236 if(UNIX AND NOT APPLE)
237         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
238 endif()
239 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
240 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
241 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Python to python site-packages or dist-packages containing 'numpy' module")
242 mark_as_advanced(PYTHON_NUMPY_PATH)
243
244 if(MINGW)
245         option(WITH_MINGW64                   "Use the 64-bit version of MinGW" OFF)
246         mark_as_advanced(WITH_MINGW64)
247 endif()
248
249 # Cycles
250 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
251 option(WITH_CYCLES_TEST                         "Build cycles test application" OFF)
252 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
253 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
254 set(CYCLES_CUDA_BINARIES_ARCH sm_13 sm_20 sm_21 sm_30 CACHE STRING "CUDA architectures to build binaries for")
255 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
256 unset(PLATFORM_DEFAULT)
257
258 # LLVM
259 option(WITH_LLVM                                        "Use LLVM" OFF)
260
261 # disable for now, but plan to support on all platforms eventually
262 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
263 mark_as_advanced(WITH_MEM_JEMALLOC)
264
265 # Debug
266 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
267 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
268
269 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
270 mark_as_advanced(WITH_ASSERT_ABORT)
271
272
273 if(APPLE)
274         if(NOT CMAKE_OSX_ARCHITECTURES)
275                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
276                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
277                 FORCE)
278         endif()
279         
280         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
281         if (${MAC_SYS} MATCHES 12)
282                 set(OSX_SYSTEM 10.8)
283         elseif (${MAC_SYS} MATCHES 11)
284                 set(OSX_SYSTEM 10.7)
285         elseif(${MAC_SYS} MATCHES 10)
286                 set(OSX_SYSTEM 10.6)
287         elseif(${MAC_SYS} MATCHES 9)
288                 set(OSX_SYSTEM 10.5)
289         else()
290                 set(OSX_SYSTEM unsupported)
291         endif()
292         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
293         
294         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
295                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our minimum target, if you have higher sdk, weak linking happens
296         endif()
297
298         if(${CMAKE_GENERATOR} MATCHES "Xcode")
299         
300                 ##### workaround for actual official cmake incompatibility with xcode 4.3 ##### 
301                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
302                         message("Official cmake does not yet support Xcode 4.3, get a patched version here: http://www.jensverwiebe.de/Blender/CMake%202.8-7patched.zip")
303                 endif()
304                 ### end workaround for actual official cmake incompatibility with xcode 4.3 ### 
305                 
306                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
307                         # Xcode 4 defaults to the Apple LLVM Compiler.
308                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
309                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
310                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
311                 endif()
312         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
313                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
314                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
315                 unset(XCODE_VERS_BUILD_NR)
316         endif()
317         
318         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
319         
320         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
321         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
322         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
323         if(CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
324                 set(USE_QTKIT ON CACHE BOOL "ON" FORCE) # no Quicktime in 64bit
325         endif()
326 endif()
327
328
329 #-----------------------------------------------------------------------------
330 # Check for conflicting/unsupported configurations
331
332 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_TEST)
333         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
334 endif()
335
336 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
337         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
338 endif()
339
340 if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK OR WITH_GAMEENGINE))
341         message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG/WITH_GAMEENGINE require WITH_AUDASPACE")
342 endif()
343
344 if(NOT WITH_SDL AND WITH_GHOST_SDL)
345         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL to be ON")
346 endif()
347
348 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
349         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
350 endif()
351
352 # python module, needs some different options
353 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
354         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
355 endif()
356
357 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
358         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
359 endif()
360
361
362 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
363         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
364 endif()
365
366 # may as well build python module without a UI
367 if(WITH_PYTHON_MODULE)
368         set(WITH_HEADLESS ON)
369 endif()
370
371 # auto enable openimageio for cycles
372 if(WITH_CYCLES)
373         set(WITH_OPENIMAGEIO ON)
374 endif()
375
376 # auto enable boost for cycles and booleans
377 if(WITH_CYCLES OR WITH_MOD_BOOLEAN)
378         set(WITH_BOOST ON)
379 endif()
380
381 # auto enable llvm for cycles_osl
382 if(WITH_CYCLES_OSL)
383         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
384 endif()
385
386 # don't store paths to libs for portable distribution
387 if(WITH_INSTALL_PORTABLE)
388         set(CMAKE_SKIP_BUILD_RPATH TRUE)
389 endif()
390
391 if(WITH_GHOST_SDL OR WITH_HEADLESS)
392         set(WITH_GHOST_XDND OFF)
393         set(WITH_X11_XF86VMODE OFF)
394         set(WITH_X11_XINPUT OFF)
395 endif()
396
397 if(MINGW)
398         if(WITH_CODEC_QUICKTIME)
399                 message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
400                                     "because it is currently unsupported, remove this "
401                                     "line if youre a developer who wants to add support.")
402         endif()
403 endif()
404
405 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
406
407
408 #-----------------------------------------------------------------------------
409 # Check for valid directories
410 # ... svn extern paths can be missing because of svn-git.
411
412 if(WITH_INTERNATIONAL)
413         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
414                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
415                                                 "This is an 'svn external', which are known not to work with bridges to other version "
416                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
417                 set(WITH_INTERNATIONAL OFF)
418         endif()
419 endif()
420
421 if(WITH_PYTHON)
422         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons")
423                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
424                                                 "This is an 'svn external', which are known not to work with bridges to other version "
425                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
426         endif()
427 endif()
428
429 #-----------------------------------------------------------------------------
430 # Initialize un-cached vars, avoid unused warning
431
432 # linux only, not cached
433 set(WITH_BINRELOC OFF)
434
435 # MAXOSX only, set to avoid uninitialized
436 set(EXETYPE "")
437
438 # C/C++ flags
439 set(PLATFORM_CFLAGS)
440
441 # these are added to later on.
442 set(C_WARNINGS)
443 set(CXX_WARNINGS)
444
445 # for gcc -Wno-blah-blah
446 set(CC_REMOVE_STRICT_FLAGS)
447
448 # libraries to link the binary with passed to target_link_libraries()
449 # known as LLIBS to scons
450 set(PLATFORM_LINKLIBS "")
451
452 # Added to linker flags in setup_liblinks
453 # - CMAKE_EXE_LINKER_FLAGS
454 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
455 set(PLATFORM_LINKFLAGS "")
456 set(PLATFORM_LINKFLAGS_DEBUG "")
457
458
459 # disabled for now, not supported
460 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
461
462 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
463 # On Unix:
464 #   cmake ../blender \
465 #         -D PYTHON_VERSION=3.2 \
466 #         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
467 #         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
468 #
469 # On Macs:
470 #   cmake ../blender \
471 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
472 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
473 #         -G Xcode
474 #
475 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
476
477 #-----------------------------------------------------------------------------
478 #Platform specifics
479
480 if(UNIX AND NOT APPLE)
481
482         # set lib directory if it exists
483         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
484                 if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
485                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux64)
486                 else()
487                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/linux)
488                 endif()
489
490                 if(NOT EXISTS ${LIBDIR})
491                         unset(LIBDIR)
492                 endif()
493         endif()
494
495         find_package(JPEG REQUIRED)
496         find_package(PNG REQUIRED)
497         find_package(ZLIB REQUIRED)
498         find_package(Freetype REQUIRED)
499
500         if(WITH_PYTHON)
501                 # No way to set py32. remove for now.
502                 # find_package(PythonLibs)
503
504                 # Use our own instead, since wothout py is such a rare case,
505                 # require this package
506                 find_package(PythonLibsUnix REQUIRED)
507         endif()
508
509
510         if(WITH_IMAGE_OPENEXR)
511                 find_package(OpenEXR)  # our own module
512                 if(NOT OPENEXR_FOUND)
513                         set(WITH_IMAGE_OPENEXR OFF)
514                 endif()
515         endif()
516
517         if(WITH_IMAGE_OPENJPEG)
518                 find_package(OpenJPEG)
519                 if(NOT OPENJPEG_FOUND)
520                         set(WITH_IMAGE_OPENJPEG OFF)
521                 endif()
522         endif()
523
524         if(WITH_IMAGE_TIFF)
525                 find_package(TIFF)
526                 if(NOT TIFF_FOUND)
527                         set(WITH_IMAGE_TIFF OFF)
528                 endif()
529         endif()
530
531         # Audio IO
532         if(WITH_OPENAL)
533                 find_package(OpenAL)
534                 if(NOT OPENAL_FOUND)
535                         set(WITH_OPENAL OFF)
536                 endif()
537         endif()
538
539         if(WITH_SDL)
540                 find_package(SDL)
541                 mark_as_advanced(
542                         SDLMAIN_LIBRARY
543                         SDL_INCLUDE_DIR
544                         SDL_LIBRARY
545                         SDL_LIBRARY_TEMP
546                 )
547                 # unset(SDLMAIN_LIBRARY CACHE)
548                 if(NOT SDL_FOUND)
549                         set(WITH_SDL OFF)
550                 endif()
551         endif()
552
553         if(WITH_JACK)
554                 find_package(Jack)
555                 if(NOT JACK_FOUND)
556                         set(WITH_JACK OFF)
557                 endif()
558         endif()
559
560         # Codecs
561         if(WITH_CODEC_SNDFILE)
562                 find_package(SndFile)
563                 if(NOT SNDFILE_FOUND)
564                         set(WITH_CODEC_SNDFILE OFF)
565                 endif()
566         endif()
567
568         if(WITH_CODEC_FFMPEG)
569                 # use lib dir if available and nothing else specified
570                 if(LIBDIR AND NOT FFMPEG)
571                         set(FFMPEG ${LIBDIR}/ffmpeg CACHE PATH "FFMPEG Directory")
572                         # XXX, some distros might need 'theoraenc theoradec' too
573                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale dirac_encoder mp3lame ogg orc-0.4 schroedinger-1.0 theora vorbis vorbisenc vpx x264 xvidcore faad asound CACHE STRING "FFMPEG Libraries")
574                 else()
575                         set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
576                         set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
577                 endif()
578
579                 mark_as_advanced(FFMPEG)
580
581                 # lame, but until we have proper find module for ffmpeg
582                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
583                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
584                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
585                 endif()
586                 # end lameness
587
588                 mark_as_advanced(FFMPEG_LIBRARIES)
589                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
590                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
591         endif()
592
593         if(WITH_INTERNATIONAL)
594                 find_library(INTL_LIBRARY
595                         NAMES intl
596                         PATHS
597                         /sw/lib
598                 )
599
600                 find_library(ICONV_LIBRARY
601                         NAMES iconv
602                         PATHS
603                         /sw/lib
604                 )
605                 mark_as_advanced(
606                         ICONV_LIBRARY
607                         INTL_LIBRARY
608                 )
609
610                 if(INTL_LIBRARY AND ICONV_LIBRARY)
611                         set(GETTEXT_LIBRARIES ${INTL_LIBRARY} ${ICONV_LIBRARY})
612                 endif()
613         endif()
614
615         if(WITH_FFTW3)
616                 find_package(Fftw3)
617                 if(NOT FFTW3_FOUND)
618                         set(WITH_FFTW3 OFF)
619                 endif()
620         endif()
621
622         if(WITH_OPENCOLLADA)
623                 find_package(OpenCOLLADA)
624                 if(OPENCOLLADA_FOUND)
625                         find_package(XML2)
626                         find_package(PCRE)
627                 else()
628                         set(WITH_OPENCOLLADA OFF)
629                 endif()
630         endif()
631
632         if(WITH_MEM_JEMALLOC)
633                 find_package(JeMalloc)
634                 if(NOT JEMALLOC_FOUND)
635                         set(WITH_MEM_JEMALLOC OFF)
636                 endif()
637         endif()
638
639         if (WITH_INPUT_NDOF)
640                 find_package(Spacenav)
641                 if(NOT SPACENAV_FOUND)
642                         set(WITH_INPUT_NDOF OFF)
643                 endif()
644
645                 # use generic names within blenders buildsystem.
646                 if(SPACENAV_FOUND)
647                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
648                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
649                 endif()
650         endif()
651
652         if(WITH_BOOST)
653                 # uses in build instructions to override include and library variables
654                 if(NOT BOOST_CUSTOM)
655                         # use lib dir if available and nothing else specified
656                         if(LIBDIR AND NOT BOOST_ROOT)
657                                 set(BOOST_ROOT ${LIBDIR}/boost)
658                                 set(Boost_USE_MULTITHREADED OFF)
659                         else()
660                                 set(Boost_USE_MULTITHREADED ON)
661                         endif()
662                         if(WITH_CYCLES_OSL)
663                                 find_package(Boost 1.34 COMPONENTS filesystem python3 regex system thread) # osl_nodes uses boost_python
664                         else()
665                                 find_package(Boost 1.34 COMPONENTS filesystem regex system thread)
666                         endif()
667                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
668                 endif()
669
670                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
671                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
672                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
673                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
674         endif()
675
676         if(WITH_OPENIMAGEIO)
677                 # use lib dir if available and nothing else specified
678                 if(LIBDIR AND NOT OPENIMAGEIO_ROOT_DIR)
679                         set(OPENIMAGEIO_ROOT_DIR ${LIBDIR}/oiio)
680                 endif()
681
682                 find_package(OpenImageIO)
683
684                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
685                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
686                 set(OPENIMAGEIO_DEFINITIONS)
687
688                 if(WITH_IMAGE_TIFF)
689                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
690                 endif()
691                 if(WITH_IMAGE_OPENEXR)
692                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
693                 endif()
694
695                 if(NOT OPENIMAGEIO_FOUND)
696                         set(WITH_OPENIMAGEIO OFF)
697                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
698                 endif()
699         endif()
700
701         if(WITH_OPENCOLORIO)
702                 # use lib dir if available and nothing else specified
703                 if(LIBDIR AND NOT OPENCOLORIO_ROOT_DIR)
704                         set(OPENCOLORIO_ROOT_DIR ${LIBDIR}/ocio)
705                 endif()
706
707                 find_package(OpenColorIO)
708
709                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
710                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
711                 set(OPENCOLORIO_DEFINITIONS)
712
713                 if(NOT OPENCOLORIO_FOUND)
714                         set(WITH_OPENCOLORIO OFF)
715                         message(STATUS "OpenColorIO not found")
716                 endif()
717         endif()
718
719         if(WITH_LLVM)
720                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
721                 set(LLVM_VERSION "3.0" CACHE STRING     "Version of LLVM to use" "")
722                 set(LLVM_STATIC YES)
723                 if(LLVM_DIRECTORY)
724                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
725                 else()
726                         set(LLVM_CONFIG llvm-config)
727                 endif()
728                 execute_process(COMMAND ${LLVM_CONFIG} --version
729                                 OUTPUT_VARIABLE LLVM_VERSION
730                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
731                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
732                                 OUTPUT_VARIABLE LLVM_DIRECTORY
733                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
734                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
735                                 OUTPUT_VARIABLE LLVM_LIB_DIR
736                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
737                 find_library(LLVM_LIBRARY
738                              NAMES libLLVMAnalysis.a # first of a whole bunch of libs to get
739                              PATHS ${LLVM_LIB_DIR})
740                 message(STATUS "LLVM version  = ${LLVM_VERSION}")
741                 message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
742                 message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
743
744                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
745                         if(LLVM_STATIC)
746                                 # if static LLVM libraries were requested, use llvm-config to generate
747                                 # the list of what libraries we need, and substitute that in the right
748                                 # way for LLVM_LIBRARY.
749                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
750                                                 OUTPUT_VARIABLE LLVM_LIBRARY
751                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
752                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
753                         endif()
754                         message(STATUS "LLVM library  = ${LLVM_LIBRARY}")
755                 else()
756                         message(FATAL_ERROR "LLVM not found.")
757                 endif()
758         endif()
759
760         if(WITH_CYCLES_OSL)
761                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
762         
763                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
764         
765                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
766                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
767                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
768                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
769                 # otherwise LLVM is missing the osl_allocate_closure_component function
770                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
771                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
772                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
773         
774                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
775                         set(OSL_FOUND TRUE)
776                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
777                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
778                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
779                 else()
780                         message(STATUS "OSL not found")
781                 endif()
782         endif()
783
784         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
785         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
786
787         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
788                 find_package(X11 REQUIRED)
789                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
790                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
791
792                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
793
794                 if(WITH_X11_XINPUT)
795                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
796                 endif()
797
798                 if(WITH_X11_XF86VMODE)
799                         # XXX, why dont cmake make this available?
800                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
801                         mark_as_advanced(X11_Xxf86vmode_LIB)
802                         if(X11_Xxf86vmode_LIB)
803                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
804                         else()
805                                 set(WITH_X11_XF86VMODE OFF)
806                         endif()
807                 endif()
808         endif()
809
810         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
811                 if(NOT WITH_PYTHON_MODULE)
812                         # BSD's dont use libdl.so
813                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
814                         # binreloc is linux only
815                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
816                         set(WITH_BINRELOC ON)
817                 endif()
818         endif()
819
820         set(PLATFORM_LINKFLAGS "-pthread")
821
822         # lfs on glibc, all compilers should use
823         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
824
825         # GNU Compiler
826         if(CMAKE_COMPILER_IS_GNUCC)
827                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
828         # CLang is the same as GCC for now.
829         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
830                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
831         # Solaris CC
832         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro") 
833                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
834                 
835         # Intel C++ Compiler
836         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
837                 # think these next two are broken
838                 find_program(XIAR xiar)
839                 if(XIAR)
840                         set(CMAKE_AR "${XIAR}")
841                 endif()
842                 mark_as_advanced(XIAR)
843
844                 find_program(XILD xild)
845                 if(XILD)
846                         set(CMAKE_LINKER "${XILD}")
847                 endif()
848                 mark_as_advanced(XILD)
849
850                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
851                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
852
853                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
854                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
855                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
856         endif()
857
858 elseif(WIN32)
859
860         # this file is included anyway when building under Windows with cl.exe
861         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
862
863         if(CMAKE_COMPILER_IS_GNUCC)
864                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
865
866                 # Setup 64bit and 64bit windows systems         
867                 if(WITH_MINGW64)
868                         message("Set 64 bit compiler for MinGW.")
869                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
870                 endif()
871         else()
872                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
873
874                 # Setup 64bit and 64bit windows systems
875                 if(CMAKE_CL_64)
876                         message("64 bit compiler detected.")
877                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
878                 endif()
879         endif()
880                 
881         add_definitions(-DWIN32)
882
883         if(WITH_INTERNATIONAL)
884                 set(ICONV ${LIBDIR}/iconv)
885                 set(ICONV_INCLUDE_DIRS ${ICONV}/include)
886                 set(ICONV_LIBRARIES iconv)
887                 set(ICONV_LIBPATH ${ICONV}/lib)
888         endif()
889
890         set(JPEG "${LIBDIR}/jpeg")
891         set(JPEG_INCLUDE_DIR "${JPEG}/include")
892         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
893
894         set(WINTAB_INC ${LIBDIR}/wintab/include)
895
896         if(WITH_OPENAL)
897                 set(OPENAL ${LIBDIR}/openal)
898                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
899                 set(OPENAL_LIBRARY wrap_oal)
900                 set(OPENAL_LIBPATH ${OPENAL}/lib)
901         endif()
902
903         if(WITH_CODEC_SNDFILE)
904                 set(SNDFILE ${LIBDIR}/sndfile)
905                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
906                 set(SNDFILE_LIBRARIES libsndfile-1)
907                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
908         endif()
909
910         if(WITH_SDL)
911                 set(SDL ${LIBDIR}/sdl)
912                 set(SDL_INCLUDE_DIR ${SDL}/include)
913                 set(SDL_LIBRARY SDL)
914                 set(SDL_LIBPATH ${SDL}/lib)
915         endif()
916
917         if(WITH_CODEC_QUICKTIME)
918                 set(QUICKTIME ${LIBDIR}/QTDevWin)
919                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
920                 set(QUICKTIME_LIBRARIES qtmlClient)
921                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
922         endif()
923
924         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
925                 add_definitions(-D__SSE__ -D__MMX__)
926         endif()
927
928         if(WITH_CYCLES_OSL)
929                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
930         
931                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
932         
933                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
934                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
935                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
936                 # WARNING! depends on correct order of OSL libs linking
937                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
938                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
939                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
940         
941                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
942                         set(OSL_FOUND TRUE)
943                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
944                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
945                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
946                 else()
947                         message(STATUS "OSL not found")
948                 endif()
949         endif()
950
951         if(MSVC)
952                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
953
954                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
955
956                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
957                 set(CMAKE_C_FLAGS   "/nologo /J /Gd"       CACHE STRING "MSVC MT C++ flags " FORCE)
958
959                 if(CMAKE_CL_64)
960                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
961                 else()
962                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
963                 endif()
964                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
965                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
966                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
967                 if(CMAKE_CL_64)
968                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
969                 else()
970                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
971                 endif()
972                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
973                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
974                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
975
976                 # most msvc warnings are C & C++
977                 set(_WARNINGS "/W3 /wd4018 /wd4244 /wd4305 /wd4800 /wd4181 /wd4065 /wd4267 /we4013 /wd4200")
978                 set(C_WARNINGS "${_WARNINGS}")
979                 set(CXX_WARNINGS "${_WARNINGS}")
980                 unset(_WARNINGS)
981
982                 if(WITH_INTERNATIONAL)
983                         set(GETTEXT ${LIBDIR}/gettext)
984                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
985                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
986                         set(GETTEXT_LIBRARIES gnu_gettext)
987                 endif()
988                 
989                 if(WITH_MOD_CLOTH_ELTOPO)
990                         set(LAPACK ${LIBDIR}/lapack)
991                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
992                         set(LAPACK_LIBPATH ${LAPACK}/lib)       
993                         set(LAPACK_LIBRARIES
994                                 ${LIBDIR}/lapack/lib/libf2c.lib
995                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
996                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
997                         )
998                 endif()
999
1000                 set(PNG_LIBRARIES libpng)
1001                 set(JPEG_LIBRARIES libjpeg)
1002                 
1003                 set(PNG "${LIBDIR}/png")
1004                 set(PNG_INCLUDE_DIR "${PNG}/include")
1005                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1006
1007                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1008                 if(CMAKE_CL_64)
1009                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
1010                 else()
1011                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
1012                 endif()
1013
1014                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1015                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1016
1017                 set(FREETYPE ${LIBDIR}/freetype)
1018                 set(FREETYPE_INCLUDE_DIRS
1019                         ${LIBDIR}/freetype/include
1020                         ${LIBDIR}/freetype/include/freetype2
1021                 )
1022                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1023
1024                 if(WITH_FFTW3)
1025                         set(FFTW3 ${LIBDIR}/fftw3)
1026                         set(FFTW3_LIBRARIES libfftw)
1027                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1028                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1029                 endif()
1030
1031                 if(WITH_OPENCOLLADA)
1032                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1033
1034                         set(OPENCOLLADA_INCLUDE_DIRS
1035                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
1036                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
1037                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
1038                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
1039                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
1040                         )
1041                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada")
1042
1043                         set(OPENCOLLADA_LIBRARIES
1044                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADASaxFrameworkLoader.lib
1045                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAFramework.lib
1046                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADABaseUtils.lib
1047                                 ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAStreamWriter.lib
1048                                 ${OPENCOLLADA_LIBPATH}/lib/MathMLSolver.lib
1049                                 ${OPENCOLLADA_LIBPATH}/lib/GeneratedSaxParser.lib
1050                                 ${OPENCOLLADA_LIBPATH}/lib/xml2.lib
1051                                 ${OPENCOLLADA_LIBPATH}/lib/buffer.lib
1052                                 ${OPENCOLLADA_LIBPATH}/lib/ftoa.lib
1053                                 ${OPENCOLLADA_LIBPATH}/lib/UTF.lib
1054                         )
1055                         set(PCRE_LIBRARIES
1056                                 ${OPENCOLLADA_LIBPATH}/lib/pcre.lib
1057                         )
1058                         
1059                         unset(OPENCOLLADA_LIBPATH)
1060                         
1061                 endif()
1062
1063                 if(WITH_CODEC_FFMPEG)
1064                         set(FFMPEG_INCLUDE_DIRS
1065                                 ${LIBDIR}/ffmpeg/include
1066                                 ${LIBDIR}/ffmpeg/include/msvc
1067                         )
1068                         set(FFMPEG_LIBRARIES
1069                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
1070                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
1071                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
1072                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
1073                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1074                         )
1075                 endif()
1076
1077                 if(WITH_IMAGE_OPENEXR)
1078                         set_lib_path(OPENEXR "openexr")
1079                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1080                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1081                         set(OPENEXR_LIBRARIES
1082                                 ${OPENEXR_LIBPATH}/Iex.lib
1083                                 ${OPENEXR_LIBPATH}/Half.lib
1084                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1085                                 ${OPENEXR_LIBPATH}/Imath.lib
1086                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1087                         )
1088                         set(OPENEXR_INCLUDE_DIRS
1089                                 ${OPENEXR_INCLUDE_DIR}
1090                                 ${OPENEXR_INCLUDE_DIR}/IlmImf
1091                                 ${OPENEXR_INCLUDE_DIR}/Iex
1092                                 ${OPENEXR_INCLUDE_DIR}/Imath
1093                         )
1094                 endif()
1095
1096                 if(WITH_IMAGE_TIFF)
1097                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1098                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1099                 endif()
1100
1101                 if(WITH_JACK)
1102                         set(JACK_INCLUDE_DIRS
1103                                 ${LIBDIR}/jack/include/jack
1104                                 ${LIBDIR}/jack/include
1105                         )
1106                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
1107                 endif()
1108
1109                 if(WITH_PYTHON)
1110                         # normally cached but not since we include them with blender
1111                         set(PYTHON_VERSION 3.2) # CACHE STRING)
1112                         set_lib_path(PYTHON "python")
1113                         set(PYTHON_LIBRARY ${PYTHON}/lib/python32.lib) #CACHE FILEPATH
1114                         #Shared includes for both vc2008 and vc2010
1115                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1116
1117                         # uncached vars
1118                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1119                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1120                 endif()
1121
1122                 if(WITH_BOOST)
1123                         set(BOOST ${LIBDIR}/boost)
1124                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1125                         if(MSVC10)
1126                                 set(BOOST_LIBPATH ${BOOST}/vc2010/lib)
1127                                 set(BOOST_POSTFIX "vc100-mt-s-1_49.lib")
1128                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_49.lib")
1129                         else()
1130                                 set(BOOST_LIBPATH ${BOOST}/lib)
1131                                 set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1132                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")                                 
1133                         endif()
1134                         set(BOOST_LIBRARIES
1135                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1136                                 optimized libboost_regex-${BOOST_POSTFIX}
1137                                 optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1138                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1139                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1140                                 debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1141                                 if(WITH_CYCLES_OSL)
1142                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1143                                                 optimized libboost_python3-${BOOST_POSTFIX}
1144                                                 debug libboost_python3-${BOOST_DEBUG_POSTFIX})
1145                                 endif(WITH_CYCLES_OSL)
1146                                 
1147                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1148                 endif()
1149                         
1150                 if(WITH_OPENIMAGEIO)
1151                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1152                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1153                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1154                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1155                         set(OPENIMAGEIO_DEFINITIONS)
1156                 endif()
1157
1158                 if(WITH_OPENCOLORIO)
1159                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1160                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1161                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1162                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1163                         set(OPENCOLORIO_DEFINITIONS)
1164                 endif()
1165
1166                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1167
1168                 # MSVC only, Mingw doesnt need
1169                 if(CMAKE_CL_64)
1170                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1171                 else()
1172                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1173                 endif()
1174
1175                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1176
1177                 # used in many places so include globally, like OpenGL
1178                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1179
1180         elseif(CMAKE_COMPILER_IS_GNUCC)
1181         # keep GCC specific stuff here          
1182                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1183                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1184
1185                 if(WITH_MINGW64)
1186                         #We need to take care though not to have these on debug builds because they may play funky with gdb
1187                         if(CMAKE_BUILD_TYPE MATCHES "Release")
1188                                 set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -ftree-vectorize")
1189                         endif()
1190                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1191                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1192                         
1193                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1194                         #Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
1195                         set(WITH_OPENMP OFF)
1196                 endif()
1197
1198                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1199
1200
1201                 add_definitions(-DFREE_WINDOWS)
1202
1203                 if(WITH_INTERNATIONAL)
1204                         set(GETTEXT ${LIBDIR}/gettext)
1205                         set(GETTEXT_INCLUDE_DIRS ${GETTEXT}/include)
1206                         set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1207                         set(GETTEXT_LIBRARIES intl)
1208                 endif()
1209                 
1210                 set(PNG "${LIBDIR}/png")
1211                 set(PNG_INCLUDE_DIR "${PNG}/include")
1212                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1213
1214                 if(WITH_MINGW64)
1215                         set(JPEG_LIBRARIES jpeg)
1216                 else()
1217                         set(JPEG_LIBRARIES libjpeg)
1218                 endif()
1219                 set(PNG_LIBRARIES png)
1220
1221                 set(ZLIB ${LIBDIR}/zlib)
1222                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1223                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1224                 set(ZLIB_LIBRARIES z)
1225
1226                 #comes with own pthread library
1227                 if(NOT WITH_MINGW64)
1228                         set(PTHREADS ${LIBDIR}/pthreads)
1229                         set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1230                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1231                         set(PTHREADS_LIBRARIES pthreadGC2)
1232                 endif()
1233                 
1234                 set(FREETYPE ${LIBDIR}/freetype)
1235                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1236                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1237                 set(FREETYPE_LIBRARY freetype)
1238
1239                 if(WITH_FFTW3)
1240                         set(FFTW3 ${LIBDIR}/fftw3)
1241                         set(FFTW3_LIBRARIES fftw3)
1242                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1243                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1244                 endif()
1245
1246                 if(WITH_OPENCOLLADA)
1247                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1248                         set(OPENCOLLADA_INCLUDE_DIRS
1249                                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
1250                                 ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
1251                                 ${LIBDIR}/opencollada/include/COLLADAFramework/include
1252                                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
1253                                 ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
1254                         )
1255                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
1256                         if(WITH_MINGW64)
1257                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre buffer ftoa xml)
1258                         else()
1259                                 set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
1260                         endif()
1261                         set(PCRE_LIBRARIES pcre)
1262                 endif()
1263
1264                 if(WITH_CODEC_FFMPEG)
1265                         set(FFMPEG ${LIBDIR}/ffmpeg)
1266                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1267                         if(WITH_MINGW64)
1268                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1269                         else()
1270                                 set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
1271                         endif()
1272                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1273                 endif()
1274
1275                 if(WITH_IMAGE_OPENEXR)
1276                         set(OPENEXR ${LIBDIR}/openexr)
1277                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1278                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1279                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1280                 endif()
1281
1282                 if(WITH_IMAGE_TIFF)
1283                         set(TIFF ${LIBDIR}/tiff)
1284                         set(TIFF_LIBRARY tiff)
1285                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1286                         set(TIFF_LIBPATH ${TIFF}/lib)
1287                 endif()
1288
1289                 if(WITH_JACK)
1290                         set(JACK ${LIBDIR}/jack)
1291                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1292                         set(JACK_LIBRARIES jack)
1293                         set(JACK_LIBPATH ${JACK}/lib)
1294
1295                         # TODO, gives linking errors, force off
1296                         set(WITH_JACK OFF)
1297                 endif()
1298
1299                 if(WITH_PYTHON)
1300                         # normally cached but not since we include them with blender
1301                         set(PYTHON_VERSION 3.2) #  CACHE STRING)
1302                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1303                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python32mw.lib")  # CACHE FILEPATH)
1304
1305                         # uncached vars
1306                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1307                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1308                 endif()
1309
1310                 if(WITH_BOOST)
1311                         set(BOOST ${LIBDIR}/boost)
1312                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1313                         if(WITH_MINGW64)
1314                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1315                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1316                         else()
1317                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1318                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1319                         endif()         
1320                         set(BOOST_LIBRARIES
1321                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1322                                 boost_regex-${BOOST_POSTFIX}
1323                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1324                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1325                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1326                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1327                                 if(WITH_CYCLES_OSL)
1328                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1329                                                 optimized libboost_python3-${BOOST_POSTFIX}
1330                                                 debug libboost_python3-${BOOST_DEBUG_POSTFIX}) 
1331                                 endif(WITH_CYCLES_OSL)
1332                                         
1333                         set(BOOST_LIBPATH ${BOOST}/lib)
1334                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1335                 endif()
1336                         
1337                 if(WITH_OPENIMAGEIO)
1338                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1339                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1340                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1341                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1342                         set(OPENIMAGEIO_DEFINITIONS)
1343                 endif()
1344                 
1345                 if(WITH_OPENCOLORIO)
1346                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1347                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1348                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1349                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1350                         set(OPENCOLORIO_DEFINITIONS)
1351                 endif()
1352
1353                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1354
1355                 ## DISABLE - causes linking errors 
1356                 ## for re-distribution, so users dont need mingw installed
1357                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1358
1359         endif()
1360
1361 elseif(APPLE)
1362
1363         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1364                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/10.7
1365         endif()
1366
1367         if(${XCODE_VERSION} VERSION_LESS 4.3)
1368                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
1369         else()
1370                 # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
1371                 # absolute pathes are more foolproof here !
1372                 set(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
1373                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
1374                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
1375         endif() 
1376         
1377         if(WITH_LIBS10.5)
1378                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1379         else()
1380                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1381                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1382                 else()
1383                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1384                 endif()
1385         endif()
1386
1387
1388         if(WITH_OPENAL)
1389                 find_package(OpenAL)
1390                 if(OPENAL_FOUND)
1391                         set(WITH_OPENAL ON)
1392                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1393                 else()
1394                         set(WITH_OPENAL OFF)
1395                 endif()
1396         endif()
1397
1398         if(WITH_JACK)
1399                 set(JACK /usr)
1400                 set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
1401                 set(JACK_LIBRARIES jack)
1402                 set(JACK_LIBPATH ${JACK}/lib)
1403         endif()
1404
1405         if(WITH_CODEC_SNDFILE)
1406                 set(SNDFILE ${LIBDIR}/sndfile)
1407                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1408                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1409                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1410         endif()
1411
1412         if(WITH_PYTHON)
1413                 if(NOT WITH_PYTHON_MODULE)
1414                         # we use precompiled libraries for py 3.2 and up by default
1415
1416                         # normally cached but not since we include them with blender
1417                         set(PYTHON_VERSION 3.2)
1418                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
1419                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1420                         set(PYTHON_LIBRARY python${PYTHON_VERSION})
1421                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1422                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1423                 else()
1424                         # module must be compiled against Python framework
1425
1426                         # normally cached but not since we include them with blender
1427                         set(PYTHON_VERSION 3.2)
1428                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1429                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1430                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1431                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-3.2m")
1432                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1433                 endif()
1434                 
1435                 # uncached vars
1436                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1437                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1438         endif()
1439
1440         if(WITH_INTERNATIONAL)
1441                 set(GETTEXT ${LIBDIR}/gettext)
1442                 set(GETTEXT_INCLUDE_DIRS "${GETTEXT}/include")
1443                 set(GETTEXT_LIBRARIES intl iconv)
1444                 set(GETTEXT_LIBPATH ${GETTEXT}/lib)
1445         endif()
1446
1447         if(WITH_FFTW3)
1448                 set(FFTW3 ${LIBDIR}/fftw3)
1449                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1450                 set(FFTW3_LIBRARIES fftw3)
1451                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1452         endif()
1453
1454         set(PNG_LIBRARIES png)
1455         set(JPEG_LIBRARIES jpeg)
1456
1457         set(ZLIB /usr)
1458         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1459         set(ZLIB_LIBRARIES z bz2)
1460
1461         set(FREETYPE ${LIBDIR}/freetype)
1462         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1463         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1464         set(FREETYPE_LIBRARY freetype)
1465
1466         if(WITH_IMAGE_OPENEXR)
1467                 set(OPENEXR ${LIBDIR}/openexr)
1468                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1469                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1470                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1471                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1472         endif()
1473
1474         if(WITH_CODEC_FFMPEG)
1475                 set(FFMPEG ${LIBDIR}/ffmpeg)
1476                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1477                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1478                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1479                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1480         endif()
1481
1482         find_library(SYSTEMSTUBS_LIBRARY
1483                 NAMES
1484                 SystemStubs
1485                 PATHS
1486         )
1487         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1488         if(SYSTEMSTUBS_LIBRARY)
1489                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1490         else()
1491                 set(PLATFORM_LINKLIBS stdc++)
1492         endif()
1493
1494         if(WITH_COCOA)
1495                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1496                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1497                 if(USE_QTKIT)
1498                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1499                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1500                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1501                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1502                                 #libSDL still needs 32bit carbon quicktime
1503                         endif()
1504                 elseif(WITH_CODEC_QUICKTIME)
1505                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1506                 endif()
1507
1508                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1509                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1510                 if(WITH_INPUT_NDOF)
1511                         # This thread it *should* work and check the framework - campbell
1512                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1513                         find_library(3D_CONNEXION_CLIENT_LIBRARY
1514                                 NAMES 3DconnexionClient
1515                         )
1516                         if(NOT 3D_CONNEXION_CLIENT_LIBRARY)
1517                                 set(WITH_INPUT_NDOF OFF)
1518                         endif()
1519
1520                         if(WITH_INPUT_NDOF)
1521                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework 3DconnexionClient")
1522                         endif()
1523                 endif()
1524
1525         else()
1526                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1527                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1528                 set(WITH_INPUT_NDOF OFF)  # unsupported
1529         endif()
1530         
1531         if(WITH_PYTHON_MODULE)
1532                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/python")# force cmake to link right framework
1533         endif()
1534         
1535         if(WITH_OPENCOLLADA)
1536                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1537
1538                 set(OPENCOLLADA_INCLUDE_DIRS
1539                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1540                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1541                         ${LIBDIR}/opencollada/include/COLLADAFramework
1542                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1543                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1544                 )
1545
1546                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1547                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1548                 #pcre is bundled with openCollada
1549                 #set(PCRE ${LIBDIR}/pcre)
1550                 #set(PCRE_LIBPATH ${PCRE}/lib)
1551                 set(PCRE_LIBRARIES pcre)
1552                 #libxml2 is used
1553                 #set(EXPAT ${LIBDIR}/expat)
1554                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1555                 set(EXPAT_LIB)
1556         endif()
1557
1558         if(WITH_SDL)
1559                 set(SDL ${LIBDIR}/sdl)
1560                 set(SDL_INCLUDE_DIR ${SDL}/include)
1561                 set(SDL_LIBRARY SDL)
1562                 set(SDL_LIBPATH ${SDL}/lib)
1563         endif()
1564
1565         set(PNG "${LIBDIR}/png")
1566         set(PNG_INCLUDE_DIR "${PNG}/include")
1567         set(PNG_LIBPATH ${PNG}/lib)
1568
1569         set(JPEG "${LIBDIR}/jpeg")
1570         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1571         set(JPEG_LIBPATH ${JPEG}/lib)
1572
1573         if(WITH_IMAGE_TIFF)
1574                 set(TIFF ${LIBDIR}/tiff)
1575                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1576                 set(TIFF_LIBRARY tiff)
1577                 set(TIFF_LIBPATH ${TIFF}/lib)
1578         endif()
1579
1580         if (WITH_INPUT_NDOF)
1581                 # linker needs "-weak_framework 3DconnexionClient"
1582         endif()
1583
1584         if(WITH_BOOST)
1585                 set(BOOST ${LIBDIR}/boost)
1586                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1587                 if(WITH_CYCLES_OSL)
1588                         set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_python3-mt boost_regex-mt boost_system-mt boost_thread-mt)
1589                 else(WITH_CYCLES_OSL)
1590                         set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt)
1591                 endif(WITH_CYCLES_OSL)
1592                 set(BOOST_LIBPATH ${BOOST}/lib)
1593                 set(BOOST_DEFINITIONS)
1594         endif()
1595
1596         if(WITH_OPENIMAGEIO)
1597                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1598                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1599                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1600                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1601                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1602         endif()
1603
1604         if(WITH_OPENCOLORIO)
1605                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1606                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1607                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1608                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1609                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1610         endif()
1611
1612         if(WITH_LLVM)
1613                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1614                 set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use" "")
1615                 set(LLVM_STATIC YES)
1616                 if(LLVM_DIRECTORY)
1617                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1618                 else()
1619                         set(LLVM_CONFIG llvm-config)
1620                 endif()
1621                 execute_process(COMMAND ${LLVM_CONFIG} --version
1622                                 OUTPUT_VARIABLE LLVM_VERSION
1623                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1624                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1625                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1626                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1627                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1628                                 OUTPUT_VARIABLE LLVM_LIB_DIR
1629                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1630                 find_library(LLVM_LIBRARY
1631                              NAMES libLLVMAnalysis.a # first of a whole bunch of libs to get
1632                              PATHS ${LLVM_LIB_DIR})
1633                 message(STATUS "LLVM version  = ${LLVM_VERSION}")
1634                 message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
1635                 message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
1636
1637                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
1638                         if(LLVM_STATIC)
1639                                 # if static LLVM libraries were requested, use llvm-config to generate
1640                                 # the list of what libraries we need, and substitute that in the right
1641                                 # way for LLVM_LIBRARY.
1642                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1643                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1644                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1645                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1646                         endif()
1647                         message(STATUS "LLVM library  = ${LLVM_LIBRARY}")
1648                 else()
1649                         message(FATAL_ERROR "LLVM not found.")
1650                 endif()
1651         endif()
1652
1653         if(WITH_CYCLES_OSL)
1654                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1655         
1656                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
1657         
1658                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1659                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1660                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1661                 # WARNING! depends on correct order of OSL libs linking
1662                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1663                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1664                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1665         
1666                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1667                         set(OSL_FOUND TRUE)
1668                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
1669                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
1670                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
1671                 else()
1672                         message(STATUS "OSL not found")
1673                 endif()
1674         endif()
1675
1676         set(EXETYPE MACOSX_BUNDLE)
1677
1678         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1679         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1680         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1681                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
1682                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
1683                 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1684                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1685                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1686                 endif()
1687         else()
1688                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1689                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1690         endif()
1691 endif()
1692
1693 #-----------------------------------------------------------------------------
1694 # Common.
1695
1696 if(APPLE OR WIN32)
1697         if(NOT EXISTS "${LIBDIR}/")
1698                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1699         endif()
1700 endif()
1701
1702 if(WITH_CYCLES)
1703         if(NOT WITH_OPENIMAGEIO)
1704                 message(FATAL_ERROR "Cycles reqires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1705         endif()
1706         if(NOT WITH_BOOST)
1707                 message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1708         endif()
1709
1710         if(WITH_CYCLES_OSL)
1711                 if(NOT WITH_LLVM)
1712                         message(FATAL_ERROR "Cycles OSL reqires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
1713                 endif()
1714         endif()
1715 endif()
1716
1717
1718 # See TEST_SSE_SUPPORT() for how this is defined.
1719
1720 if(WITH_RAYOPTIMIZATION)
1721         if(SUPPORT_SSE_BUILD)
1722                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1723                 add_definitions(-D__SSE__ -D__MMX__)
1724         endif()
1725         if(SUPPORT_SSE2_BUILD)
1726                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1727                 add_definitions(-D__SSE2__)
1728                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1729                         add_definitions(-D__MMX__)
1730                 endif()
1731         endif()
1732 endif()
1733
1734
1735 # set the endian define
1736 if(MSVC)
1737         # for some reason this fails on msvc
1738         add_definitions(-D__LITTLE_ENDIAN__)
1739         
1740 # OSX-Note: as we do crosscompiling with specific set architecture,
1741 # endianess-detection and autosetting is counterproductive
1742 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1743
1744 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1745         add_definitions(-D__LITTLE_ENDIAN__)
1746 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1747         add_definitions(-D__BIG_ENDIAN__)
1748         
1749 else()
1750         include(TestBigEndian)
1751         test_big_endian(_SYSTEM_BIG_ENDIAN)
1752         if(_SYSTEM_BIG_ENDIAN)
1753                 add_definitions(-D__BIG_ENDIAN__)
1754         else()
1755                 add_definitions(-D__LITTLE_ENDIAN__)
1756         endif()
1757         unset(_SYSTEM_BIG_ENDIAN)
1758 endif()
1759
1760
1761 if(WITH_IMAGE_OPENJPEG)
1762         if(WITH_SYSTEM_OPENJPEG)
1763                 # dealt with above
1764         else()
1765                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1766                 add_definitions(-DOPJ_STATIC)
1767         endif()
1768 endif()
1769
1770 if(WITH_IMAGE_REDCODE)
1771         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1772         set(REDCODE_INC ${REDCODE})
1773 endif()
1774
1775 #-----------------------------------------------------------------------------
1776 # Blender WebPlugin
1777
1778 if(WITH_WEBPLUGIN)
1779         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1780         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1781
1782         set(WITH_PLAYER ON)
1783 endif()
1784
1785
1786 #-----------------------------------------------------------------------------
1787 # Configure OpenGL.
1788 find_package(OpenGL)
1789 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1790 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1791 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1792
1793 #-----------------------------------------------------------------------------
1794 # Configure OpenMP.
1795 if(WITH_OPENMP)
1796         find_package(OpenMP)
1797         if(OPENMP_FOUND)
1798                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1799                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1800
1801                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1802                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1803                 endif()
1804         else()
1805                 set(WITH_OPENMP OFF)
1806         endif()
1807
1808         mark_as_advanced(
1809                 OpenMP_C_FLAGS
1810                 OpenMP_CXX_FLAGS
1811         )
1812 endif()
1813
1814 #-----------------------------------------------------------------------------
1815 # Configure GLEW
1816
1817 if(WITH_SYSTEM_GLEW)
1818         find_package(GLEW)
1819
1820         if(NOT GLEW_FOUND)
1821                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
1822         endif()
1823
1824         mark_as_advanced(
1825                 GLEW_LIBRARY
1826                 GLEW_INCLUDE_PATH
1827         )
1828 else()
1829         # set(GLEW_LIBRARY "")  # unused
1830         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1831 endif()
1832
1833 #-----------------------------------------------------------------------------
1834 # Configure Python.
1835
1836 if(WITH_PYTHON_MODULE)
1837         add_definitions(-DPy_ENABLE_SHARED)
1838 endif()
1839
1840 #-----------------------------------------------------------------------------
1841 # Extra compile flags
1842
1843 if(CMAKE_COMPILER_IS_GNUCC)
1844
1845         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1846         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1847         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1848         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1849         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1850         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1851         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1852         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1853         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1854         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1855         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1856         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1857         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1858         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1859         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1860         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1861         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1862         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1863         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1864         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1865
1866         # disable because it gives warnings for printf() & friends.
1867         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1868
1869         if(NOT APPLE)
1870                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1871         endif()
1872
1873         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1874         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1875         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1876         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1877         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1878         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1879         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1880         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1881
1882         # causes too many warnings
1883         if(NOT APPLE)
1884                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1885                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1886         endif()
1887
1888         # flags to undo strict flags
1889         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1890         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1891
1892         if(NOT APPLE)
1893                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1894         endif()
1895
1896 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1897
1898         # strange, clang complains these are not supported, but then yses them.
1899         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1900         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1901         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1902         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1903         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1904         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1905         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1906
1907         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1908         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1909         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1910         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1911         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.
1912         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1913         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1914
1915 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1916
1917         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1918         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1919         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1920
1921         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1922         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1923         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1924
1925         # disable numbered, false positives
1926         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1927         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1928
1929 endif()
1930
1931 # MSVC2010 fails to links C++ libs right
1932 if(MSVC10)
1933         if(WITH_OPENCOLLADA)
1934                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
1935         endif()
1936 endif()
1937
1938 # ensure python header is found since detection can fail, this could happen
1939 # with _any_ library but since we used a fixed python version this tends to
1940 # be most problematic.
1941 if(WITH_PYTHON)
1942         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1943                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1944                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1945                                                         "to a valid python include path. Containing "
1946                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
1947         endif()
1948
1949         if(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
1950                 # set but invalid
1951                 if(NOT ${PYTHON_NUMPY_PATH} STREQUAL "")
1952                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
1953                                 message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
1954                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
1955                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
1956                         endif()
1957                 # not set, so initialize
1958                 else()
1959                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
1960                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
1961
1962                         # re-cache
1963                         unset(PYTHON_NUMPY_PATH CACHE)
1964                         find_path(PYTHON_NUMPY_PATH
1965                           NAMES
1966                             numpy
1967                           HINTS
1968                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
1969                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
1970                           PATH_SUFFIXES
1971                             site-packages
1972                             dist-packages
1973                            NO_DEFAULT_PATH
1974                         )
1975
1976                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
1977                                 message(WARNING "'numpy' path could not be found in:\n"
1978                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
1979                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
1980                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
1981                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
1982                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
1983                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
1984                         else()
1985                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
1986                         endif()
1987
1988                         unset(_PY_VER_SPLIT)
1989                         unset(_PY_VER_MAJOR)
1990                 endif()
1991         endif()
1992 endif()
1993
1994
1995 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS} ${C_WARNINGS}")
1996 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
1997
1998 #-------------------------------------------------------------------------------
1999 # Global Defines
2000
2001 # better not set includes here but this debugging option is off by default.
2002 if(WITH_CXX_GUARDEDALLOC)
2003         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2004         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2005 endif()
2006
2007 if(WITH_ASSERT_ABORT)
2008         add_definitions(-DWITH_ASSERT_ABORT)
2009 endif()
2010
2011 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2012 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2013
2014 #-----------------------------------------------------------------------------
2015 # Libraries
2016
2017 add_subdirectory(source)
2018 add_subdirectory(intern)
2019 add_subdirectory(extern)
2020
2021
2022 #-----------------------------------------------------------------------------
2023 # Blender Application
2024 if(WITH_BLENDER)
2025         add_subdirectory(source/creator)
2026 endif()
2027
2028
2029 #-----------------------------------------------------------------------------
2030 # Blender Player
2031 if(WITH_PLAYER)
2032         add_subdirectory(source/blenderplayer)
2033 endif()
2034
2035 #-----------------------------------------------------------------------------
2036 # CPack for generating packages
2037 include(build_files/cmake/packaging.cmake)
2038
2039
2040 #-----------------------------------------------------------------------------
2041 # Print Final Configuration
2042
2043 if(FIRST_RUN)
2044         set(_config_msg "\n* Blender Configuration *")
2045         macro(info_cfg_option
2046                 _setting)
2047                 set(_msg "   * ${_setting}")
2048                 string(LENGTH "${_msg}" _len)
2049                 while("32" GREATER "${_len}")
2050                         set(_msg "${_msg} ")
2051                          math(EXPR _len "${_len} + 1")
2052                 endwhile()
2053
2054                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2055         endmacro()
2056
2057         macro(info_cfg_text
2058                 _text)
2059                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2060
2061
2062         endmacro()
2063
2064         info_cfg_text("Build Options:")
2065         info_cfg_option(WITH_GAMEENGINE)
2066         info_cfg_option(WITH_PLAYER)
2067         info_cfg_option(WITH_BULLET)
2068         info_cfg_option(WITH_IK_SOLVER)
2069         info_cfg_option(WITH_IK_ITASC)
2070         info_cfg_option(WITH_OPENCOLLADA)
2071         info_cfg_option(WITH_FFTW3)
2072         info_cfg_option(WITH_INTERNATIONAL)
2073         info_cfg_option(WITH_INPUT_NDOF)
2074         info_cfg_option(WITH_CYCLES)
2075         info_cfg_option(WITH_OPENCOLORIO)
2076
2077         info_cfg_text("Compiler Options:")
2078         info_cfg_option(WITH_BUILDINFO)
2079         info_cfg_option(WITH_OPENMP)
2080         info_cfg_option(WITH_RAYOPTIMIZATION)
2081
2082         info_cfg_text("System Options:")
2083         info_cfg_option(WITH_INSTALL_PORTABLE)
2084         info_cfg_option(WITH_X11_XF86VMODE)
2085         info_cfg_option(WITH_X11_XINPUT)
2086         info_cfg_option(WITH_MEM_JEMALLOC)
2087         info_cfg_option(WITH_SYSTEM_GLEW)
2088         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2089
2090         info_cfg_text("Image Formats:")
2091         info_cfg_option(WITH_IMAGE_CINEON)
2092         info_cfg_option(WITH_IMAGE_DDS)
2093         info_cfg_option(WITH_IMAGE_HDR)
2094         info_cfg_option(WITH_IMAGE_OPENEXR)
2095         info_cfg_option(WITH_IMAGE_OPENJPEG)
2096         info_cfg_option(WITH_IMAGE_REDCODE)
2097         info_cfg_option(WITH_IMAGE_TIFF)
2098
2099         info_cfg_text("Audio:")
2100         info_cfg_option(WITH_OPENAL)
2101         info_cfg_option(WITH_SDL)
2102         info_cfg_option(WITH_JACK)
2103         info_cfg_option(WITH_CODEC_AVI)
2104         info_cfg_option(WITH_CODEC_FFMPEG)
2105         info_cfg_option(WITH_CODEC_SNDFILE)
2106
2107         info_cfg_text("Compression:")
2108         info_cfg_option(WITH_LZMA)
2109         info_cfg_option(WITH_LZO)
2110
2111         info_cfg_text("Python:")
2112         info_cfg_option(WITH_PYTHON_INSTALL)
2113         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2114         info_cfg_option(WITH_PYTHON_MODULE)
2115         info_cfg_option(WITH_PYTHON_SAFETY)
2116
2117         info_cfg_text("Modifiers:")
2118         info_cfg_option(WITH_MOD_BOOLEAN)
2119         info_cfg_option(WITH_MOD_REMESH)
2120         info_cfg_option(WITH_MOD_DECIMATE)
2121         info_cfg_option(WITH_MOD_FLUID)
2122         info_cfg_option(WITH_MOD_OCEANSIM)
2123
2124         info_cfg_text("")
2125
2126         message("${_config_msg}")
2127 endif()