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