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