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