b28b74804d3601980c4359f63a3b2c6d1e36e0ca
[blender.git] / build_files / cmake / platform / platform_apple.cmake
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) 2016, Blender Foundation
18 # All rights reserved.
19 #
20 # Contributor(s): Sergey Sharybin.
21 #
22 # ***** END GPL LICENSE BLOCK *****
23
24 # Libraries configuration for Apple.
25
26 if(NOT DEFINED LIBDIR)
27         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
28 else()
29         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
30 endif()
31 if(NOT EXISTS "${LIBDIR}/")
32         message(FATAL_ERROR "Mac OSX requires pre-compiled libs at: '${LIBDIR}'")
33 endif()
34
35 if(WITH_OPENAL)
36         find_package(OpenAL)
37         if(OPENAL_FOUND)
38                 set(WITH_OPENAL ON)
39                 set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
40         else()
41                 set(WITH_OPENAL OFF)
42         endif()
43 endif()
44
45 if(WITH_ALEMBIC)
46         set(ALEMBIC ${LIBDIR}/alembic)
47         set(ALEMBIC_INCLUDE_DIR ${ALEMBIC}/include)
48         set(ALEMBIC_INCLUDE_DIRS ${ALEMBIC_INCLUDE_DIR})
49         set(ALEMBIC_LIBPATH ${ALEMBIC}/lib)
50         set(ALEMBIC_LIBRARIES Alembic)
51 endif()
52
53 if(WITH_OPENSUBDIV)
54         set(OPENSUBDIV ${LIBDIR}/opensubdiv)
55         set(OPENSUBDIV_LIBPATH ${OPENSUBDIV}/lib)
56         find_library(OSL_LIB_UTIL NAMES osdutil PATHS ${OPENSUBDIV_LIBPATH})
57         find_library(OSL_LIB_CPU NAMES osdCPU PATHS ${OPENSUBDIV_LIBPATH})
58         find_library(OSL_LIB_GPU NAMES osdGPU PATHS ${OPENSUBDIV_LIBPATH})
59         set(OPENSUBDIV_INCLUDE_DIR ${OPENSUBDIV}/include)
60         set(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
61         list(APPEND OPENSUBDIV_LIBRARIES ${OSL_LIB_UTIL} ${OSL_LIB_CPU} ${OSL_LIB_GPU})
62 endif()
63
64 if(WITH_JACK)
65         find_library(JACK_FRAMEWORK
66                 NAMES jackmp
67         )
68         set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
69         if(NOT JACK_FRAMEWORK)
70                 set(WITH_JACK OFF)
71         endif()
72 endif()
73
74 if(WITH_CODEC_SNDFILE)
75         set(SNDFILE ${LIBDIR}/sndfile)
76         set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
77         set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
78         set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
79 endif()
80
81 if(WITH_PYTHON)
82         # we use precompiled libraries for py 3.5 and up by default
83         set(PYTHON_VERSION 3.5)
84         if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
85                 # normally cached but not since we include them with blender
86                 set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
87                 set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}m")
88                 set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
89                 set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
90                 # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
91         else()
92                 # module must be compiled against Python framework
93                 set(_py_framework "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}")
94
95                 set(PYTHON_INCLUDE_DIR "${_py_framework}/include/python${PYTHON_VERSION}m")
96                 set(PYTHON_EXECUTABLE "${_py_framework}/bin/python${PYTHON_VERSION}m")
97                 set(PYTHON_LIBPATH "${_py_framework}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
98                 #set(PYTHON_LIBRARY python${PYTHON_VERSION})
99                 #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
100
101                 unset(_py_framework)
102         endif()
103
104         # uncached vars
105         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
106         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
107
108         if(NOT EXISTS "${PYTHON_EXECUTABLE}")
109                 message(FATAL_ERROR "Python executable missing: ${PYTHON_EXECUTABLE}")
110         endif()
111 endif()
112
113 if(WITH_FFTW3)
114         set(FFTW3 ${LIBDIR}/fftw3)
115         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
116         set(FFTW3_LIBRARIES fftw3)
117         set(FFTW3_LIBPATH ${FFTW3}/lib)
118 endif()
119
120 set(PNG_LIBRARIES png)
121 set(JPEG_LIBRARIES jpeg)
122
123 set(ZLIB /usr)
124 set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
125 set(ZLIB_LIBRARIES z bz2)
126
127 set(FREETYPE ${LIBDIR}/freetype)
128 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
129 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
130 set(FREETYPE_LIBRARY freetype)
131
132 if(WITH_IMAGE_OPENEXR)
133         set(OPENEXR ${LIBDIR}/openexr)
134         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
135         set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
136         set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
137         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
138 endif()
139
140 if(WITH_CODEC_FFMPEG)
141         set(FFMPEG ${LIBDIR}/ffmpeg)
142         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
143         set(FFMPEG_LIBRARIES
144                 avcodec avdevice avformat avutil
145                 mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg
146         )
147         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
148 endif()
149
150 find_library(SYSTEMSTUBS_LIBRARY
151         NAMES
152         SystemStubs
153         PATHS
154 )
155 mark_as_advanced(SYSTEMSTUBS_LIBRARY)
156 if(SYSTEMSTUBS_LIBRARY)
157         list(APPEND PLATFORM_LINKLIBS SystemStubs)
158 endif()
159
160 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
161 set(PLATFORM_LINKFLAGS
162         "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio"
163 )
164 if(WITH_CODEC_QUICKTIME)
165         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
166         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
167                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
168                 # libSDL still needs 32bit carbon quicktime
169         endif()
170 endif()
171
172 if(WITH_CXX11)
173         list(APPEND PLATFORM_LINKLIBS c++)
174 else()
175         list(APPEND PLATFORM_LINKLIBS stdc++)
176 endif()
177
178 if(WITH_JACK)
179         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
180 endif()
181
182 if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
183         # force cmake to link right framework
184         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")
185 endif()
186
187 if(WITH_OPENCOLLADA)
188         set(OPENCOLLADA ${LIBDIR}/opencollada)
189
190         set(OPENCOLLADA_INCLUDE_DIRS
191                 ${LIBDIR}/opencollada/include/COLLADAStreamWriter
192                 ${LIBDIR}/opencollada/include/COLLADABaseUtils
193                 ${LIBDIR}/opencollada/include/COLLADAFramework
194                 ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
195                 ${LIBDIR}/opencollada/include/GeneratedSaxParser
196         )
197
198         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
199         set(OPENCOLLADA_LIBRARIES
200                 OpenCOLLADASaxFrameworkLoader
201                 -lOpenCOLLADAFramework
202                 -lOpenCOLLADABaseUtils
203                 -lOpenCOLLADAStreamWriter
204                 -lMathMLSolver
205                 -lGeneratedSaxParser
206                 -lxml2 -lbuffer -lftoa
207         )
208         # Use UTF functions from collada if LLVM is not enabled
209         if(NOT WITH_LLVM)
210                 list(APPEND OPENCOLLADA_LIBRARIES -lUTF)
211         endif()
212         # pcre is bundled with openCollada
213         #set(PCRE ${LIBDIR}/pcre)
214         #set(PCRE_LIBPATH ${PCRE}/lib)
215         set(PCRE_LIBRARIES pcre)
216         #libxml2 is used
217         #set(EXPAT ${LIBDIR}/expat)
218         #set(EXPAT_LIBPATH ${EXPAT}/lib)
219         set(EXPAT_LIB)
220 endif()
221
222 if(WITH_SDL)
223         set(SDL ${LIBDIR}/sdl)
224         set(SDL_INCLUDE_DIR ${SDL}/include)
225         set(SDL_LIBRARY SDL2)
226         set(SDL_LIBPATH ${SDL}/lib)
227         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lazy_framework ForceFeedback")
228 endif()
229
230 set(PNG "${LIBDIR}/png")
231 set(PNG_INCLUDE_DIRS "${PNG}/include")
232 set(PNG_LIBPATH ${PNG}/lib)
233
234 set(JPEG "${LIBDIR}/jpeg")
235 set(JPEG_INCLUDE_DIR "${JPEG}/include")
236 set(JPEG_LIBPATH ${JPEG}/lib)
237
238 if(WITH_IMAGE_TIFF)
239         set(TIFF ${LIBDIR}/tiff)
240         set(TIFF_INCLUDE_DIR ${TIFF}/include)
241         set(TIFF_LIBRARY tiff)
242         set(TIFF_LIBPATH ${TIFF}/lib)
243 endif()
244
245 if(WITH_BOOST)
246         set(BOOST ${LIBDIR}/boost)
247         set(BOOST_INCLUDE_DIR ${BOOST}/include)
248         set(BOOST_LIBRARIES
249                 boost_date_time-mt
250                 boost_filesystem-mt
251                 boost_regex-mt
252                 boost_system-mt
253                 boost_thread-mt
254                 boost_wave-mt
255         )
256         if(WITH_INTERNATIONAL)
257                 list(APPEND BOOST_LIBRARIES boost_locale-mt)
258         endif()
259         if(WITH_CYCLES_NETWORK)
260                 list(APPEND BOOST_LIBRARIES boost_serialization-mt)
261         endif()
262         if(WITH_OPENVDB)
263                 list(APPEND BOOST_LIBRARIES boost_iostreams-mt)
264         endif()
265         set(BOOST_LIBPATH ${BOOST}/lib)
266         set(BOOST_DEFINITIONS)
267 endif()
268
269 if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
270         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
271 endif()
272
273 if(WITH_OPENIMAGEIO)
274         set(OPENIMAGEIO ${LIBDIR}/openimageio)
275         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
276         set(OPENIMAGEIO_LIBRARIES
277                 ${OPENIMAGEIO}/lib/libOpenImageIO.a
278                 ${PNG_LIBRARIES}
279                 ${JPEG_LIBRARIES}
280                 ${TIFF_LIBRARY}
281                 ${OPENEXR_LIBRARIES}
282                 ${ZLIB_LIBRARIES}
283         )
284         set(OPENIMAGEIO_LIBPATH
285                 ${OPENIMAGEIO}/lib
286                 ${JPEG_LIBPATH}
287                 ${PNG_LIBPATH}
288                 ${TIFF_LIBPATH}
289                 ${OPENEXR_LIBPATH}
290                 ${ZLIB_LIBPATH}
291         )
292         set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
293         set(OPENIMAGEIO_IDIFF "${LIBDIR}/openimageio/bin/idiff")
294 endif()
295
296 if(WITH_OPENCOLORIO)
297         set(OPENCOLORIO ${LIBDIR}/opencolorio)
298         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
299         set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
300         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
301 endif()
302
303 if(WITH_OPENVDB)
304         set(OPENVDB ${LIBDIR}/openvdb)
305         set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
306         set(TBB_INCLUDE_DIRS ${LIBDIR}/tbb/include)
307         set(TBB_LIBRARIES ${LIBDIR}/tbb/lib/libtbb.a)
308         set(OPENVDB_LIBRARIES openvdb blosc ${TBB_LIBRARIES})
309         set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
310         set(OPENVDB_DEFINITIONS)
311 endif()
312
313 if(WITH_LLVM)
314         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
315         set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
316         if(EXISTS "${LLVM_ROOT_DIR}/bin/llvm-config")
317                 set(LLVM_CONFIG "${LLVM_ROOT_DIR}/bin/llvm-config")
318         else()
319                 set(LLVM_CONFIG llvm-config)
320         endif()
321         execute_process(COMMAND ${LLVM_CONFIG} --version
322                         OUTPUT_VARIABLE LLVM_VERSION
323                         OUTPUT_STRIP_TRAILING_WHITESPACE)
324         execute_process(COMMAND ${LLVM_CONFIG} --prefix
325                         OUTPUT_VARIABLE LLVM_ROOT_DIR
326                         OUTPUT_STRIP_TRAILING_WHITESPACE)
327         execute_process(COMMAND ${LLVM_CONFIG} --libdir
328                         OUTPUT_VARIABLE LLVM_LIBPATH
329                         OUTPUT_STRIP_TRAILING_WHITESPACE)
330         find_library(LLVM_LIBRARY
331                       NAMES LLVMAnalysis # first of a whole bunch of libs to get
332                       PATHS ${LLVM_LIBPATH})
333
334         if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
335                 if(LLVM_STATIC)
336                         # if static LLVM libraries were requested, use llvm-config to generate
337                         # the list of what libraries we need, and substitute that in the right
338                         # way for LLVM_LIBRARY.
339                         execute_process(COMMAND ${LLVM_CONFIG} --libfiles
340                                         OUTPUT_VARIABLE LLVM_LIBRARY
341                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
342                         string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
343                 else()
344                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
345                 endif()
346         else()
347                 message(FATAL_ERROR "LLVM not found.")
348         endif()
349 endif()
350
351 if(WITH_CYCLES_OSL)
352         set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
353
354         find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
355         find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
356         find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
357         # WARNING! depends on correct order of OSL libs linking
358         list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
359         find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
360         find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
361
362         if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
363                 set(OSL_FOUND TRUE)
364         else()
365                 message(STATUS "OSL not found")
366                 set(WITH_CYCLES_OSL OFF)
367         endif()
368 endif()
369
370 if(WITH_OPENMP)
371         execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
372         string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
373         if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
374                 set(WITH_OPENMP OFF)
375         else() # vanilla gcc or clang_omp support OpenMP
376                 message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
377                 if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
378                         set(OPENMP_FOUND ON)
379                         set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
380                         set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
381                         include_directories(${LIBDIR}/openmp/include)
382                         link_directories(${LIBDIR}/openmp/lib)
383                         # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
384                         # They are linked also to omp lib, so we need it in builddir for runtime exexcution,
385                         # TODO: remove all unneeded dependencies from these
386
387                         # for intermediate binaries, in respect to lib ID
388                         execute_process(
389                                 COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES}
390                                 ${LIBDIR}/openmp/lib/libiomp5.dylib
391                                 ${CMAKE_BINARY_DIR}/Resources/lib/libiomp5.dylib)
392                 endif()
393         endif()
394 endif()
395
396 set(EXETYPE MACOSX_BUNDLE)
397
398 set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
399 set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
400 if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
401         set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
402         set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
403         if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
404                 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
405                 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
406         endif()
407 else()
408         set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
409         set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
410 endif()
411
412 if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
413         # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
414         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
415 endif()
416 # Get rid of eventually clashes, we export some symbols explicite as local
417 set(PLATFORM_LINKFLAGS
418         "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map"
419 )
420
421 if(WITH_CXX11)
422         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
423         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -stdlib=libc++")
424 endif()
425
426 # Suppress ranlib "has no symbols" warnings (workaround for T48250)
427 set(CMAKE_C_ARCHIVE_CREATE   "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
428 set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
429 set(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
430 set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")