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