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