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