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