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