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