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