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