BoostPython3.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. # find_boost_python3() tries to find the package with different component
  19. # names. By default it tries "python3", "python-py$suffix" and
  20. # "python-$dotsuffix", where suffix is based on the `python_version` argument.
  21. # One can supply a custom component name by setting the
  22. # `CALAMARES_BOOST_PYTHON3_COMPONENT` variable at CMake time.
  23. set( CALAMARES_BOOST_PYTHON3_COMPONENT python3 CACHE STRING
  24. "Name of the Boost.Python component. If Boost.Python is installed as
  25. libboost_python-foo.so then this variable should be set to 'python-foo'."
  26. )
  27. include(FindPackageHandleStandardArgs)
  28. macro( _find_boost_python3_int boost_version componentname found_var )
  29. foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} ${componentname} )
  30. find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
  31. string( TOUPPER ${_fbp_name} _fbp_uc_name )
  32. if( Boost_${_fbp_uc_name}_FOUND )
  33. set( ${found_var} ${_fbp_uc_name} )
  34. break()
  35. endif()
  36. endforeach()
  37. endmacro()
  38. macro( find_boost_python3 boost_version python_version found_var )
  39. set( ${found_var} OFF )
  40. set( _fbp_found OFF )
  41. # turns "3.4.123abc" into "34"
  42. string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" _fbp_python_short_version ${python_version} )
  43. _find_boost_python3_int( ${boost_version} python-py${_fbp_python_short_version} _fbp_found )
  44. if (NOT _fbp_found)
  45. # The following loop changes the searched name for Gentoo based distributions
  46. # turns "3.4.123abc" into "3.4"
  47. string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1.\\2" _fbp_python_short_version ${python_version} )
  48. _find_boost_python3_int( ${boost_version} python-${_fbp_python_short_version} _fbp_found )
  49. endif()
  50. set( ${found_var} ${_fbp_found} )
  51. # This is superfluous, but allows proper reporting in the features list
  52. if ( _fbp_found )
  53. find_package( Boost ${boost_version} COMPONENTS ${_fbp_found} )
  54. else()
  55. find_package( Boost ${boost_version} COMPONENTS Python )
  56. endif()
  57. set_package_properties(
  58. Boost PROPERTIES
  59. DESCRIPTION "A C++ library which enables seamless interoperability between C++ and Python 3."
  60. URL "http://www.boost.org"
  61. )
  62. endmacro()