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