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