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