37cabd00022870b5d2d7b3c38492389c1567be0c
[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" ON) 
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 set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on. 
125
126 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)
127 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)
128 if(APPLE)
129         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
130 endif()
131
132 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
133 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
134 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
135 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ON)
136 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
137 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
138 mark_as_advanced(WITH_SYSTEM_BULLET)
139 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
140 option(WITH_PLAYER        "Build Player" OFF)
141 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
142 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
143
144 # GHOST Windowing Library Options
145 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
146 mark_as_advanced(WITH_GHOST_DEBUG)
147
148 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
149 mark_as_advanced(WITH_GHOST_SDL)
150
151 # Misc...
152 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
153 mark_as_advanced(WITH_HEADLESS)
154
155 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
156 mark_as_advanced(WITH_AUDASPACE)
157
158 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
159
160 if(UNIX AND NOT APPLE)
161         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
162         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
163         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
164
165         option(WITH_GHOST_XDND   "Enable drag'n'drop support on X11 using XDND protocol" ON)
166 else()
167         # not an option for other OS's
168         set(WITH_SYSTEM_GLEW OFF)
169 endif()
170
171
172 # (unix defaults to System OpenJPEG On)
173 if(UNIX AND NOT APPLE)
174         set(PLATFORM_DEFAULT ON)
175 else()
176         set(PLATFORM_DEFAULT OFF)
177 endif()
178 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
179 unset(PLATFORM_DEFAULT)
180
181
182 # Modifiers
183 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
184 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
185 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
186 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
187 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
188 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
189 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
190
191 # Image format support
192 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" OFF)
193 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
194 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
195 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
196 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
197 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
198 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
199 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
200 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
201
202 # Audio/Video format support
203 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
204 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
205 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
206
207 if(APPLE)
208         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ON)
209         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
210 else()
211         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
212 endif()
213
214 # 3D format support
215 # Disable opencollada when we don't have precompiled libs
216 if(APPLE OR WIN32)
217         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" ON)
218 else()
219         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" OFF)
220 endif()
221
222 # Sound output
223 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
224 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
225 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
226 if(UNIX AND NOT APPLE)
227         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
228 endif()
229
230 # Compression
231 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
232 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
233
234 # Camera/motion tracking
235 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
236
237 # Freestyle
238 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
239
240 # Misc
241 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
242 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
243 option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
244 if(UNIX AND NOT APPLE)
245         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
246         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
247         if(WITH_STATIC_LIBS)
248                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
249                 mark_as_advanced(WITH_BOOST_ICU)
250         endif()
251 endif()
252 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
253 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
254 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Python to python site-packages or dist-packages containing 'numpy' module")
255 mark_as_advanced(PYTHON_NUMPY_PATH)
256
257 if(UNIX AND NOT APPLE)
258         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
259 endif()
260
261 # Cycles
262 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
263 option(WITH_CYCLES_STANDALONE           "Build cycles standalone application" OFF)
264 option(WITH_CYCLES_STANDALONE_GUI       "Build cycles standalone with GUI" OFF)
265 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
266 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
267 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 CACHE STRING "CUDA architectures to build binaries for")
268 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
269 unset(PLATFORM_DEFAULT)
270
271 # LLVM
272 option(WITH_LLVM                                        "Use LLVM" OFF)
273 option(LLVM_STATIC                                      "Link with LLVM static libraries" ON)
274 mark_as_advanced(LLVM_STATIC)
275
276 # disable for now, but plan to support on all platforms eventually
277 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
278 mark_as_advanced(WITH_MEM_JEMALLOC)
279
280 # currently only used for BLI_mempool
281 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
282 mark_as_advanced(WITH_MEM_VALGRIND)
283
284 # Debug
285 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
286 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
287
288 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
289 mark_as_advanced(WITH_ASSERT_ABORT)
290
291 option(WITH_BOOST                                       "Enable features depending on boost" ON)
292
293 if(CMAKE_COMPILER_IS_GNUCC)
294         option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
295         mark_as_advanced(WITH_GCC_MUDFLAP)
296 endif()
297
298 if(APPLE)
299         cmake_minimum_required(VERSION 2.8.8)
300         cmake_policy(VERSION 2.8.8)
301
302         if(NOT CMAKE_OSX_ARCHITECTURES)
303                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
304                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
305                 FORCE)
306         endif()
307         
308         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
309         if(${MAC_SYS} MATCHES 13)
310                 set(OSX_SYSTEM 10.9)
311         elseif(${MAC_SYS} MATCHES 12)
312                 set(OSX_SYSTEM 10.8)
313         elseif(${MAC_SYS} MATCHES 11)
314                 set(OSX_SYSTEM 10.7)
315         elseif(${MAC_SYS} MATCHES 10)
316                 set(OSX_SYSTEM 10.6)
317         elseif(${MAC_SYS} MATCHES 9)
318                 set(OSX_SYSTEM 10.5)
319         else()
320                 set(OSX_SYSTEM unsupported)
321         endif()
322         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
323         
324         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
325         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
326         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
327         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
328         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
329         
330         if(${CMAKE_GENERATOR} MATCHES "Xcode")
331         
332                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
333                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
334                         if(${DP_NAME} MATCHES Xcode5)
335                                 set(XCODE_VERSION 5)
336                         endif()
337                 endif()
338
339                 ##### cmake incompatibility with xcode  4.3 and higher #####
340                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
341                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
342                 endif()
343                 ### end cmake incompatibility with xcode 4.3 and higher ###
344                 
345                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
346                         # Xcode 4 defaults to the Apple LLVM Compiler.
347                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
348                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
349                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
350                 endif()
351         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
352                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
353                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
354                 unset(XCODE_VERS_BUILD_NR)
355         endif()
356         
357         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
358
359         if(${XCODE_VERSION} VERSION_LESS 4.3)
360                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
361         else()
362                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
363                 # so i use a selfcomposed bundlepath here  
364                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
365                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
366                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
367                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
368                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
369                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
370                 endif()
371         endif()
372
373         if(OSX_SYSTEM MATCHES 10.9)
374                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
375         endif()
376
377         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
378                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
379         endif()
380         
381         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
382                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
383                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
384                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
385                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
386         endif()
387
388         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
389 endif()
390
391
392 #-----------------------------------------------------------------------------
393 # Check for conflicting/unsupported configurations
394
395 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
396         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
397 endif()
398
399 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
400         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
401 endif()
402
403 if(NOT WITH_AUDASPACE)
404         if(WITH_OPENAL)
405                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
406         endif()
407         if(WITH_JACK)
408                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
409         endif()
410         if(WITH_GAMEENGINE)
411                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
412         endif()
413 endif()
414
415 if(NOT WITH_SDL AND WITH_GHOST_SDL)
416         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
417 endif()
418
419 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
420         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
421 endif()
422
423 # python module, needs some different options
424 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
425         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
426 endif()
427
428 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
429         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
430 endif()
431
432
433 # may as well build python module without a UI
434 if(WITH_PYTHON_MODULE)
435         set(WITH_HEADLESS ON)
436 endif()
437
438 if(NOT WITH_PYTHON)
439         set(WITH_CYCLES OFF)
440 endif()
441
442 # enable boost for cycles, booleans, audaspace or i18n
443 # otherwise if the user disabled
444 if(NOT WITH_BOOST)
445         # Explicitly disabled. so disable all deps.
446         macro(set_and_warn
447                 _setting _val)
448                 if(${${_setting}})
449                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
450                 endif()
451                 set(${_setting} ${_val})
452         endmacro()
453
454         set_and_warn(WITH_CYCLES         OFF)
455         set_and_warn(WITH_MOD_BOOLEAN    OFF)
456         set_and_warn(WITH_AUDASPACE      OFF)
457         set_and_warn(WITH_INTERNATIONAL  OFF)
458
459         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
460         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
461 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
462         # Keep enabled
463 else()
464         # Enabled but we don't need it
465         set(WITH_BOOST OFF)
466 endif()
467
468 # auto enable openimageio for cycles
469 if(WITH_CYCLES)
470         set(WITH_OPENIMAGEIO ON)
471 endif()
472
473 # auto enable openimageio linking dependencies
474 if(WITH_OPENIMAGEIO)
475         set(WITH_IMAGE_OPENEXR ON)
476         set(WITH_IMAGE_TIFF ON)
477 endif()
478
479 # auto enable llvm for cycles_osl
480 if(WITH_CYCLES_OSL)
481         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
482 endif()
483
484 # don't store paths to libs for portable distribution
485 if(WITH_INSTALL_PORTABLE)
486         set(CMAKE_SKIP_BUILD_RPATH TRUE)
487 endif()
488
489 if(WITH_GHOST_SDL OR WITH_HEADLESS)
490         set(WITH_GHOST_XDND OFF)
491         set(WITH_X11_XF86VMODE OFF)
492         set(WITH_X11_XINPUT OFF)
493 endif()
494
495 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
496
497 TEST_STDBOOL_SUPPORT()
498 if(HAVE_STDBOOL_H)
499         add_definitions(-DHAVE_STDBOOL_H)
500 endif()
501
502 #-----------------------------------------------------------------------------
503 # Check for valid directories
504 # ... a partial checkout may cause this.
505 #
506 # note: we need to check for a known subdir in both cases.
507 #       since uninitialized git submodules will give blank dirs
508
509 if(WITH_INTERNATIONAL)
510         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
511                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
512                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
513                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
514                 set(WITH_INTERNATIONAL OFF)
515         endif()
516 endif()
517
518 if(WITH_PYTHON)
519         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
520                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
521                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
522                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
523         endif()
524 endif()
525
526 #-----------------------------------------------------------------------------
527 # Initialize un-cached vars, avoid unused warning
528
529 # linux only, not cached
530 set(WITH_BINRELOC OFF)
531
532 # MAXOSX only, set to avoid uninitialized
533 set(EXETYPE "")
534
535 # C/C++ flags
536 set(PLATFORM_CFLAGS)
537
538 # these are added to later on.
539 set(C_WARNINGS)
540 set(CXX_WARNINGS)
541
542 # for gcc -Wno-blah-blah
543 set(CC_REMOVE_STRICT_FLAGS)
544
545 # libraries to link the binary with passed to target_link_libraries()
546 # known as LLIBS to scons
547 set(PLATFORM_LINKLIBS "")
548
549 # Added to linker flags in setup_liblinks
550 # - CMAKE_EXE_LINKER_FLAGS
551 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
552 set(PLATFORM_LINKFLAGS "")
553 set(PLATFORM_LINKFLAGS_DEBUG "")
554
555
556 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
557 # On Unix:
558 #   cmake ../blender \
559 #         -D PYTHON_VERSION=3.4 \
560 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
561 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
562 #
563 # On Macs:
564 #   cmake ../blender \
565 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
566 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
567 #         -G Xcode
568 #
569 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
570
571 #-----------------------------------------------------------------------------
572 #Platform specifics
573
574 if(UNIX AND NOT APPLE)
575         macro(find_package_wrapper)
576                 string(TOUPPER ${ARGV0} _NAME_UPPER)
577                 if(WITH_STATIC_LIBS)
578                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
579                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
580                 endif()
581                 find_package(${ARGV})
582                 if(WITH_STATIC_LIBS)
583                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
584                         unset(_cmake_find_library_suffixes_back)
585                 endif()
586         endmacro()
587
588         find_package_wrapper(JPEG REQUIRED)
589         find_package_wrapper(PNG REQUIRED)
590         find_package_wrapper(ZLIB REQUIRED)
591         find_package_wrapper(Freetype REQUIRED)
592
593         if(WITH_PYTHON)
594                 # No way to set py34. remove for now.
595                 # find_package(PythonLibs)
596
597                 # Use our own instead, since wothout py is such a rare case,
598                 # require this package
599                 # XXX Linking errors with debian static python :/
600 #               find_package_wrapper(PythonLibsUnix REQUIRED)
601                 find_package(PythonLibsUnix REQUIRED)
602         endif()
603
604         if(WITH_IMAGE_OPENEXR)
605                 find_package_wrapper(OpenEXR)  # our own module
606                 if(NOT OPENEXR_FOUND)
607                         set(WITH_IMAGE_OPENEXR OFF)
608                 endif()
609         endif()
610
611         if(WITH_IMAGE_OPENJPEG)
612                 find_package_wrapper(OpenJPEG)
613                 if(NOT OPENJPEG_FOUND)
614                         set(WITH_IMAGE_OPENJPEG OFF)
615                 endif()
616         endif()
617
618         if(WITH_IMAGE_TIFF)
619                 # XXX Linking errors with debian static tiff :/
620 #               find_package_wrapper(TIFF)
621                 find_package(TIFF)
622                 if(NOT TIFF_FOUND)
623                         set(WITH_IMAGE_TIFF OFF)
624                 endif()
625         endif()
626
627         # Audio IO
628         if(WITH_OPENAL)
629                 find_package_wrapper(OpenAL)
630                 if(NOT OPENAL_FOUND)
631                         set(WITH_OPENAL OFF)
632                 endif()
633         endif()
634
635         if(WITH_SDL)
636                 find_package_wrapper(SDL)
637                 mark_as_advanced(
638                         SDLMAIN_LIBRARY
639                         SDL_INCLUDE_DIR
640                         SDL_LIBRARY
641                         SDL_LIBRARY_TEMP
642                 )
643                 # unset(SDLMAIN_LIBRARY CACHE)
644                 if(NOT SDL_FOUND)
645                         set(WITH_SDL OFF)
646                 endif()
647         endif()
648
649         if(WITH_JACK)
650                 find_package_wrapper(Jack)
651                 if(NOT JACK_FOUND)
652                         set(WITH_JACK OFF)
653                 endif()
654         endif()
655
656         # Codecs
657         if(WITH_CODEC_SNDFILE)
658                 find_package_wrapper(SndFile)
659                 if(NOT SNDFILE_FOUND)
660                         set(WITH_CODEC_SNDFILE OFF)
661                 endif()
662         endif()
663
664         if(WITH_CODEC_FFMPEG)
665                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
666                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
667
668                 mark_as_advanced(FFMPEG)
669
670                 # lame, but until we have proper find module for ffmpeg
671                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
672                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
673                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
674                 endif()
675                 # end lameness
676
677                 mark_as_advanced(FFMPEG_LIBRARIES)
678                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
679                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
680         endif()
681
682         if(WITH_FFTW3)
683                 find_package_wrapper(Fftw3)
684                 if(NOT FFTW3_FOUND)
685                         set(WITH_FFTW3 OFF)
686                 endif()
687         endif()
688
689         if(WITH_OPENCOLLADA)
690                 find_package_wrapper(OpenCOLLADA)
691                 if(OPENCOLLADA_FOUND)
692                         find_package_wrapper(XML2)
693                         find_package_wrapper(PCRE)
694                 else()
695                         set(WITH_OPENCOLLADA OFF)
696                 endif()
697         endif()
698
699         if(WITH_MEM_JEMALLOC)
700                 find_package_wrapper(JeMalloc)
701                 if(NOT JEMALLOC_FOUND)
702                         set(WITH_MEM_JEMALLOC OFF)
703                 endif()
704         endif()
705
706         if(WITH_INPUT_NDOF)
707                 find_package_wrapper(Spacenav)
708                 if(NOT SPACENAV_FOUND)
709                         set(WITH_INPUT_NDOF OFF)
710                 endif()
711
712                 # use generic names within blenders buildsystem.
713                 if(SPACENAV_FOUND)
714                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
715                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
716                 endif()
717         endif()
718
719         if(WITH_BOOST)
720                 # uses in build instructions to override include and library variables
721                 if(NOT BOOST_CUSTOM)
722                         if(WITH_STATIC_LIBS)
723                                 set(Boost_USE_STATIC_LIBS ON)
724                         endif()
725                         set(Boost_USE_MULTITHREADED ON)
726                         set(__boost_packages filesystem regex system thread date_time)
727                         if(WITH_INTERNATIONAL)
728                                 list(APPEND __boost_packages locale)
729                         endif()
730                         if(WITH_CYCLES_NETWORK)
731                                 list(APPEND __boost_packages serialization)
732                         endif()
733                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
734                         if(NOT Boost_FOUND)
735                                 # try to find non-multithreaded if -mt not found, this flag
736                                 # doesn't matter for us, it has nothing to do with thread
737                                 # safety, but keep it to not disturb build setups
738                                 set(Boost_USE_MULTITHREADED OFF)
739                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
740                         endif()
741                         unset(__boost_packages)
742                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
743                                 find_package(IcuLinux)
744                         endif()
745                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
746                 endif()
747
748                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
749                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
750                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
751                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
752         endif()
753
754         if(WITH_OPENIMAGEIO)
755                 find_package_wrapper(OpenImageIO)
756
757                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
758                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
759                 set(OPENIMAGEIO_DEFINITIONS "")
760
761                 if(WITH_IMAGE_TIFF)
762                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
763                 endif()
764                 if(WITH_IMAGE_OPENEXR)
765                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
766                 endif()
767
768                 if(NOT OPENIMAGEIO_FOUND)
769                         set(WITH_OPENIMAGEIO OFF)
770                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
771                 endif()
772         endif()
773
774         if(WITH_OPENCOLORIO)
775                 find_package_wrapper(OpenColorIO)
776
777                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
778                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
779                 set(OPENCOLORIO_DEFINITIONS)
780
781                 if(NOT OPENCOLORIO_FOUND)
782                         set(WITH_OPENCOLORIO OFF)
783                         message(STATUS "OpenColorIO not found")
784                 endif()
785         endif()
786
787         # XXX Maybe most of this section should go into an llvm module?
788         if(WITH_LLVM)
789                 # Set llvm version if not specified
790                 if(NOT LLVM_VERSION)
791                         set(LLVM_VERSION "3.0")
792                 endif()
793
794                 if(LLVM_DIRECTORY)
795                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
796                         if(NOT LLVM_CONFIG)
797                                 find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
798                         endif()
799                 else()
800                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
801                         if(NOT LLVM_CONFIG)
802                                 find_program(LLVM_CONFIG llvm-config)
803                         endif()
804                 endif()
805
806                 if(NOT DEFINED LLVM_VERSION)
807                         execute_process(COMMAND ${LLVM_CONFIG} --version
808                                                         OUTPUT_VARIABLE LLVM_VERSION
809                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
810                         set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
811                 endif()
812                 if(NOT DEFINED LLVM_DIRECTORY)
813                         execute_process(COMMAND ${LLVM_CONFIG} --prefix
814                                                         OUTPUT_VARIABLE LLVM_DIRECTORY
815                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
816                         set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
817                 endif()
818                 if(NOT DEFINED LLVM_LIBPATH)
819                         execute_process(COMMAND ${LLVM_CONFIG} --libdir
820                                                         OUTPUT_VARIABLE LLVM_LIBPATH
821                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
822                         set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
823                 endif()
824
825                 if(LLVM_STATIC)
826                         find_library(LLVM_LIBRARY
827                                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
828                                      PATHS ${LLVM_LIBPATH})
829                 else()
830                         find_library(LLVM_LIBRARY
831                                      NAMES LLVM-${LLVM_VERSION}
832                                      PATHS ${LLVM_LIBPATH})
833                 endif()
834
835
836                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
837                         if(LLVM_STATIC)
838                                 # if static LLVM libraries were requested, use llvm-config to generate
839                                 # the list of what libraries we need, and substitute that in the right
840                                 # way for LLVM_LIBRARY.
841                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
842                                                 OUTPUT_VARIABLE LLVM_LIBRARY
843                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
844                                 string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
845                         endif()
846                 else()
847                         message(FATAL_ERROR "LLVM not found.")
848                 endif()
849
850                 # Fix for conflict with Mesa llvmpipe
851                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
852         endif()
853
854         if(WITH_CYCLES_OSL)
855                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
856         
857                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
858         
859                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
860                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
861                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
862                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
863                 # otherwise LLVM is missing the osl_allocate_closure_component function
864                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
865                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
866                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
867         
868                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
869                         set(OSL_FOUND TRUE)
870                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
871                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
872                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
873                 else()
874                         message(STATUS "OSL not found")
875                 endif()
876         endif()
877
878         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
879         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread")
880
881         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
882                 find_package(X11 REQUIRED)
883                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
884                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
885
886                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
887
888                 if(WITH_X11_XINPUT)
889                         if(X11_Xinput_LIB)
890                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
891                         else()
892                                 set(WITH_X11_XINPUT OFF)
893                         endif()
894                 endif()
895
896                 if(WITH_X11_XF86VMODE)
897                         # XXX, why dont cmake make this available?
898                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
899                         mark_as_advanced(X11_Xxf86vmode_LIB)
900                         if(X11_Xxf86vmode_LIB)
901                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
902                         else()
903                                 set(WITH_X11_XF86VMODE OFF)
904                         endif()
905                 endif()
906         endif()
907
908         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
909                 if(NOT WITH_PYTHON_MODULE)
910                         # binreloc is linux only
911                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
912                         set(WITH_BINRELOC ON)
913                 endif()
914         endif()
915
916         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
917
918         # lfs on glibc, all compilers should use
919         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
920
921         # GNU Compiler
922         if(CMAKE_COMPILER_IS_GNUCC)
923                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
924         # CLang is the same as GCC for now.
925         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
926                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
927         # Solaris CC
928         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
929                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
930                 
931         # Intel C++ Compiler
932         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
933                 # think these next two are broken
934                 find_program(XIAR xiar)
935                 if(XIAR)
936                         set(CMAKE_AR "${XIAR}")
937                 endif()
938                 mark_as_advanced(XIAR)
939
940                 find_program(XILD xild)
941                 if(XILD)
942                         set(CMAKE_LINKER "${XILD}")
943                 endif()
944                 mark_as_advanced(XILD)
945
946                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
947                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
948
949                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
950                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
951                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
952         endif()
953
954 elseif(WIN32)
955
956         add_definitions(-DWIN32)
957
958         if(MSVC)
959
960                 # drop support for older MSVC
961                 if(MSVC_VERSION VERSION_LESS 1800)
962                         message(FATAL_ERROR "MSVC versions older then 2013 are no longer supported")
963                 endif()
964
965                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
966
967                 # MSVC11 SDL is not hard linked to dxguid.lib
968                 if(MSVC11 AND WITH_SDL)
969                         set(PLATFORM_LINKLIBS ${PLATFORM_LINKLIBS} dxguid)
970                 endif()
971
972                 add_definitions(
973                         -D_CRT_NONSTDC_NO_DEPRECATE
974                         -D_CRT_SECURE_NO_DEPRECATE
975                         -D_SCL_SECURE_NO_DEPRECATE
976                         -D_CONSOLE
977                         -D_LIB
978                 )
979
980                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
981                 if(NOT MSVC_VERSION VERSION_LESS 1700)
982                         add_definitions(-D_ALLOW_KEYWORD_MACROS)
983                 endif()
984
985                 if(CMAKE_CL_64)
986                         # We want to support Vista level ABI for x64
987                         if(NOT MSVC_VERSION VERSION_LESS 1700)
988                                 add_definitions(-D_WIN32_WINNT=0x600)
989                         endif()
990                 endif()
991
992                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
993                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
994
995                 if(CMAKE_CL_64)
996                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
997                 else()
998                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
999                 endif()
1000                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1001                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1002                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1003                 if(CMAKE_CL_64)
1004                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1005                 else()
1006                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1007                 endif()
1008                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1009                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1010                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1011
1012                 # most msvc warnings are C & C++
1013                 set(_WARNINGS
1014                         # warning level:
1015                         "/W3"
1016                         "/w34062"  # switch statement contains 'default' but no 'case' labels
1017                         # disable:
1018                         "/wd4018"  # signed/unsigned mismatch
1019                         "/wd4065"  # switch statement contains 'default' but no 'case' labels
1020                         "/wd4127"  # conditional expression is constant
1021                         "/wd4181"  # qualifier applied to reference type; ignored
1022                         "/wd4200"  # zero-sized array in struct/union
1023                         "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1024                         "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1025                         "/wd4305"  # truncation from 'type1' to 'type2'
1026                         "/wd4800"  # forcing value to bool 'true' or 'false'
1027                         # errors:
1028                         "/we4013"  # 'function' undefined; assuming extern returning int
1029                         "/we4431"  # missing type specifier - int assumed
1030                 )
1031
1032                 string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1033                 set(C_WARNINGS "${_WARNINGS}")
1034                 set(CXX_WARNINGS "${_WARNINGS}")
1035                 unset(_WARNINGS)
1036
1037                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1038
1039                 # MSVC only, Mingw doesnt need
1040                 if(CMAKE_CL_64)
1041                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1042                 else()
1043                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1044                 endif()
1045
1046                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1047
1048                 if(NOT DEFINED LIBDIR)
1049                         # Setup 64bit and 64bit windows systems
1050                         if(CMAKE_CL_64)
1051                                 message(STATUS "64 bit compiler detected.")
1052                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/win64)
1053                         else()
1054                                 message(STATUS "32 bit compiler detected.")
1055                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/windows)
1056                         endif()
1057                         if(MSVC12)
1058                                 message(STATUS "Visual C++ 2013 detected.")
1059                                 set(LIBDIR ${LIBDIR_BASE}_vc12)
1060                         elseif(MSVC11)
1061                                 message(STATUS "Visual C++ 2012 detected.")
1062                                 set(LIBDIR ${LIBDIR_BASE}_vc11)
1063                         else()
1064                                 set(LIBDIR ${LIBDIR_BASE})
1065                         endif()
1066                 else()
1067                         message(STATUS using LIBDIR  ${LIBDIR})
1068                 endif()
1069
1070                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1071                 FILE(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1072                 FOREACH(child ${children})
1073                 IF(IS_DIRECTORY ${LIBDIR}/${child})
1074                         LIST(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1075                 ENDIF()
1076                 ENDFOREACH()
1077
1078                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1079                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1080                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1081                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1082                 set(ZLIB_DIR ${LIBDIR}/zlib)
1083                 find_package(zlib) # we want to find before finding things that depend on it like png
1084
1085
1086                 find_package(png)
1087                 if(NOT PNG_FOUND)
1088                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1089                         message(WARNING "Using HARDCODED libpng locations")
1090                         set(PNG_LIBRARIES libpng)
1091                         set(PNG "${LIBDIR}/png")
1092                         set(PNG_INCLUDE_DIR "${PNG}/include")
1093                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1094                 endif()
1095
1096                 find_package(jpeg REQUIRED)
1097
1098                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1099                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1100
1101                 set(FREETYPE ${LIBDIR}/freetype)
1102                 set(FREETYPE_INCLUDE_DIRS
1103                         ${LIBDIR}/freetype/include
1104                         ${LIBDIR}/freetype/include/freetype2
1105                 )
1106                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1107                 find_package(freetype REQUIRED)
1108
1109                 if(WITH_FFTW3)
1110                         set(FFTW3 ${LIBDIR}/fftw3)
1111                         set(FFTW3_LIBRARIES libfftw)
1112                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1113                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1114                 endif()
1115
1116                 if(WITH_OPENCOLLADA)
1117                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1118
1119                         set(OPENCOLLADA_INCLUDE_DIRS
1120                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1121                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1122                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1123                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1124                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1125                         )
1126
1127                         set(OPENCOLLADA_LIBRARIES
1128                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1129                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1130                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1131                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1132                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1133                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1134                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1135                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1136                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1137                                 ${OPENCOLLADA}/lib/opencollada/UTF.lib
1138                         )
1139                         set(PCRE_LIBRARIES
1140                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1141                         )
1142                 endif()
1143
1144                 if(WITH_CODEC_FFMPEG)
1145                         set(FFMPEG_INCLUDE_DIRS
1146                                 ${LIBDIR}/ffmpeg/include
1147                                 ${LIBDIR}/ffmpeg/include/msvc
1148                         )
1149                         find_package(FFMPEG)
1150                         if(NOT FFMPEG_FOUND)
1151                                 message(WARNING "Using HARDCODED ffmpeg locations")
1152                                 # MSVC11 FFMPEG libs are newer
1153                                 if(MSVC11)
1154                                         set(FFMPEG_LIBRARY_VERSION 54)
1155                                         set(FFMPEG_LIBRARY_VERSION_AVU 52)
1156                                 else()
1157                                         set(FFMPEG_LIBRARY_VERSION 55)
1158                                         set(FFMPEG_LIBRARY_VERSION_AVU 52)
1159                                 endif()
1160                                 set(FFMPEG_LIBRARIES
1161                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1162                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1163                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1164                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1165                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1166                                         )
1167                         endif()
1168                 endif()
1169
1170                 if(WITH_IMAGE_OPENEXR)
1171                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1172                         set(OPENEXR_VERSION "2.1")
1173                         find_package(OPENEXR REQUIRED)
1174                         if(NOT OPENEXR_FOUND)
1175                         message(WARNING "Using HARDCODED OpenEXR locations")
1176                         set(OPENEXR ${LIBDIR}/openexr)
1177                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1178                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1179                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1180                         set(OPENEXR_LIBRARIES
1181                                 ${OPENEXR_LIBPATH}/Iex.lib
1182                                 ${OPENEXR_LIBPATH}/Half.lib
1183                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1184                                 ${OPENEXR_LIBPATH}/Imath.lib
1185                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1186                         )
1187                         endif(NOT OPENEXR_FOUND)
1188                 endif()
1189
1190                 if(WITH_IMAGE_TIFF)
1191                 # Try to find tiff first then complain and set static and maybe wrong paths
1192                 find_package(TIFF)
1193                 if(NOT TIFF_FOUND)
1194                         message(WARNING "Using HARDCODED libtiff locations")
1195                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1196                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1197                 endif()
1198                 endif()
1199
1200                 if(WITH_JACK)
1201                         set(JACK_INCLUDE_DIRS
1202                                 ${LIBDIR}/jack/include/jack
1203                                 ${LIBDIR}/jack/include
1204                         )
1205                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1206                 endif()
1207
1208                 if(WITH_PYTHON)
1209                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1210
1211                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1212                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1213                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1214                         unset(_PYTHON_VERSION_NO_DOTS)
1215
1216                         # Shared includes for both vc2008 and vc2010
1217                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1218
1219                         # uncached vars
1220                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1221                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1222                 endif()
1223
1224                 if(WITH_BOOST)
1225                         if(WITH_CYCLES_OSL)
1226                                 set(boost_extra_libs wave)
1227                         endif(WITH_CYCLES_OSL)
1228                         if(WITH_INTERNATIONAL)
1229                                 list(APPEND boost_extra_libs locale)
1230                         endif(WITH_INTERNATIONAL)
1231                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1232                         IF(NOT Boost_FOUND)
1233                                 message(WARNING "USING HARDCODED boost locations")
1234                                 set(BOOST ${LIBDIR}/boost)
1235                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1236                                 if(MSVC12)
1237                                         set(BOOST_LIBPATH ${BOOST}/lib)
1238                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1239                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1240                                 elseif(MSVC11)
1241                                         set(BOOST_LIBPATH ${BOOST}/lib)
1242                                         set(BOOST_POSTFIX "vc110-mt-s-1_53.lib")
1243                                         set(BOOST_DEBUG_POSTFIX "vc110-mt-sgd-1_53.lib")
1244                                 else()
1245                                         set(BOOST_LIBPATH ${BOOST}/lib)
1246                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1247                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1248                                 endif()
1249                                 set(BOOST_LIBRARIES
1250                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1251                                         optimized libboost_regex-${BOOST_POSTFIX}
1252                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1253                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1254                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1255                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1256                                 if(WITH_CYCLES_OSL)
1257                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1258                                                 optimized libboost_wave-${BOOST_POSTFIX}
1259                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1260                                 endif()
1261                                 if(WITH_INTERNATIONAL)
1262                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1263                                                 optimized libboost_locale-${BOOST_POSTFIX}
1264                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1265                                 endif()
1266                         else() # we found boost using find_package
1267                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1268                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1269                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1270                         endif()
1271                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1272                 endif()
1273                         
1274                 if(WITH_OPENIMAGEIO)
1275                         find_package(OpenImageIO)
1276                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1277                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1278                         set(OPENIMAGEIO_LIBRARIES optimized OpenImageIO debug OpenImageIO_d)
1279                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1280                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1281                 endif()
1282
1283                 if(WITH_LLVM)
1284                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1285                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_DIRECTORY}/lib/*.lib)
1286
1287                         if(EXISTS ${LLVM_DIRECTORY}/debug/lib)
1288                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1289                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1290                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1291                                 endforeach(LLVM_OPTIMIZED_LIB)
1292                         
1293                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_DIRECTORY}/debug/lib/*.lib)
1294
1295                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1296                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1297                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1298                                 endforeach(LLVM_DEBUG_LIB)
1299
1300                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1301                         else()
1302                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1303                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1304                         endif()
1305                         
1306                 endif()
1307         
1308                 if(WITH_OPENCOLORIO)
1309                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1310                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1311                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1312                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1313                         set(OPENCOLORIO_DEFINITIONS)
1314                 endif()
1315                 
1316
1317                 if(WITH_MOD_CLOTH_ELTOPO)
1318                         set(LAPACK ${LIBDIR}/lapack)
1319                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1320                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1321                         set(LAPACK_LIBRARIES
1322                                 ${LIBDIR}/lapack/lib/libf2c.lib
1323                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1324                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1325                         )
1326                 endif()
1327
1328                 # used in many places so include globally, like OpenGL
1329                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1330
1331         elseif(CMAKE_COMPILER_IS_GNUCC)
1332                 # keep GCC specific stuff here
1333                 include(CheckCSourceCompiles)
1334                 # Setup 64bit and 64bit windows systems
1335                 CHECK_C_SOURCE_COMPILES("
1336                         #ifndef __MINGW64__
1337                         #error
1338                         #endif
1339                         int main(void) { return 0; }
1340                         " 
1341                         WITH_MINGW64)
1342                 
1343                 if(WITH_MINGW64)
1344                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1345                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1346                 else()
1347                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1348                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1349                         
1350                         if(WITH_RAYOPTIMIZATION)
1351                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1352                         endif()
1353                 endif()
1354                 
1355                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1356                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1357
1358                 if(WITH_MINGW64)
1359                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1360                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1361                         
1362                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1363                 endif()
1364
1365                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1366
1367                 add_definitions(-DFREE_WINDOWS)
1368
1369                 set(PNG "${LIBDIR}/png")
1370                 set(PNG_INCLUDE_DIR "${PNG}/include")
1371                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1372
1373                 if(WITH_MINGW64)
1374                         set(JPEG_LIBRARIES jpeg)
1375                 else()
1376                         set(JPEG_LIBRARIES libjpeg)
1377                 endif()
1378                 set(PNG_LIBRARIES png)
1379
1380                 set(ZLIB ${LIBDIR}/zlib)
1381                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1382                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1383                 set(ZLIB_LIBRARIES z)
1384
1385                 set(JPEG "${LIBDIR}/jpeg")
1386                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1387                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1388                 
1389                 # comes with own pthread library
1390                 if(NOT WITH_MINGW64)
1391                         set(PTHREADS ${LIBDIR}/pthreads)
1392                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1393                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1394                         set(PTHREADS_LIBRARIES pthreadGC2)
1395                 endif()
1396                 
1397                 set(FREETYPE ${LIBDIR}/freetype)
1398                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1399                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1400                 set(FREETYPE_LIBRARY freetype)
1401
1402                 if(WITH_FFTW3)
1403                         set(FFTW3 ${LIBDIR}/fftw3)
1404                         set(FFTW3_LIBRARIES fftw3)
1405                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1406                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1407                 endif()
1408
1409                 if(WITH_OPENCOLLADA)
1410                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1411                         set(OPENCOLLADA_INCLUDE_DIRS
1412                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1413                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1414                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1415                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1416                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1417                         )
1418                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1419                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1420                         set(PCRE_LIBRARIES pcre)
1421                 endif()
1422
1423                 if(WITH_CODEC_FFMPEG)
1424                         set(FFMPEG ${LIBDIR}/ffmpeg)
1425                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1426                         if(WITH_MINGW64)
1427                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1428                         else()
1429                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1430                         endif()
1431                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1432                 endif()
1433
1434                 if(WITH_IMAGE_OPENEXR)
1435                         set(OPENEXR ${LIBDIR}/openexr)
1436                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1437                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1438                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1439                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1440                 endif()
1441
1442                 if(WITH_IMAGE_TIFF)
1443                         set(TIFF ${LIBDIR}/tiff)
1444                         set(TIFF_LIBRARY tiff)
1445                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1446                         set(TIFF_LIBPATH ${TIFF}/lib)
1447                 endif()
1448
1449                 if(WITH_JACK)
1450                         set(JACK ${LIBDIR}/jack)
1451                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1452                         set(JACK_LIBRARIES jack)
1453                         set(JACK_LIBPATH ${JACK}/lib)
1454
1455                         # TODO, gives linking errors, force off
1456                         set(WITH_JACK OFF)
1457                 endif()
1458
1459                 if(WITH_PYTHON)
1460                         # normally cached but not since we include them with blender
1461                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1462                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1463                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1464                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1465                         unset(_PYTHON_VERSION_NO_DOTS)
1466
1467                         # uncached vars
1468                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1469                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1470                 endif()
1471
1472                 if(WITH_BOOST)
1473                         set(BOOST ${LIBDIR}/boost)
1474                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1475                         if(WITH_MINGW64)
1476                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1477                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1478                         else()
1479                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1480                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1481                         endif()
1482                         set(BOOST_LIBRARIES
1483                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1484                                 boost_regex-${BOOST_POSTFIX}
1485                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1486                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1487                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1488                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1489                         if(WITH_INTERNATIONAL)
1490                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1491                                         optimized boost_locale-${BOOST_POSTFIX}
1492                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1493                         endif()
1494                         if(WITH_CYCLES_OSL)
1495                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1496                                         optimized boost_wave-${BOOST_POSTFIX}
1497                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1498                         endif()
1499                         set(BOOST_LIBPATH ${BOOST}/lib)
1500                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1501                 endif()
1502                         
1503                 if(WITH_OPENIMAGEIO)
1504                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1505                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1506                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1507                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1508                         set(OPENIMAGEIO_DEFINITIONS "")
1509                 endif()
1510                 
1511                 if(WITH_LLVM)
1512                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1513                         set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
1514                         # Explicitly set llvm lib order.
1515                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1516                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1517                                 LLVMAsmParser LLVMAsmPrinter
1518                                 LLVMBitReader LLVMBitWriter
1519                                 LLVMDebugInfo LLVMExecutionEngine
1520                                 LLVMInstCombine LLVMInstrumentation
1521                                 LLVMInterpreter LLVMJIT
1522                                 LLVMLinker LLVMMC
1523                                 LLVMMCDisassembler LLVMMCJIT
1524                                 LLVMMCParser LLVMObject
1525                                 LLVMRuntimeDyld 
1526                                 LLVMSupport
1527                                 LLVMTableGen LLVMTarget
1528                                 LLVMTransformUtils LLVMVectorize
1529                                 LLVMX86AsmParser LLVMX86AsmPrinter
1530                                 LLVMX86CodeGen LLVMX86Desc
1531                                 LLVMX86Disassembler LLVMX86Info
1532                                 LLVMX86Utils LLVMipa
1533                                 LLVMipo LLVMCore)
1534                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1535                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
1536                 endif()
1537                 
1538                 if(WITH_OPENCOLORIO)
1539                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1540                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1541                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1542                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1543                         set(OPENCOLORIO_DEFINITIONS)
1544                 endif()
1545
1546                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1547
1548                 ## DISABLE - causes linking errors 
1549                 ## for re-distribution, so users dont need mingw installed
1550                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1551
1552         endif()
1553         
1554         # Things common to both mingw and MSVC  should go here
1555
1556         set(WINTAB_INC ${LIBDIR}/wintab/include)
1557
1558         if(WITH_OPENAL)
1559                 set(OPENAL ${LIBDIR}/openal)
1560                 set(OPENALDIR ${LIBDIR}/openal)
1561                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1562                 if(MSVC11 OR MSVC12)
1563                         set(OPENAL_LIBRARY openal32)
1564                 else()
1565                         set(OPENAL_LIBRARY wrap_oal)
1566                 endif()
1567                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1568         endif()
1569
1570         if(WITH_CODEC_SNDFILE)
1571                 set(SNDFILE ${LIBDIR}/sndfile)
1572                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1573                 set(SNDFILE_LIBRARIES libsndfile-1)
1574                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1575         endif()
1576
1577         if(WITH_SDL)
1578                 set(SDL ${LIBDIR}/sdl)
1579                 set(SDL_INCLUDE_DIR ${SDL}/include)
1580                 set(SDL_LIBRARY SDL)
1581                 set(SDL_LIBPATH ${SDL}/lib)
1582         endif()
1583
1584         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1585                 add_definitions(-D__SSE__ -D__MMX__)
1586         endif()
1587
1588         if(WITH_CYCLES_OSL)
1589                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1590         
1591                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1592                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1593                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1594                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1595                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1596                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1597                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1598                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1599                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1600         
1601                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1602                         set(OSL_FOUND TRUE)
1603                 else()
1604                         message(STATUS "OSL not found")
1605                 endif()
1606         endif()
1607
1608 elseif(APPLE)
1609
1610         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1611                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1612         endif()
1613
1614         if(WITH_LIBS10.5)
1615                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1616         else()
1617                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1618                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1619                 else()
1620                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1621                 endif()
1622         endif()
1623
1624
1625         if(WITH_OPENAL)
1626                 find_package(OpenAL)
1627                 if(OPENAL_FOUND)
1628                         set(WITH_OPENAL ON)
1629                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1630                 else()
1631                         set(WITH_OPENAL OFF)
1632                 endif()
1633         endif()
1634
1635         if(WITH_JACK)
1636                 find_library(JACK_FRAMEWORK
1637                         NAMES jackmp
1638                 )
1639                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1640                 if(NOT JACK_FRAMEWORK)
1641                         set(WITH_JACK OFF)
1642                 endif()
1643         endif()
1644
1645         if(WITH_CODEC_SNDFILE)
1646                 set(SNDFILE ${LIBDIR}/sndfile)
1647                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1648                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1649                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1650         endif()
1651
1652         if(WITH_PYTHON)
1653                 # we use precompiled libraries for py 3.4 and up by default
1654                 set(PYTHON_VERSION 3.4)
1655                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1656                         # normally cached but not since we include them with blender
1657                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1658                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1659                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1660                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1661                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1662                 else()
1663                         # module must be compiled against Python framework
1664                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1665                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1666                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1667                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1668                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1669                 endif()
1670                 
1671                 # uncached vars
1672                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1673                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1674         endif()
1675
1676         if(WITH_FFTW3)
1677                 set(FFTW3 ${LIBDIR}/fftw3)
1678                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1679                 set(FFTW3_LIBRARIES fftw3)
1680                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1681         endif()
1682
1683         set(PNG_LIBRARIES png)
1684         set(JPEG_LIBRARIES jpeg)
1685
1686         set(ZLIB /usr)
1687         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1688         set(ZLIB_LIBRARIES z bz2)
1689
1690         set(FREETYPE ${LIBDIR}/freetype)
1691         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1692         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1693         set(FREETYPE_LIBRARY freetype)
1694
1695         if(WITH_IMAGE_OPENEXR)
1696                 set(OPENEXR ${LIBDIR}/openexr)
1697                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1698                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1699                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1700                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1701         endif()
1702
1703         if(WITH_CODEC_FFMPEG)
1704                 set(FFMPEG ${LIBDIR}/ffmpeg)
1705                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1706                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1707                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1708                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1709         endif()
1710
1711         find_library(SYSTEMSTUBS_LIBRARY
1712                 NAMES
1713                 SystemStubs
1714                 PATHS
1715         )
1716         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1717         if(SYSTEMSTUBS_LIBRARY)
1718                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1719         else()
1720                 set(PLATFORM_LINKLIBS stdc++)
1721         endif()
1722
1723         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1724         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1725         if(WITH_CODEC_QUICKTIME)
1726                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1727                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1728                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1729                         # libSDL still needs 32bit carbon quicktime
1730                 endif()
1731         endif()
1732
1733         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1734         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1735         if(WITH_INPUT_NDOF)
1736                 # This thread it *should* work and check the framework - campbell
1737                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1738                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1739                         NAMES 3DconnexionClient
1740                 )
1741                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1742                         set(WITH_INPUT_NDOF OFF)
1743                 endif()
1744
1745                 if(WITH_INPUT_NDOF)
1746                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1747                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1748                 endif()
1749         endif()
1750
1751         if(WITH_JACK)
1752                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1753         endif()
1754         
1755         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1756                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1757         endif()
1758         
1759         if(WITH_OPENCOLLADA)
1760                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1761
1762                 set(OPENCOLLADA_INCLUDE_DIRS
1763                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1764                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1765                         ${LIBDIR}/opencollada/include/COLLADAFramework
1766                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1767                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1768                 )
1769
1770                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1771                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1772                 # pcre is bundled with openCollada
1773                 #set(PCRE ${LIBDIR}/pcre)
1774                 #set(PCRE_LIBPATH ${PCRE}/lib)
1775                 set(PCRE_LIBRARIES pcre)
1776                 #libxml2 is used
1777                 #set(EXPAT ${LIBDIR}/expat)
1778                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1779                 set(EXPAT_LIB)
1780         endif()
1781
1782         if(WITH_SDL)
1783                 set(SDL ${LIBDIR}/sdl)
1784                 set(SDL_INCLUDE_DIR ${SDL}/include)
1785                 set(SDL_LIBRARY SDL)
1786                 set(SDL_LIBPATH ${SDL}/lib)
1787         endif()
1788
1789         set(PNG "${LIBDIR}/png")
1790         set(PNG_INCLUDE_DIR "${PNG}/include")
1791         set(PNG_LIBPATH ${PNG}/lib)
1792
1793         set(JPEG "${LIBDIR}/jpeg")
1794         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1795         set(JPEG_LIBPATH ${JPEG}/lib)
1796
1797         if(WITH_IMAGE_TIFF)
1798                 set(TIFF ${LIBDIR}/tiff)
1799                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1800                 set(TIFF_LIBRARY tiff)
1801                 set(TIFF_LIBPATH ${TIFF}/lib)
1802         endif()
1803
1804         if(WITH_INPUT_NDOF)
1805                 # linker needs "-weak_framework 3DconnexionClient"
1806         endif()
1807
1808         if(WITH_BOOST)
1809                 set(BOOST ${LIBDIR}/boost)
1810                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1811                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1812                 if(WITH_INTERNATIONAL)
1813                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1814                 endif()
1815                 if(WITH_CYCLES_NETWORK)
1816                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
1817                 endif()
1818                 set(BOOST_LIBPATH ${BOOST}/lib)
1819                 set(BOOST_DEFINITIONS)
1820         endif()
1821         
1822         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
1823                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
1824         endif()
1825
1826         if(WITH_OPENIMAGEIO)
1827                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1828                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1829                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1830                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1831                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1832         endif()
1833
1834         if(WITH_OPENCOLORIO)
1835                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1836                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1837                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1838                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1839                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1840         endif()
1841
1842         if(WITH_LLVM)
1843                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1844                 set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
1845                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1846                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1847                 else()
1848                         set(LLVM_CONFIG llvm-config)
1849                 endif()
1850                 execute_process(COMMAND ${LLVM_CONFIG} --version
1851                                 OUTPUT_VARIABLE LLVM_VERSION
1852                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1853                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1854                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1855                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1856                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1857                                 OUTPUT_VARIABLE LLVM_LIBPATH
1858                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1859                 find_library(LLVM_LIBRARY
1860                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1861                              PATHS ${LLVM_LIBPATH})
1862
1863                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
1864                         if(LLVM_STATIC)
1865                                 # if static LLVM libraries were requested, use llvm-config to generate
1866                                 # the list of what libraries we need, and substitute that in the right
1867                                 # way for LLVM_LIBRARY.
1868                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1869                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1870                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1871                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1872                         endif()
1873                 else()
1874                         message(FATAL_ERROR "LLVM not found.")
1875                 endif()
1876         endif()
1877
1878         if(WITH_CYCLES_OSL)
1879                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1880         
1881                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1882                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1883                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1884                 # WARNING! depends on correct order of OSL libs linking
1885                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1886                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1887                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1888         
1889                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1890                         set(OSL_FOUND TRUE)
1891                 else()
1892                         message(STATUS "OSL not found")
1893                 endif()
1894         endif()
1895         
1896         if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
1897                 set(OPENMP_FOUND ON)
1898                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
1899                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
1900                 include_directories(${LIBDIR}/openmp/include)
1901                 LINK_DIRECTORIES(${LIBDIR}/openmp/lib)
1902                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/bin/libiomp5.dylib) # for intermediate binaries, lib id is @loader_path
1903         else()
1904                 set(OpenMP_C_FLAGS "" CACHE STRING "C compiler flags for OpenMP parallization" FORCE) # unset
1905                 set(OpenMP_CXX_FLAGS "" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE) # unset
1906         endif()
1907
1908         set(EXETYPE MACOSX_BUNDLE)
1909
1910         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1911         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1912         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1913                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
1914                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
1915                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
1916                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1917                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1918                 endif()
1919         else()
1920                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1921                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1922         endif()
1923
1924         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
1925                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
1926                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
1927         endif()
1928 endif()
1929
1930 #-----------------------------------------------------------------------------
1931 # Common.
1932
1933 if(APPLE OR WIN32)
1934         if(NOT EXISTS "${LIBDIR}/")
1935                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1936         endif()
1937 endif()
1938
1939 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
1940         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
1941 endif()
1942
1943 if(WITH_CYCLES)
1944         if(NOT WITH_OPENIMAGEIO)
1945                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1946         endif()
1947         if(NOT WITH_BOOST)
1948                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1949         endif()
1950
1951         if(WITH_CYCLES_OSL)
1952                 if(NOT WITH_LLVM)
1953                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
1954                 endif()
1955         endif()
1956 endif()
1957
1958 if(WITH_INTERNATIONAL)
1959         if(NOT WITH_BOOST)
1960                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
1961         endif()
1962 endif()
1963
1964 # See TEST_SSE_SUPPORT() for how this is defined.
1965
1966 if(WITH_RAYOPTIMIZATION)
1967         if(SUPPORT_SSE_BUILD)
1968                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1969                 add_definitions(-D__SSE__ -D__MMX__)
1970         endif()
1971         if(SUPPORT_SSE2_BUILD)
1972                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1973                 add_definitions(-D__SSE2__)
1974                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1975                         add_definitions(-D__MMX__)
1976                 endif()
1977         endif()
1978 endif()
1979
1980
1981 # set the endian define
1982 if(MSVC)
1983         # for some reason this fails on msvc
1984         add_definitions(-D__LITTLE_ENDIAN__)
1985         
1986 # OSX-Note: as we do crosscompiling with specific set architecture,
1987 # endianess-detection and autosetting is counterproductive
1988 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1989
1990 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1991         add_definitions(-D__LITTLE_ENDIAN__)
1992 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1993         add_definitions(-D__BIG_ENDIAN__)
1994         
1995 else()
1996         include(TestBigEndian)
1997         test_big_endian(_SYSTEM_BIG_ENDIAN)
1998         if(_SYSTEM_BIG_ENDIAN)
1999                 add_definitions(-D__BIG_ENDIAN__)
2000         else()
2001                 add_definitions(-D__LITTLE_ENDIAN__)
2002         endif()
2003         unset(_SYSTEM_BIG_ENDIAN)
2004 endif()
2005
2006
2007 if(WITH_IMAGE_OPENJPEG)
2008         if(WITH_SYSTEM_OPENJPEG)
2009                 # dealt with above
2010         else()
2011                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2012                 add_definitions(-DOPJ_STATIC)
2013         endif()
2014 endif()
2015
2016 if(WITH_IMAGE_REDCODE)
2017         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2018         set(REDCODE_INC ${REDCODE})
2019 endif()
2020
2021
2022 #-----------------------------------------------------------------------------
2023 # Configure OpenGL.
2024 find_package(OpenGL)
2025 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2026 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
2027 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
2028
2029 #-----------------------------------------------------------------------------
2030 # Configure OpenMP.
2031 if(WITH_OPENMP)
2032         find_package(OpenMP)
2033         if(OPENMP_FOUND)
2034                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2035                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2036
2037                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
2038                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
2039                 endif()
2040         else()
2041                 set(WITH_OPENMP OFF)
2042         endif()
2043
2044         mark_as_advanced(
2045                 OpenMP_C_FLAGS
2046                 OpenMP_CXX_FLAGS
2047         )
2048 endif()
2049
2050 #-----------------------------------------------------------------------------
2051 # Configure GLEW
2052
2053 if(WITH_SYSTEM_GLEW)
2054         find_package(GLEW)
2055
2056         if(NOT GLEW_FOUND)
2057                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
2058         endif()
2059
2060         mark_as_advanced(
2061                 GLEW_LIBRARY
2062                 GLEW_INCLUDE_PATH
2063         )
2064 else()
2065         # set(GLEW_LIBRARY "")  # unused
2066         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2067 endif()
2068
2069
2070 #-----------------------------------------------------------------------------
2071 # Configure Bullet
2072
2073 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2074         find_package(Bullet)
2075         if(NOT BULLET_FOUND)
2076                 set(WITH_BULLET OFF)
2077         endif()
2078 else()
2079         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2080         # set(BULLET_LIBRARIES "")
2081 endif()
2082
2083 #-----------------------------------------------------------------------------
2084 # Configure Python.
2085
2086 if(WITH_PYTHON_MODULE)
2087         add_definitions(-DPy_ENABLE_SHARED)
2088 endif()
2089
2090 #-----------------------------------------------------------------------------
2091 # Extra compile flags
2092
2093 if(CMAKE_COMPILER_IS_GNUCC)
2094
2095         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2096         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2097         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2098         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2099         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2100         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2101         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2102         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2103         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2104         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2105         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2106         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2107         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2108         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2109         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2110         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2111         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2112         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2113         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2114         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2115
2116         # gcc 4.2 gives annoying warnings on every file with this
2117         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2118                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2119         endif()
2120
2121         # versions before gcc4.6 give many BLI_math warnings
2122         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2123                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2124                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2125         endif()
2126
2127         # disable because it gives warnings for printf() & friends.
2128         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2129
2130         if(NOT APPLE)
2131                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2132         endif()
2133
2134         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2135         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2136         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2137         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2138         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2139         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2140         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2141         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2142
2143         # gcc 4.2 gives annoying warnings on every file with this
2144         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2145                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2146         endif()
2147
2148         # causes too many warnings
2149         if(NOT APPLE)
2150                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2151                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2152         endif()
2153
2154         # flags to undo strict flags
2155         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2156         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2157
2158         if(NOT APPLE)
2159                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2160         endif()
2161
2162 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2163
2164         # strange, clang complains these are not supported, but then yses them.
2165         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2166         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2167         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2168         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2169         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2170         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2171         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2172         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2173         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2174         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2175
2176         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2177         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2178         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2179         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2180         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.
2181         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2182         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2183
2184         # gives too many unfixable warnings
2185         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2186         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2187
2188         # flags to undo strict flags
2189         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2190         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2191
2192         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2193         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2194         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2195         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2196         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2197         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2198         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2199         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2200
2201         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2202         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2203         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2204         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2205         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2206
2207 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2208
2209         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2210         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2211         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2212
2213         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2214         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2215         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2216
2217         # disable numbered, false positives
2218         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2219         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2220
2221 endif()
2222
2223 # ensure python header is found since detection can fail, this could happen
2224 # with _any_ library but since we used a fixed python version this tends to
2225 # be most problematic.
2226 if(WITH_PYTHON)
2227         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2228                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2229                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2230                                                         "to a valid python include path. Containing "
2231                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2232         endif()
2233
2234         if(WIN32)
2235                 # pass, we have this in an archive to extract
2236         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2237                 # set but invalid
2238                 # -- disabled until we make numpy bundled with blender - campbell
2239                 if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
2240 #                       if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
2241 #                               message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
2242 #                                               "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2243 #                               set(WITH_PYTHON_INSTALL_NUMPY OFF)
2244 #                       endif()
2245                 # not set, so initialize
2246                 else()
2247                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
2248                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
2249
2250                         # re-cache
2251                         unset(PYTHON_NUMPY_PATH CACHE)
2252                         find_path(PYTHON_NUMPY_PATH
2253                           NAMES
2254                             numpy
2255                           HINTS
2256                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
2257                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
2258                           PATH_SUFFIXES
2259                             site-packages
2260                             dist-packages
2261                            NO_DEFAULT_PATH
2262                         )
2263
2264                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
2265                                 message(WARNING "'numpy' path could not be found in:\n"
2266                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
2267                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
2268                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
2269                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
2270                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2271                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
2272                         else()
2273                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
2274                         endif()
2275
2276                         unset(_PY_VER_SPLIT)
2277                         unset(_PY_VER_MAJOR)
2278                 endif()
2279         endif()
2280
2281         if(WIN32 OR APPLE)
2282                 # pass, we have this in lib/python/site-packages
2283         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2284                 if(NOT EXISTS ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests)
2285                         # gets annoying otherwise...
2286                         if(FIRST_RUN)
2287                                 message(WARNING "'requests' path could not be found in:\n"
2288                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/requests'\n"
2289                                                 "WITH_PYTHON_INSTALL_REQUESTS option will be ignored when installing python")
2290                         endif()
2291                         set(WITH_PYTHON_INSTALL_REQUESTS OFF)
2292                 endif()
2293         endif()
2294 endif()
2295
2296 if(WITH_GCC_MUDFLAP)
2297         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2298         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2299         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2300         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2301 endif()
2302
2303 # Include warnings first, so its possible to disable them with user defined flags
2304 # eg: -Wno-uninitialized
2305 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2306 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2307
2308 # defined above, platform spesific but shared names
2309 mark_as_advanced(
2310         CYCLES_OSL
2311         OSL_LIB_EXEC
2312         OSL_COMPILER
2313         OSL_LIB_COMP
2314         OSL_LIB_QUERY
2315         OSL_INCLUDES
2316 )
2317
2318 mark_as_advanced(
2319         LLVM_CONFIG
2320         LLVM_DIRECTORY
2321         LLVM_LIBRARY
2322         LLVM_VERSION
2323 )
2324
2325 #-------------------------------------------------------------------------------
2326 # Global Defines
2327
2328 # better not set includes here but this debugging option is off by default.
2329 if(WITH_CXX_GUARDEDALLOC)
2330         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2331         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2332 endif()
2333
2334 if(WITH_ASSERT_ABORT)
2335         add_definitions(-DWITH_ASSERT_ABORT)
2336 endif()
2337
2338 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2339 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2340
2341 #-----------------------------------------------------------------------------
2342 # Libraries
2343
2344 if(WITH_BLENDER OR WITH_PLAYER)
2345         add_subdirectory(source)
2346         add_subdirectory(intern)
2347         add_subdirectory(extern)
2348 elseif(WITH_CYCLES_STANDALONE)
2349         add_subdirectory(intern/cycles)
2350         if(NOT WITH_SYSTEM_GLEW)
2351                 add_subdirectory(extern/glew)
2352         endif()
2353 endif()
2354
2355 #-----------------------------------------------------------------------------
2356 # Blender Application
2357 if(WITH_BLENDER)
2358         add_subdirectory(source/creator)
2359 endif()
2360
2361
2362 #-----------------------------------------------------------------------------
2363 # Blender Player
2364 if(WITH_PLAYER)
2365         add_subdirectory(source/blenderplayer)
2366 endif()
2367
2368 #-----------------------------------------------------------------------------
2369 # CPack for generating packages
2370 include(build_files/cmake/packaging.cmake)
2371
2372
2373 #-----------------------------------------------------------------------------
2374 # Print Final Configuration
2375
2376 if(FIRST_RUN)
2377         set(_config_msg "\n* Blender Configuration *")
2378         macro(info_cfg_option
2379                 _setting)
2380                 set(_msg "   * ${_setting}")
2381                 string(LENGTH "${_msg}" _len)
2382                 while("32" GREATER "${_len}")
2383                         set(_msg "${_msg} ")
2384                          math(EXPR _len "${_len} + 1")
2385                 endwhile()
2386
2387                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2388         endmacro()
2389
2390         macro(info_cfg_text
2391                 _text)
2392                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2393
2394
2395         endmacro()
2396
2397         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2398         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2399
2400         info_cfg_text("Build Options:")
2401         info_cfg_option(WITH_GAMEENGINE)
2402         info_cfg_option(WITH_PLAYER)
2403         info_cfg_option(WITH_BULLET)
2404         info_cfg_option(WITH_IK_SOLVER)
2405         info_cfg_option(WITH_IK_ITASC)
2406         info_cfg_option(WITH_OPENCOLLADA)
2407         info_cfg_option(WITH_FFTW3)
2408         info_cfg_option(WITH_INTERNATIONAL)
2409         info_cfg_option(WITH_INPUT_NDOF)
2410         info_cfg_option(WITH_CYCLES)
2411         info_cfg_option(WITH_FREESTYLE)
2412         info_cfg_option(WITH_OPENCOLORIO)
2413
2414         info_cfg_text("Compiler Options:")
2415         info_cfg_option(WITH_BUILDINFO)
2416         info_cfg_option(WITH_OPENMP)
2417         info_cfg_option(WITH_RAYOPTIMIZATION)
2418
2419         info_cfg_text("System Options:")
2420         info_cfg_option(WITH_INSTALL_PORTABLE)
2421         info_cfg_option(WITH_X11_XF86VMODE)
2422         info_cfg_option(WITH_X11_XINPUT)
2423         info_cfg_option(WITH_MEM_JEMALLOC)
2424         info_cfg_option(WITH_MEM_VALGRIND)
2425         info_cfg_option(WITH_SYSTEM_GLEW)
2426         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2427
2428         info_cfg_text("Image Formats:")
2429         info_cfg_option(WITH_OPENIMAGEIO)
2430         info_cfg_option(WITH_IMAGE_CINEON)
2431         info_cfg_option(WITH_IMAGE_DDS)
2432         info_cfg_option(WITH_IMAGE_HDR)
2433         info_cfg_option(WITH_IMAGE_OPENEXR)
2434         info_cfg_option(WITH_IMAGE_OPENJPEG)
2435         info_cfg_option(WITH_IMAGE_REDCODE)
2436         info_cfg_option(WITH_IMAGE_TIFF)
2437
2438         info_cfg_text("Audio:")
2439         info_cfg_option(WITH_OPENAL)
2440         info_cfg_option(WITH_SDL)
2441         info_cfg_option(WITH_JACK)
2442         info_cfg_option(WITH_JACK_DYNLOAD)
2443         info_cfg_option(WITH_CODEC_AVI)
2444         info_cfg_option(WITH_CODEC_FFMPEG)
2445         info_cfg_option(WITH_CODEC_SNDFILE)
2446
2447         info_cfg_text("Compression:")
2448         info_cfg_option(WITH_LZMA)
2449         info_cfg_option(WITH_LZO)
2450
2451         info_cfg_text("Python:")
2452         info_cfg_option(WITH_PYTHON_INSTALL)
2453         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2454         info_cfg_option(WITH_PYTHON_MODULE)
2455         info_cfg_option(WITH_PYTHON_SAFETY)
2456         if(APPLE)
2457                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2458         endif()
2459
2460         info_cfg_text("Modifiers:")
2461         info_cfg_option(WITH_MOD_BOOLEAN)
2462         info_cfg_option(WITH_MOD_REMESH)
2463         info_cfg_option(WITH_MOD_FLUID)
2464         info_cfg_option(WITH_MOD_OCEANSIM)
2465
2466         info_cfg_text("Other:")
2467         info_cfg_option(WITH_OPENNL)
2468
2469         # debug
2470         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2471
2472         info_cfg_text("")
2473
2474         message("${_config_msg}")
2475 endif()