BoostPython3.cmake 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # On Ubuntu 14.04, the libboost-python1.54-dev package comes with one library
  2. # for each Python version:
  3. # libboost_python-py27.so
  4. # libboost_python-py33.so
  5. # libboost_python-py34.so
  6. #
  7. # Boost upstream however installs Boost.Python3 libboost_python3.so, which is
  8. # what FindBoost.cmake is looking for. It looks for a library named
  9. # "libboost_${component}.so".
  10. #
  11. # On Gentoo instead, the >=dev-libs/boost-1.54 package provides boost library
  12. # with a name like:
  13. # libboost_python-2.7.so
  14. # libboost_python-3.3.so
  15. # libboost_python-3.4.so
  16. # depending on what python's targets you selected during install
  17. #
  18. # On Fedora >= 30 instead, the boost-python3-devel provides boost library with a
  19. # name like:
  20. # libboost_python37.so
  21. # depending on what python's targets you selected during install
  22. #
  23. # find_boost_python3() tries to find the package with different component
  24. # names. By default it tries "python3", "python-py$suffix" and
  25. # "python-$dotsuffix", where suffix is based on the `python_version` argument.
  26. # One can supply a custom component name by setting the
  27. # `CALAMARES_BOOST_PYTHON3_COMPONENT` variable at CMake time.
  28. set( CALAMARES_BOOST_PYTHON3_COMPONENT python3 CACHE STRING
  29. "Name of the Boost.Python component. If Boost.Python is installed as
  30. libboost_python-foo.so then this variable should be set to 'python-foo'."
  31. )
  32. include(FindPackageHandleStandardArgs)
  33. macro( _find_boost_python3_int boost_version componentname found_var )
  34. foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} ${componentname} )
  35. find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
  36. string( TOUPPER ${_fbp_name} _fbp_uc_name )
  37. if( Boost_${_fbp_uc_name}_FOUND )
  38. set( ${found_var} ${_fbp_uc_name} )
  39. break()
  40. endif()
  41. endforeach()
  42. endmacro()
  43. macro( find_boost_python3 boost_version python_version found_var )
  44. set( ${found_var} OFF )
  45. set( _fbp_found OFF )
  46. # turns "3.4.123abc" into "34"
  47. string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" _fbp_python_short_version ${python_version} )
  48. _find_boost_python3_int( ${boost_version} python-py${_fbp_python_short_version} _fbp_found )
  49. if (NOT _fbp_found)
  50. _find_boost_python3_int( ${boost_version} python${_fbp_python_short_version} _fbp_found )
  51. endif()
  52. if (NOT _fbp_found)
  53. # The following loop changes the searched name for Gentoo based distributions
  54. # turns "3.4.123abc" into "3.4"
  55. string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1.\\2" _fbp_python_short_version ${python_version} )
  56. _find_boost_python3_int( ${boost_version} python-${_fbp_python_short_version} _fbp_found )
  57. endif()
  58. set( ${found_var} ${_fbp_found} )
  59. # This is superfluous, but allows proper reporting in the features list
  60. if ( _fbp_found )
  61. find_package( Boost ${boost_version} COMPONENTS ${_fbp_found} )
  62. else()
  63. find_package( Boost ${boost_version} COMPONENTS Python )
  64. endif()
  65. set_package_properties(
  66. Boost PROPERTIES
  67. DESCRIPTION "A C++ library which enables seamless interoperability between C++ and Python 3."
  68. URL "http://www.boost.org"
  69. )
  70. endmacro()