Package.cmake 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. set(_thirdparty_platform)
  2. if(APPLE)
  3. set(_thirdparty_platform "darwin-libs-a")
  4. elseif(WIN32)
  5. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  6. set(_thirdparty_platform "win-libs-vc14-x64")
  7. else()
  8. set(_thirdparty_platform "win-libs-vc14")
  9. endif()
  10. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  11. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  12. set(_thirdparty_platform "linux-libs-arm64")
  13. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  14. set(_thirdparty_platform "linux-libs-x64")
  15. else()
  16. set(_thirdparty_platform "linux-libs-a")
  17. endif()
  18. elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
  19. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  20. set(_thirdparty_platform "freebsd-libs-arm64")
  21. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  22. set(_thirdparty_platform "freebsd-libs-x64")
  23. else()
  24. set(_thirdparty_platform "freebsd-libs-a")
  25. endif()
  26. elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
  27. set(_thirdparty_platform "android-libs-${CMAKE_ANDROID_ARCH}")
  28. elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
  29. set(_thirdparty_platform "emscripten-libs")
  30. elseif(CMAKE_SYSTEM_NAME STREQUAL "WASI")
  31. set(_thirdparty_platform "wasi-libs-${CMAKE_SYSTEM_PROCESSOR}")
  32. endif()
  33. set(_thirdparty_dir_default "")
  34. if(_thirdparty_platform)
  35. if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/thirdparty/${_thirdparty_platform}")
  36. set(_thirdparty_dir_default "${PROJECT_SOURCE_DIR}/thirdparty")
  37. else()
  38. message(WARNING
  39. "Ignoring thirdparty directory without ${_thirdparty_platform} subdirectory.")
  40. endif()
  41. endif()
  42. set(THIRDPARTY_DIRECTORY "${_thirdparty_dir_default}" CACHE PATH
  43. "Optional location of a makepanda-style thirdparty directory. All libraries
  44. located here will be prioritized over system libraries. Useful for
  45. cross-compiling.")
  46. set(THIRDPARTY_DLLS)
  47. if(THIRDPARTY_DIRECTORY)
  48. if(NOT _thirdparty_platform)
  49. message(FATAL_ERROR
  50. "You can't use THIRDPARTY_DIRECTORY on this platform. Unset it to continue.")
  51. endif()
  52. # This policy is necessary for PackageName_ROOT variables to be respected
  53. if(POLICY CMP0074)
  54. cmake_policy(GET CMP0074 _policy_cmp0074)
  55. endif()
  56. if(NOT _policy_cmp0074 STREQUAL "NEW")
  57. message(FATAL_ERROR
  58. "Your version of CMake is too old; please upgrade or unset THIRDPARTY_DIRECTORY to continue.")
  59. endif()
  60. if(APPLE)
  61. # Make sure thirdparty has the first shot, not system frameworks
  62. set(CMAKE_FIND_FRAMEWORK LAST)
  63. elseif(WIN32)
  64. set(BISON_ROOT "${THIRDPARTY_DIRECTORY}/win-util")
  65. set(FLEX_ROOT "${THIRDPARTY_DIRECTORY}/win-util")
  66. endif()
  67. foreach(_Package
  68. ARToolKit
  69. Assimp
  70. Bullet
  71. Eigen3
  72. FCollada
  73. FFMPEG
  74. FMODEx
  75. Freetype
  76. HarfBuzz
  77. JPEG
  78. LibSquish
  79. ODE
  80. Ogg
  81. OpenAL
  82. OpenEXR
  83. OpenSSL
  84. OpusFile
  85. PNG
  86. SWResample
  87. SWScale
  88. TIFF
  89. VorbisFile
  90. VRPN
  91. ZLIB
  92. )
  93. string(TOLOWER "${_Package}" _package)
  94. string(TOUPPER "${_Package}" _PACKAGE)
  95. # Some packages in the thirdparty dir have different subdirectory names from
  96. # the name of the CMake package
  97. if(_package STREQUAL "eigen3")
  98. set(_package "eigen")
  99. elseif(_package STREQUAL "ogg")
  100. set(_package "vorbis") # It's in the same install dir here
  101. elseif(_package STREQUAL "opusfile")
  102. set(_package "opus")
  103. elseif(_package STREQUAL "libsquish")
  104. set(_package "squish")
  105. elseif(_package STREQUAL "swresample" OR _package STREQUAL "swscale")
  106. set(_package "ffmpeg") # These are also part of FFmpeg
  107. elseif(_package STREQUAL "vorbisfile")
  108. set(_package "vorbis")
  109. endif()
  110. # Set search path
  111. set(${_Package}_ROOT "${THIRDPARTY_DIRECTORY}/${_thirdparty_platform}/${_package}")
  112. # Set up copying DLLs, if necessary
  113. file(GLOB _dlls "${${_Package}_ROOT}/bin/*.dll")
  114. if(_dlls)
  115. set(_havevar "HAVE_${_PACKAGE}")
  116. set(THIRDPARTY_DLLS_${_havevar} "${_dlls}")
  117. list(APPEND THIRDPARTY_DLLS "${_havevar}")
  118. endif()
  119. endforeach(_Package)
  120. endif()
  121. # This is used to copy the DLLs alongside the output of `package`
  122. function(thirdparty_copy_alongside package)
  123. set(_dlls)
  124. foreach(_havevar ${THIRDPARTY_DLLS})
  125. if(${_havevar})
  126. list(APPEND _dlls ${THIRDPARTY_DLLS_${_havevar}})
  127. endif()
  128. endforeach(_havevar)
  129. if(NOT _dlls)
  130. # Don't try to copy/install nothingness
  131. return()
  132. endif()
  133. add_custom_command(TARGET ${package} POST_BUILD
  134. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  135. ${_dlls} $<TARGET_FILE_DIR:${package}>
  136. )
  137. # Also install the DLLs
  138. install(FILES ${_dlls} DESTINATION ${CMAKE_INSTALL_BINDIR})
  139. endfunction(thirdparty_copy_alongside)
  140. #
  141. # ------------ Python ------------
  142. #
  143. set(WANT_PYTHON_VERSION ""
  144. CACHE STRING "Which Python version to seek out for building Panda3D against.")
  145. if(DEFINED _PREV_WANT_PYTHON_VERSION
  146. AND NOT _PREV_WANT_PYTHON_VERSION STREQUAL WANT_PYTHON_VERSION)
  147. # The user changed WANT_PYTHON_VERSION. We need to force FindPython to start
  148. # anew, deleting any variable that was autodetected last time
  149. foreach(_prev_var ${_PREV_PYTHON_VALUES})
  150. string(REPLACE "=" ";" _prev_var "${_prev_var}")
  151. list(GET _prev_var 0 _prev_var_name)
  152. list(GET _prev_var 1 _prev_var_sha1)
  153. string(SHA1 _current_var_sha1 "${${_prev_var_name}}")
  154. if(_prev_var_sha1 STREQUAL _current_var_sha1)
  155. unset(${_prev_var_name} CACHE)
  156. endif()
  157. endforeach(_prev_var)
  158. unset(_PREV_PYTHON_VALUES CACHE)
  159. endif()
  160. # Look for Python in the thirdparty directory on Windows.
  161. if(WIN32 AND THIRDPARTY_DIRECTORY)
  162. set(_python_dir_suffix "")
  163. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  164. set(_python_dir_suffix "-x64")
  165. endif()
  166. if(WANT_PYTHON_VERSION)
  167. set(Python_ROOT_DIR "${THIRDPARTY_DIRECTORY}/win-python${WANT_PYTHON_VERSION}${_python_dir_suffix}")
  168. else()
  169. # CMake doesn't support NATURAL sorting until 3.18, so we sort the 3.1x
  170. # versions separately from the prior versions.
  171. file(GLOB _python_dirs "${THIRDPARTY_DIRECTORY}/win-python3.[0-9][0-9]${_python_dir_suffix}")
  172. file(GLOB _python_dirs2 "${THIRDPARTY_DIRECTORY}/win-python3.[0-9]${_python_dir_suffix}")
  173. list(SORT _python_dirs COMPARE FILE_BASENAME CASE INSENSITIVE ORDER DESCENDING)
  174. list(SORT _python_dirs2 COMPARE FILE_BASENAME CASE INSENSITIVE ORDER DESCENDING)
  175. list(APPEND _python_dirs ${_python_dirs2})
  176. set(Python_ROOT_DIR "${_python_dirs}")
  177. endif()
  178. endif()
  179. if(WANT_PYTHON_VERSION)
  180. # A specific version is requested; ensure we get that specific version
  181. list(APPEND WANT_PYTHON_VERSION "EXACT")
  182. endif()
  183. get_directory_property(_old_cache_vars CACHE_VARIABLES)
  184. find_package(Python ${WANT_PYTHON_VERSION} QUIET COMPONENTS Interpreter Development)
  185. if(Python_FOUND)
  186. set(PYTHON_FOUND ON)
  187. set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
  188. set(PYTHON_INCLUDE_DIRS ${Python_INCLUDE_DIRS})
  189. set(PYTHON_LIBRARY_DIRS ${Python_LIBRARY_DIRS})
  190. set(PYTHON_VERSION_STRING ${Python_VERSION})
  191. endif()
  192. if(CMAKE_VERSION VERSION_LESS "3.15")
  193. # CMake versions this old don't provide Python::Module, so we need to hack up
  194. # the variables to ensure no explicit linkage against libpython occurs
  195. if(WIN32)
  196. # Nothing needed here; explicit linkage is appropriate
  197. set(PYTHON_LIBRARY "${Python_LIBRARY}")
  198. set(PYTHON_LIBRARIES ${Python_LIBRARIES})
  199. elseif(APPLE OR UNIX)
  200. # Just unset and let the implicit linkage take over
  201. set(PYTHON_LIBRARY "")
  202. set(PYTHON_LIBRARIES "")
  203. if(APPLE)
  204. # macOS requires this explicit flag on the linker command line to allow the
  205. # references to the Python symbols to resolve at dynamic link time
  206. string(APPEND CMAKE_MODULE_LINKER_FLAGS " -undefined dynamic_lookup")
  207. endif()
  208. else()
  209. # On every other platform, guessing is a bad idea - insist the user upgrade
  210. # their CMake instead.
  211. message(WARNING "For Python support on this platform, please use CMake >= 3.15!")
  212. set(PYTHON_FOUND OFF)
  213. endif()
  214. endif()
  215. package_option(Python
  216. DEFAULT ON
  217. "Enables support for Python. If INTERROGATE_PYTHON_INTERFACE
  218. is also enabled, Python bindings will be generated."
  219. IMPORTED_AS Python::Module)
  220. # Also detect the optimal install paths:
  221. if(HAVE_PYTHON)
  222. if(WIN32 AND NOT CYGWIN)
  223. set(_LIB_DIR ".")
  224. set(_ARCH_DIR ".")
  225. elseif(PYTHON_EXECUTABLE)
  226. # Python 3.12 drops the distutils module, so we have to use the newer
  227. # sysconfig module instead. Earlier versions of Python had the newer
  228. # module too, but it was broken in Debian/Ubuntu, see #1230
  229. if(PYTHON_VERSION_STRING VERSION_LESS "3.12")
  230. execute_process(
  231. COMMAND ${PYTHON_EXECUTABLE}
  232. -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(False))"
  233. OUTPUT_VARIABLE _LIB_DIR
  234. OUTPUT_STRIP_TRAILING_WHITESPACE)
  235. execute_process(
  236. COMMAND ${PYTHON_EXECUTABLE}
  237. -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(True))"
  238. OUTPUT_VARIABLE _ARCH_DIR
  239. OUTPUT_STRIP_TRAILING_WHITESPACE)
  240. else()
  241. execute_process(
  242. COMMAND ${PYTHON_EXECUTABLE}
  243. -c "import sysconfig; print(sysconfig.get_path('purelib'))"
  244. OUTPUT_VARIABLE _LIB_DIR
  245. OUTPUT_STRIP_TRAILING_WHITESPACE)
  246. execute_process(
  247. COMMAND ${PYTHON_EXECUTABLE}
  248. -c "import sysconfig; print(sysconfig.get_path('platlib'))"
  249. OUTPUT_VARIABLE _ARCH_DIR
  250. OUTPUT_STRIP_TRAILING_WHITESPACE)
  251. endif()
  252. else()
  253. set(_LIB_DIR "")
  254. set(_ARCH_DIR "")
  255. endif()
  256. execute_process(
  257. COMMAND ${PYTHON_EXECUTABLE}
  258. -c "from sysconfig import get_config_var as g; print((g('EXT_SUFFIX') or g('SO'))[:])"
  259. OUTPUT_VARIABLE _EXT_SUFFIX
  260. ERROR_QUIET
  261. OUTPUT_STRIP_TRAILING_WHITESPACE)
  262. if(NOT _EXT_SUFFIX)
  263. if(CYGWIN)
  264. set(_EXT_SUFFIX ".dll")
  265. elseif(WIN32)
  266. set(_EXT_SUFFIX ".pyd")
  267. else()
  268. set(_EXT_SUFFIX ".so")
  269. endif()
  270. endif()
  271. set(PYTHON_LIB_INSTALL_DIR "${_LIB_DIR}" CACHE STRING
  272. "Path to the Python architecture-independent package directory.")
  273. set(PYTHON_ARCH_INSTALL_DIR "${_ARCH_DIR}" CACHE STRING
  274. "Path to the Python architecture-dependent package directory.")
  275. set(PYTHON_EXTENSION_SUFFIX "${_EXT_SUFFIX}" CACHE STRING
  276. "Suffix for Python binary extension modules.")
  277. # Determine the platform to use for .whl files.
  278. if(WIN32)
  279. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  280. set(_platform "win-amd64")
  281. else()
  282. set(_platform "win32")
  283. endif()
  284. elseif(APPLE)
  285. if(NOT CMAKE_OSX_ARCHITECTURES)
  286. set(_arch_tag ${CMAKE_SYSTEM_PROCESSOR})
  287. elseif("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
  288. if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES)
  289. set(_arch_tag "universal2")
  290. elseif("i386" IN_LIST CMAKE_OSX_ARCHITECTURES AND
  291. "ppc64" IN_LIST CMAKE_OSX_ARCHITECTURES AND
  292. "ppc" IN_LIST CMAKE_OSX_ARCHITECTURES)
  293. set(_arch_tag "universal")
  294. elseif("i386" IN_LIST CMAKE_OSX_ARCHITECTURES AND
  295. "ppc" IN_LIST CMAKE_OSX_ARCHITECTURES)
  296. set(_arch_tag "fat32")
  297. elseif("ppc64" IN_LIST CMAKE_OSX_ARCHITECTURES)
  298. set(_arch_tag "fat64")
  299. elseif("i386" IN_LIST CMAKE_OSX_ARCHITECTURES)
  300. set(_arch_tag "intel")
  301. else()
  302. set(_arch_tag "x86_64")
  303. endif()
  304. elseif("i386" IN_LIST CMAKE_OSX_ARCHITECTURES AND
  305. "ppc" IN_LIST CMAKE_OSX_ARCHITECTURES)
  306. set(_arch_tag "fat")
  307. else()
  308. list(GET CMAKE_OSX_ARCHITECTURES 0 _arch_tag)
  309. endif()
  310. set(_target "${CMAKE_OSX_DEPLOYMENT_TARGET}")
  311. if(_arch_tag STREQUAL "arm64" AND _target VERSION_LESS "11.0")
  312. set(_target "11.0")
  313. elseif(PYTHON_VERSION_STRING VERSION_GREATER_EQUAL "3.13" AND _target VERSION_LESS "10.13")
  314. set(_target "10.13")
  315. elseif(PYTHON_VERSION_STRING VERSION_GREATER_EQUAL "3.8" AND _target VERSION_LESS "10.9")
  316. set(_target "10.9")
  317. endif()
  318. set(_platform "macosx-${_target}-${_arch_tag}")
  319. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  320. set(_platform "linux-${CMAKE_SYSTEM_PROCESSOR}")
  321. if(IS_DIRECTORY "/opt/python")
  322. # Sloppy detection for manylinux.
  323. if(EXISTS "/lib64/libc-2.5.so" OR EXISTS "/lib/libc-2.5.so")
  324. set(_platform "manylinux1-${CMAKE_SYSTEM_PROCESSOR}")
  325. elseif(EXISTS "/lib64/libc-2.12.so" OR EXISTS "/lib/libc-2.12.so")
  326. set(_platform "manylinux2010-${CMAKE_SYSTEM_PROCESSOR}")
  327. elseif(EXISTS "/lib64/libc-2.17.so" OR EXISTS "/lib/libc-2.17.so")
  328. set(_platform "manylinux2014-${CMAKE_SYSTEM_PROCESSOR}")
  329. elseif(EXISTS "/lib/x86_64-linux-gnu/libc-2.24.so" OR EXISTS "/lib/i386-linux-gnu/libc-2.24.so")
  330. set(_platform "manylinux_2_24-${CMAKE_SYSTEM_PROCESSOR}")
  331. elseif(EXISTS "/etc/almalinux-release" AND EXISTS "/lib64/libc-2.28.so")
  332. set(_platform "manylinux_2_28-${CMAKE_SYSTEM_PROCESSOR}")
  333. endif()
  334. endif()
  335. elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
  336. set(_platform "emscripten-${CMAKE_SYSTEM_PROCESSOR}")
  337. else()
  338. set(_platform "")
  339. endif()
  340. # This is being read out of the CMake cache by makewheel.py.
  341. if(_platform)
  342. set(PYTHON_PLATFORM_TAG "${_platform}" CACHE STRING "" FORCE)
  343. else()
  344. unset(PYTHON_PLATFORM_TAG CACHE)
  345. endif()
  346. endif()
  347. if(NOT DEFINED _PREV_PYTHON_VALUES)
  348. # We need to make note of all auto-defined Python variables
  349. set(_prev_python_values)
  350. get_directory_property(_new_cache_vars CACHE_VARIABLES)
  351. foreach(_cache_var ${_new_cache_vars})
  352. if(_cache_var MATCHES "^(Python|PYTHON)_" AND NOT _old_cache_vars MATCHES ";${_cache_var};")
  353. string(SHA1 _cache_var_sha1 "${${_cache_var}}")
  354. list(APPEND _prev_python_values "${_cache_var}=${_cache_var_sha1}")
  355. endif()
  356. endforeach(_cache_var)
  357. set(_PREV_PYTHON_VALUES "${_prev_python_values}" CACHE INTERNAL "Internal." FORCE)
  358. endif()
  359. set(_PREV_WANT_PYTHON_VERSION "${WANT_PYTHON_VERSION}" CACHE INTERNAL "Internal." FORCE)
  360. #
  361. # ------------ Data handling libraries ------------
  362. #
  363. # OpenSSL
  364. find_package(OpenSSL COMPONENTS SSL Crypto QUIET)
  365. package_option(OpenSSL
  366. DEFAULT ON
  367. "Enable OpenSSL support"
  368. IMPORTED_AS OpenSSL::SSL OpenSSL::Crypto)
  369. option(REPORT_OPENSSL_ERRORS
  370. "Define this true to include the OpenSSL code to report verbose
  371. error messages when they occur." OFF)
  372. option(REPORT_OPENSSL_ERRORS_Debug "" ON)
  373. package_status(OpenSSL "OpenSSL")
  374. # zlib
  375. find_package(ZLIB QUIET)
  376. package_option(ZLIB
  377. "Enables support for compression of Panda assets."
  378. IMPORTED_AS ZLIB::ZLIB)
  379. package_status(ZLIB "zlib")
  380. #
  381. # ------------ Image formats ------------
  382. #
  383. # JPEG
  384. find_package(JPEG QUIET)
  385. package_option(JPEG "Enable support for loading .jpg images.")
  386. package_status(JPEG "libjpeg")
  387. # PNG
  388. find_package(PNG QUIET)
  389. package_option(PNG
  390. "Enable support for loading .png images."
  391. IMPORTED_AS PNG::PNG)
  392. package_status(PNG "libpng")
  393. # TIFF
  394. find_package(TIFF QUIET)
  395. package_option(TIFF "Enable support for loading .tif images.")
  396. package_status(TIFF "libtiff")
  397. # OpenEXR
  398. find_package(OpenEXR QUIET)
  399. if (TARGET OpenEXR::IlmImf AND NOT TARGET OpenEXR::OpenEXR)
  400. package_option(OpenEXR
  401. "Enable support for loading .exr images."
  402. IMPORTED_AS OpenEXR::IlmImf)
  403. else()
  404. package_option(OpenEXR
  405. "Enable support for loading .exr images."
  406. IMPORTED_AS OpenEXR::OpenEXR)
  407. endif()
  408. package_status(OpenEXR "OpenEXR")
  409. # libsquish
  410. find_package(LibSquish QUIET MODULE)
  411. package_option(SQUISH
  412. "Enables support for automatic compression of DXT textures."
  413. FOUND_AS LibSquish)
  414. package_status(SQUISH "libsquish")
  415. #
  416. # ------------ Asset formats ------------
  417. #
  418. # Assimp
  419. find_package(Assimp QUIET MODULE)
  420. package_option(Assimp
  421. "Build pandatool with support for loading 3D assets supported by Assimp.")
  422. package_status(Assimp "Assimp")
  423. # FCollada
  424. find_package(FCollada QUIET)
  425. package_option(FCollada
  426. "Build pandatool with support for loading Collada files using FCollada."
  427. IMPORTED_AS FCollada::FCollada)
  428. package_status(FCollada "FCollada")
  429. #
  430. # ------------ Math libraries ------------
  431. #
  432. # Eigen
  433. find_package(Eigen3 QUIET)
  434. package_option(EIGEN
  435. "Enables use of the Eigen linear algebra library.
  436. If this is provided, Panda will use this library as the fundamental
  437. implementation of its own linmath library; otherwise, it will use
  438. its own internal implementation. The primary advantage of using
  439. Eigen is SSE2 support, which is only activated if LINMATH_ALIGN
  440. is also enabled."
  441. FOUND_AS Eigen3
  442. LICENSE "MPL-2")
  443. option(LINMATH_ALIGN
  444. "This is required for activating SSE2 support using Eigen.
  445. Activating this does constrain most objects in Panda to 16-byte
  446. alignment, which could impact memory usage on very-low-memory
  447. platforms. Currently experimental." ON)
  448. if(LINMATH_ALIGN)
  449. package_status(EIGEN "Eigen linear algebra library" "vectorization enabled in build")
  450. else()
  451. package_status(EIGEN "Eigen linear algebra library" "vectorization NOT enabled in build")
  452. endif()
  453. # FFTW
  454. # FFTW 3.3.7, when built with autotools, doesn't install
  455. # FFTW3LibraryDepends.cmake, which will crash us if we use CONFIG mode. BAH!
  456. # Force MODULE mode to fix that.
  457. find_package(FFTW3 MODULE QUIET)
  458. package_option(FFTW
  459. "This enables support for compression of animations in .bam files.
  460. This is only necessary for creating or reading .bam files containing
  461. compressed animations."
  462. FOUND_AS "FFTW3"
  463. LICENSE "GPL")
  464. package_status(FFTW "FFTW")
  465. #
  466. # ------------ Multimedia formats ------------
  467. #
  468. # FFmpeg
  469. find_package(FFMPEG QUIET)
  470. find_package(SWScale QUIET)
  471. find_package(SWResample QUIET)
  472. package_option(FFMPEG
  473. "Enables support for audio- and video-decoding using the FFmpeg library.")
  474. package_option(SWScale
  475. "Enables support for FFmpeg's libswscale for video rescaling.")
  476. package_option(SWResample
  477. "Enables support for FFmpeg's libresample for audio resampling.")
  478. if(HAVE_SWSCALE AND HAVE_SWRESAMPLE)
  479. set(ffmpeg_features "with swscale and swresample")
  480. elseif(HAVE_SWSCALE)
  481. set(ffmpeg_features "with swscale")
  482. elseif(HAVE_SWRESAMPLE)
  483. set(ffmpeg_features "with swresample")
  484. else()
  485. set(ffmpeg_features "without resampling/rescaling support")
  486. endif()
  487. package_status(FFMPEG "FFmpeg" "${ffmpeg_features}")
  488. # Vorbis
  489. find_package(VorbisFile QUIET)
  490. package_option(VORBIS
  491. FOUND_AS VorbisFile
  492. "Enables support for decoding Vorbis-encoded .ogg audio files via libvorbisfile.")
  493. package_status(VORBIS "Vorbis")
  494. # Opus
  495. find_package(OpusFile QUIET)
  496. package_option(OPUS
  497. FOUND_AS OpusFile
  498. "Enables support for decoding .opus audio files via libopusfile.")
  499. package_status(OPUS "Opus")
  500. #
  501. # ------------ Audio libraries ------------
  502. #
  503. # FMOD Ex
  504. if(NOT APPLE)
  505. find_package(FMODEx QUIET)
  506. endif()
  507. package_option(FMODEx
  508. "This enables support for the FMOD Ex sound library,
  509. from Firelight Technologies. This audio library is free for non-commercial
  510. use."
  511. LICENSE "FMOD")
  512. package_status(FMODEx "FMOD Ex sound library")
  513. # OpenAL
  514. find_package(OpenAL QUIET)
  515. package_option(OpenAL
  516. "This enables support for audio output via OpenAL. Some platforms, such as
  517. macOS, provide their own OpenAL implementation, which Panda3D can use. But,
  518. on most platforms this will imply OpenAL Soft, which is LGPL licensed."
  519. IMPORTED_AS OpenAL::OpenAL
  520. LICENSE "LGPL")
  521. package_status(OpenAL "OpenAL sound library")
  522. if(OpenAL_FOUND AND APPLE OR OPENAL_FOUND AND APPLE)
  523. set(HAVE_OPENAL_FRAMEWORK YES)
  524. endif()
  525. #
  526. # ------------ UI libraries ------------
  527. #
  528. # Freetype
  529. find_package(Freetype QUIET)
  530. package_option(Freetype
  531. "This enables support for the FreeType font-rendering library. If disabled,
  532. Panda3D will only be able to read fonts specially made with egg-mkfont."
  533. IMPORTED_AS freetype)
  534. package_status(Freetype "FreeType")
  535. # HarfBuzz
  536. # Some versions of harfbuzz-config.cmake contain an endless while loop, so we
  537. # force MODULE mode here.
  538. find_package(HarfBuzz MODULE QUIET)
  539. package_option(HarfBuzz
  540. "This enables support for the HarfBuzz text shaping library."
  541. IMPORTED_AS harfbuzz::harfbuzz)
  542. package_status(HarfBuzz "HarfBuzz")
  543. # GTK3
  544. if(NOT WIN32)
  545. find_package(GTK3 QUIET)
  546. endif()
  547. package_option(GTK3
  548. "This is necessary to build the PStats performance analysis tool on platforms
  549. other than Windows.")
  550. package_status(GTK3 "gtk+-3")
  551. #
  552. # ------------ Physics engines ------------
  553. #
  554. # Bullet
  555. find_package(Bullet MODULE QUIET)
  556. package_option(Bullet
  557. "Enable this option to support game dynamics with the Bullet physics library.")
  558. package_status(Bullet "Bullet physics")
  559. # ODE
  560. find_package(ODE QUIET)
  561. package_option(ODE
  562. "Enable this option to support game dynamics with the Open Dynamics Engine (ODE)."
  563. LICENSE "BSD-3"
  564. IMPORTED_AS ODE::ODE)
  565. package_status(ODE "Open Dynamics Engine")
  566. #
  567. # ------------ SpeedTree ------------
  568. #
  569. # SpeedTree
  570. find_package(SpeedTree QUIET)
  571. package_option(SpeedTree
  572. "Enable this option to include scenegraph support for SpeedTree trees."
  573. LICENSE "SpeedTree")
  574. package_status(SpeedTree "SpeedTree")
  575. #
  576. # ------------ Rendering APIs ------------
  577. #
  578. # OpenGL
  579. find_package(OpenGL QUIET)
  580. package_option(GL
  581. "Enable OpenGL support."
  582. FOUND_AS OPENGL
  583. IMPORTED_AS OpenGL::GL)
  584. package_status(GL "OpenGL")
  585. # OpenGL ES 1
  586. if(NOT APPLE) # Apple X11 ships the GLES headers but they're broken
  587. find_package(OpenGLES1 QUIET)
  588. endif()
  589. package_option(GLES1
  590. "Enable support for OpenGL ES 1.x rendering APIs."
  591. FOUND_AS OPENGLES1)
  592. package_status(GLES1 "OpenGL ES 1.x")
  593. # OpenGL ES 2
  594. if(NOT APPLE) # Apple X11 ships the GLES headers but they're broken
  595. find_package(OpenGLES2 QUIET)
  596. endif()
  597. package_option(GLES2
  598. "Enable support for OpenGL ES 2.x rendering APIs."
  599. FOUND_AS OPENGLES2)
  600. package_status(GLES2 "OpenGL ES 2.x")
  601. # Direct3D 9
  602. find_package(Direct3D9 QUIET COMPONENTS dxguid dxerr d3dx9)
  603. package_option(DX9
  604. "Enable support for DirectX 9. This is typically only viable on Windows."
  605. FOUND_AS Direct3D9)
  606. package_status(DX9 "Direct3D 9.x")
  607. #
  608. # ------------ Display APIs ------------
  609. #
  610. # X11 (and GLX)
  611. if(NOT APPLE)
  612. find_package(X11 QUIET)
  613. endif()
  614. if(NOT X11_Xkb_FOUND OR NOT X11_Xutil_FOUND)
  615. # Panda implicitly requires these supplementary X11 libs; if we can't find
  616. # them, we just say we didn't find X11 at all.
  617. set(X11_FOUND OFF)
  618. endif()
  619. package_option(X11
  620. "Provides X-server support on Unix platforms. X11 may need to be linked
  621. against for tinydisplay, but probably only on a Linux platform.")
  622. set(HAVE_GLX_AVAILABLE OFF)
  623. if(HAVE_GL AND HAVE_X11 AND NOT APPLE)
  624. set(HAVE_GLX_AVAILABLE ON)
  625. endif()
  626. option(HAVE_GLX "Enables GLX. Requires OpenGL and X11." ${HAVE_GLX_AVAILABLE})
  627. if(HAVE_GLX AND NOT HAVE_GLX_AVAILABLE)
  628. message(SEND_ERROR "HAVE_GLX manually set to ON but it is not available!")
  629. endif()
  630. if(HAVE_GLX)
  631. package_status(X11 "X11" "with GLX")
  632. else()
  633. package_status(X11 "X11" "without GLX")
  634. endif()
  635. # EGL
  636. find_package(EGL QUIET)
  637. package_option(EGL
  638. "Enable support for the Khronos EGL context management interface for
  639. OpenGL ES. This is necessary to support OpenGL ES under X11.")
  640. package_status(EGL "EGL")
  641. #
  642. # ------------ Vision tools ------------
  643. #
  644. # OpenCV
  645. find_package(OpenCV QUIET COMPONENTS core highgui OPTIONAL_COMPONENTS videoio)
  646. package_option(OpenCV
  647. "Enable support for OpenCV. This will be built into the 'vision' package."
  648. FOUND_AS OpenCV)
  649. package_status(OpenCV "OpenCV")
  650. # CMake <3.7 doesn't support GREATER_EQUAL, so this uses NOT LESS instead.
  651. if(NOT OpenCV_VERSION_MAJOR LESS 3)
  652. set(OPENCV_VER_3 ON)
  653. elseif(NOT OpenCV_VERSION_MAJOR LESS 2 AND
  654. NOT OpenCV_VERSION_MINOR LESS 3)
  655. set(OPENCV_VER_23 ON)
  656. endif()
  657. # ARToolKit
  658. find_package(ARToolKit QUIET)
  659. package_option(ARToolKit
  660. "Enable support for ARToolKit. This will be built into the 'vision' package.")
  661. package_status(ARToolKit "ARToolKit")
  662. #
  663. # ------------ VR integration ------------
  664. #
  665. # VRPN
  666. find_package(VRPN QUIET)
  667. package_option(VRPN
  668. "Enables support for connecting to VRPN servers. This is only needed if you
  669. are building Panda3D for a fixed VRPN-based VR installation.")
  670. package_status(VRPN "VRPN")
  671. #
  672. # ------------ Shader Pipeline ------------
  673. #
  674. find_package(glslang QUIET)
  675. package_option(glslang
  676. DEFAULT ON
  677. "Enables support for compiling GLSL and Cg shaders."
  678. IMPORTED_AS glslang::glslang glslang::MachineIndependent glslang::glslang-default-resource-limits)
  679. package_status(glslang "glslang")
  680. find_package(SPIRV-Cross QUIET)
  681. package_option(SPIRV-Cross
  682. DEFAULT ON
  683. "Necessary to support shaders on older OpenGL drivers and DirectX 9."
  684. FOUND_AS SPIRV_CROSS)
  685. package_status(SPIRV-Cross "spirv-cross")