Cleanup: remove contributors for CMake files
[blender.git] / build_files / cmake / platform / platform_unix.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 any *nix system including Linux and Unix.
22
23 # Detect precompiled library directory
24 if(NOT DEFINED LIBDIR)
25         set(LIBDIR_NAME ${CMAKE_SYSTEM_NAME}_${CMAKE_SYSTEM_PROCESSOR})
26         string(TOLOWER ${LIBDIR_NAME} LIBDIR_NAME)
27         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_NAME})
28 else()
29         message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
30 endif()
31
32 if(EXISTS ${LIBDIR})
33         file(GLOB LIB_SUBDIRS ${LIBDIR}/*)
34         # NOTE: Make sure "proper" compiled zlib comes first before the one
35         # which is a part of OpenCollada. They have different ABI, and we
36         # do need to use the official one.
37         set(CMAKE_PREFIX_PATH ${LIBDIR}/zlib ${LIB_SUBDIRS})
38         set(WITH_STATIC_LIBS ON)
39         set(WITH_OPENMP_STATIC ON)
40 endif()
41
42 # Wrapper to prefer static libraries
43 macro(find_package_wrapper)
44         if(WITH_STATIC_LIBS)
45                 find_package_static(${ARGV})
46         else()
47                 find_package(${ARGV})
48         endif()
49 endmacro()
50
51 find_package_wrapper(JPEG REQUIRED)
52 find_package_wrapper(PNG REQUIRED)
53 find_package_wrapper(ZLIB REQUIRED)
54 find_package_wrapper(Freetype REQUIRED)
55
56 if(WITH_LZO AND WITH_SYSTEM_LZO)
57         find_package_wrapper(LZO)
58         if(NOT LZO_FOUND)
59                 message(FATAL_ERROR "Failed finding system LZO version!")
60         endif()
61 endif()
62
63 if(WITH_SYSTEM_EIGEN3)
64         find_package_wrapper(Eigen3)
65         if(NOT EIGEN3_FOUND)
66                 message(FATAL_ERROR "Failed finding system Eigen3 version!")
67         endif()
68 endif()
69 # else values are set below for all platforms
70
71 if(WITH_PYTHON)
72         # No way to set py35, remove for now.
73         # find_package(PythonLibs)
74
75         # Use our own instead, since without py is such a rare case,
76         # require this package
77         # XXX Linking errors with debian static python :/
78 #               find_package_wrapper(PythonLibsUnix REQUIRED)
79         find_package(PythonLibsUnix REQUIRED)
80 endif()
81
82 if(WITH_IMAGE_OPENEXR)
83         find_package_wrapper(OpenEXR)  # our own module
84         if(NOT OPENEXR_FOUND)
85                 set(WITH_IMAGE_OPENEXR OFF)
86         endif()
87 endif()
88
89 if(WITH_IMAGE_OPENJPEG)
90         find_package_wrapper(OpenJPEG)
91         if(NOT OPENJPEG_FOUND)
92                 set(WITH_IMAGE_OPENJPEG OFF)
93         endif()
94 endif()
95
96 if(WITH_IMAGE_TIFF)
97         # XXX Linking errors with debian static tiff :/
98 #               find_package_wrapper(TIFF)
99         find_package(TIFF)
100         if(NOT TIFF_FOUND)
101                 set(WITH_IMAGE_TIFF OFF)
102         endif()
103 endif()
104
105 # Audio IO
106 if(WITH_SYSTEM_AUDASPACE)
107         find_package_wrapper(Audaspace)
108         if(NOT AUDASPACE_FOUND OR NOT AUDASPACE_C_FOUND)
109                 message(FATAL_ERROR "Audaspace external library not found!")
110         endif()
111 endif()
112
113 if(WITH_OPENAL)
114         find_package_wrapper(OpenAL)
115         if(NOT OPENAL_FOUND)
116                 set(WITH_OPENAL OFF)
117         endif()
118 endif()
119
120 if(WITH_SDL)
121         if(WITH_SDL_DYNLOAD)
122                 set(SDL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/sdlew/include/SDL2")
123                 set(SDL_LIBRARY)
124         else()
125                 find_package_wrapper(SDL2)
126                 if(SDL2_FOUND)
127                         # Use same names for both versions of SDL until we move to 2.x.
128                         set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
129                         set(SDL_LIBRARY "${SDL2_LIBRARY}")
130                         set(SDL_FOUND "${SDL2_FOUND}")
131                 else()
132                         find_package_wrapper(SDL)
133                 endif()
134                 mark_as_advanced(
135                         SDL_INCLUDE_DIR
136                         SDL_LIBRARY
137                 )
138                 # unset(SDLMAIN_LIBRARY CACHE)
139                 if(NOT SDL_FOUND)
140                         set(WITH_SDL OFF)
141                 endif()
142         endif()
143 endif()
144
145 if(WITH_JACK)
146         find_package_wrapper(Jack)
147         if(NOT JACK_FOUND)
148                 set(WITH_JACK OFF)
149         endif()
150 endif()
151
152 # Codecs
153 if(WITH_CODEC_SNDFILE)
154         find_package_wrapper(SndFile)
155         if(NOT LIBSNDFILE_FOUND)
156                 set(WITH_CODEC_SNDFILE OFF)
157         endif()
158 endif()
159
160 if(WITH_CODEC_FFMPEG)
161         if(EXISTS ${LIBDIR})
162                 # For precompiled lib directory, all ffmpeg dependencies are in the same folder
163                 file(GLOB ffmpeg_libs ${LIBDIR}/ffmpeg/lib/*.a ${LIBDIR}/sndfile/lib/*.a)
164                 set(FFMPEG ${LIBDIR}/ffmpeg CACHE PATH "FFMPEG Directory")
165                 set(FFMPEG_LIBRARIES ${ffmpeg_libs} ${ffmpeg_libs} CACHE STRING "FFMPEG Libraries")
166         else()
167                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
168                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
169         endif()
170
171         mark_as_advanced(FFMPEG)
172
173         # lame, but until we have proper find module for ffmpeg
174         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
175         if(EXISTS "${FFMPEG}/include/ffmpeg/")
176                 list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
177         endif()
178         # end lameness
179
180         mark_as_advanced(FFMPEG_LIBRARIES)
181         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
182 endif()
183
184 if(WITH_FFTW3)
185         find_package_wrapper(Fftw3)
186         if(NOT FFTW3_FOUND)
187                 set(WITH_FFTW3 OFF)
188         endif()
189 endif()
190
191 if(WITH_OPENCOLLADA)
192         find_package_wrapper(OpenCOLLADA)
193         if(OPENCOLLADA_FOUND)
194                 find_package_wrapper(XML2)
195                 find_package_wrapper(PCRE)
196         else()
197                 set(WITH_OPENCOLLADA OFF)
198         endif()
199 endif()
200
201 if(WITH_MEM_JEMALLOC)
202         find_package_wrapper(JeMalloc)
203         if(NOT JEMALLOC_FOUND)
204                 set(WITH_MEM_JEMALLOC OFF)
205         endif()
206 endif()
207
208 if(WITH_INPUT_NDOF)
209         find_package_wrapper(Spacenav)
210         if(SPACENAV_FOUND)
211                 # use generic names within blenders buildsystem.
212                 set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
213                 set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
214         else()
215                 set(WITH_INPUT_NDOF OFF)
216         endif()
217 endif()
218
219 if(WITH_CYCLES_OSL)
220         set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
221         if(NOT OSL_ROOT)
222                 set(OSL_ROOT ${CYCLES_OSL})
223         endif()
224         find_package_wrapper(OpenShadingLanguage)
225         if(OSL_FOUND)
226                 if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
227                         # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
228                         # otherwise LLVM is missing the osl_allocate_closure_component function
229                         set(OSL_LIBRARIES
230                                 ${OSL_OSLCOMP_LIBRARY}
231                                 -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY}
232                                 -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY}
233                         )
234                 endif()
235         else()
236                 message(STATUS "OSL not found, disabling it from Cycles")
237                 set(WITH_CYCLES_OSL OFF)
238         endif()
239 endif()
240
241 if(WITH_OPENVDB)
242         find_package_wrapper(OpenVDB)
243         find_package_wrapper(TBB)
244         find_package_wrapper(Blosc)
245         if(NOT TBB_FOUND)
246                 set(WITH_OPENVDB OFF)
247                 set(WITH_OPENVDB_BLOSC OFF)
248                 message(STATUS "TBB not found, disabling OpenVDB")
249         elseif(NOT OPENVDB_FOUND)
250                 set(WITH_OPENVDB OFF)
251                 set(WITH_OPENVDB_BLOSC OFF)
252                 message(STATUS "OpenVDB not found, disabling it")
253         elseif(NOT BLOSC_FOUND)
254                 set(WITH_OPENVDB_BLOSC OFF)
255                 message(STATUS "Blosc not found, disabling it for OpenVBD")
256         endif()
257 endif()
258
259 if(WITH_ALEMBIC)
260         find_package_wrapper(Alembic)
261
262         if(WITH_ALEMBIC_HDF5)
263                 set(HDF5_ROOT_DIR ${LIBDIR}/hdf5)
264                 find_package_wrapper(HDF5)
265         endif()
266
267         if(NOT ALEMBIC_FOUND OR (WITH_ALEMBIC_HDF5 AND NOT HDF5_FOUND))
268                 set(WITH_ALEMBIC OFF)
269                 set(WITH_ALEMBIC_HDF5 OFF)
270         endif()
271 endif()
272
273 if(WITH_BOOST)
274         # uses in build instructions to override include and library variables
275         if(NOT BOOST_CUSTOM)
276                 if(WITH_STATIC_LIBS)
277                         set(Boost_USE_STATIC_LIBS ON)
278                 endif()
279                 set(Boost_USE_MULTITHREADED ON)
280                 set(__boost_packages filesystem regex thread date_time)
281                 if(WITH_CYCLES_OSL)
282                         if(NOT (${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6"))
283                                 list(APPEND __boost_packages wave)
284                         else()
285                         endif()
286                 endif()
287                 if(WITH_INTERNATIONAL)
288                         list(APPEND __boost_packages locale)
289                 endif()
290                 if(WITH_CYCLES_NETWORK)
291                         list(APPEND __boost_packages serialization)
292                 endif()
293                 if(WITH_OPENVDB)
294                         list(APPEND __boost_packages iostreams)
295                 endif()
296                 list(APPEND __boost_packages system)
297                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
298                 if(NOT Boost_FOUND)
299                         # try to find non-multithreaded if -mt not found, this flag
300                         # doesn't matter for us, it has nothing to do with thread
301                         # safety, but keep it to not disturb build setups
302                         set(Boost_USE_MULTITHREADED OFF)
303                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
304                 endif()
305                 unset(__boost_packages)
306                 if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
307                         find_package(IcuLinux)
308                 endif()
309                 mark_as_advanced(Boost_DIR)  # why doesn't boost do this?
310         endif()
311
312         set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
313         set(BOOST_LIBRARIES ${Boost_LIBRARIES})
314         set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
315         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
316 endif()
317
318 if(WITH_OPENIMAGEIO)
319         find_package_wrapper(OpenImageIO)
320         if(NOT OPENIMAGEIO_PUGIXML_FOUND AND WITH_CYCLES_STANDALONE)
321                 find_package_wrapper(PugiXML)
322         else()
323                 set(PUGIXML_INCLUDE_DIR "${OPENIMAGEIO_INCLUDE_DIR/OpenImageIO}")
324                 set(PUGIXML_LIBRARIES "")
325         endif()
326
327         set(OPENIMAGEIO_LIBRARIES
328                 ${OPENIMAGEIO_LIBRARIES}
329                 ${PNG_LIBRARIES}
330                 ${JPEG_LIBRARIES}
331                 ${ZLIB_LIBRARIES}
332                 ${BOOST_LIBRARIES}
333         )
334         set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
335         set(OPENIMAGEIO_DEFINITIONS "")
336
337         if(WITH_IMAGE_TIFF)
338                 list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
339         endif()
340         if(WITH_IMAGE_OPENEXR)
341                 list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
342         endif()
343
344         if(NOT OPENIMAGEIO_FOUND)
345                 set(WITH_OPENIMAGEIO OFF)
346                 message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
347         endif()
348 endif()
349
350 if(WITH_OPENCOLORIO)
351         find_package_wrapper(OpenColorIO)
352
353         set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
354         set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
355         set(OPENCOLORIO_DEFINITIONS)
356
357         if(NOT OPENCOLORIO_FOUND)
358                 set(WITH_OPENCOLORIO OFF)
359                 message(STATUS "OpenColorIO not found")
360         endif()
361 endif()
362
363 if(WITH_CYCLES_EMBREE)
364         find_package(Embree 3.2.4 REQUIRED)
365 endif()
366
367 if(WITH_LLVM)
368         if(EXISTS ${LIBDIR})
369                 set(LLVM_STATIC ON)
370         endif()
371
372         find_package_wrapper(LLVM)
373
374         # Symbol conflicts with same UTF library used by OpenCollada
375         if(EXISTS ${LIBDIR})
376                 if(WITH_OPENCOLLADA AND (${LLVM_VERSION} VERSION_LESS "4.0.0"))
377                         list(REMOVE_ITEM OPENCOLLADA_LIBRARIES ${OPENCOLLADA_UTF_LIBRARY})
378                 endif()
379         endif()
380
381         if(NOT LLVM_FOUND)
382                 set(WITH_LLVM OFF)
383                 message(STATUS "LLVM not found")
384         endif()
385 endif()
386
387 if(WITH_LLVM OR WITH_SDL_DYNLOAD)
388         # Fix for conflict with Mesa llvmpipe
389         set(PLATFORM_LINKFLAGS
390                 "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'"
391         )
392 endif()
393
394 if(WITH_OPENSUBDIV)
395         find_package_wrapper(OpenSubdiv)
396
397         set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBRARIES})
398         set(OPENSUBDIV_LIBPATH)  # TODO, remove and reference the absolute path everywhere
399
400         if(NOT OPENSUBDIV_FOUND)
401                 set(WITH_OPENSUBDIV OFF)
402                 message(STATUS "OpenSubdiv not found")
403         endif()
404 endif()
405
406 # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
407 if(HAIKU)
408         list(APPEND PLATFORM_LINKLIBS -lnetwork)
409 else()
410         list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm)
411 endif()
412
413 find_package(Threads REQUIRED)
414 list(APPEND PLATFORM_LINKLIBS ${CMAKE_THREAD_LIBS_INIT})
415 # used by other platforms
416 set(PTHREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
417
418 if(CMAKE_DL_LIBS)
419         list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
420 endif()
421
422 if(CMAKE_SYSTEM_NAME MATCHES "Linux")
423         if(NOT WITH_PYTHON_MODULE)
424                 # binreloc is linux only
425                 set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
426                 set(WITH_BINRELOC ON)
427         endif()
428 endif()
429
430 # lfs on glibc, all compilers should use
431 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
432
433 # GNU Compiler
434 if(CMAKE_COMPILER_IS_GNUCC)
435         set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
436
437         if(WITH_LINKER_GOLD)
438                 execute_process(
439                         COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
440                         ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
441                 if("${LD_VERSION}" MATCHES "GNU gold")
442                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
443                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
444                 else()
445                         message(STATUS "GNU gold linker isn't available, using the default system linker.")
446                 endif()
447                 unset(LD_VERSION)
448         endif()
449
450 # CLang is the same as GCC for now.
451 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
452         set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
453 # Intel C++ Compiler
454 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
455         # think these next two are broken
456         find_program(XIAR xiar)
457         if(XIAR)
458                 set(CMAKE_AR "${XIAR}")
459         endif()
460         mark_as_advanced(XIAR)
461
462         find_program(XILD xild)
463         if(XILD)
464                 set(CMAKE_LINKER "${XILD}")
465         endif()
466         mark_as_advanced(XILD)
467
468         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
469         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
470
471         # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
472         set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
473         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
474 endif()