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