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