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