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