platform_unix.cmake 13 KB

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