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