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