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