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