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