CMake: refactor boost.python search

- improve description of Python dependencies
 - refactor search per python-version-style
 - report on features and found boost modules the standard way
This commit is contained in:
Adriaan de Groot 2017-09-23 03:02:27 -04:00
parent 6f1f08f728
commit 81db2bad5f
2 changed files with 38 additions and 36 deletions

View file

@ -20,38 +20,50 @@
# "python-$dotsuffix", where suffix is based on the `python_version` argument.
# One can supply a custom component name by setting the
# `CALAMARES_BOOST_PYTHON3_COMPONENT` variable at CMake time.
set( CALAMARES_BOOST_PYTHON3_COMPONENT python3 CACHE STRING
"Name of the Boost.Python component. If Boost.Python is installed as
libboost_python-foo.so then this variable should be set to 'python-foo'."
)
macro( find_boost_python3 boost_version python_version found_var )
set( ${found_var} OFF )
include(FindPackageHandleStandardArgs)
# turns "3.4.123abc" into "34"
string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" _fbp_python_short_version ${python_version} )
foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} python-py${_fbp_python_short_version} )
macro( _find_boost_python3_int boost_version componentname found_var )
foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} ${componentname} )
find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
string( TOUPPER ${_fbp_name} _fbp_uc_name )
if( Boost_${_fbp_uc_name}_FOUND )
set( ${found_var} ON )
set( ${found_var} ${_fbp_uc_name} )
break()
endif()
endforeach()
endmacro()
if (NOT ${found_var})
macro( find_boost_python3 boost_version python_version found_var )
set( ${found_var} OFF )
set( _fbp_found OFF )
# turns "3.4.123abc" into "34"
string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1\\2" _fbp_python_short_version ${python_version} )
_find_boost_python3_int( ${boost_version} python-py${_fbp_python_short_version} _fbp_found )
if (NOT _fbp_found)
# The following loop changes the searched name for Gentoo based distributions
# turns "3.4.123abc" into "3.4"
string( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\..*" "\\1.\\2" _fbp_python_short_version ${python_version} )
foreach( _fbp_name ${CALAMARES_BOOST_PYTHON3_COMPONENT} python-${_fbp_python_short_version} )
find_package( Boost ${boost_version} QUIET COMPONENTS ${_fbp_name} )
string( TOUPPER ${_fbp_name} _fbp_uc_name )
if( Boost_${_fbp_uc_name}_FOUND )
set( ${found_var} ON )
break()
endif()
endforeach()
_find_boost_python3_int( ${boost_version} python-${_fbp_python_short_version} _fbp_found )
endif()
set( ${found_var} ${_fbp_found} )
# This is superfluous, but allows proper reporting in the features list
if ( _fbp_found )
find_package( Boost ${boost_version} COMPONENTS ${_fbp_found} )
else()
find_package( Boost ${boost_version} COMPONENTS Python )
endif()
set_package_properties(
Boost PROPERTIES
DESCRIPTION "A C++ library which enables seamless interoperability between C++ and Python 3."
URL "http://www.boost.org"
)
endmacro()