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