FindBoost fails to find boost python libraries compiled with python 3.10
Forum question: https://discourse.cmake.org/t/findboost-cmake-with-python-3-10/4586 Regexps in FindBoost assumes that python's minor version has only one digit. That's not true for 3.10. The following diff fixes problem for me (however it's probably better to allow any number of digits in version).
--- Modules/FindBoost.cmake.orig 2021-12-16 12:28:12 UTC
+++ Modules/FindBoost.cmake
@@ -393,7 +393,7 @@ cmake_policy(SET CMP0102 NEW) # if mark_as_advanced(no
function(_boost_get_existing_target component target_var)
set(names "${component}")
- if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9])?$")
+ if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9]{1,2})?$")
# handle pythonXY and numpyXY versioned components and also python X.Y, mpi_python etc.
list(APPEND names
"${CMAKE_MATCH_1}${CMAKE_MATCH_2}" # python
@@ -410,7 +410,7 @@ function(_boost_get_existing_target component target_v
if(TARGET "${prefix}::${name}")
# The target may be an INTERFACE library that wraps around a single other
# target for compatibility. Unwrap this layer so we can extract real info.
- if("${name}" MATCHES "^(python|numpy|mpi_python)([1-9])([0-9])$")
+ if("${name}" MATCHES "^(python|numpy|mpi_python)([1-9])([0-9]{1,2})$")
set(name_nv "${CMAKE_MATCH_1}")
if(TARGET "${prefix}::${name_nv}")
get_property(type TARGET "${prefix}::${name}" PROPERTY TYPE)
@@ -433,7 +433,7 @@ endfunction()
function(_boost_get_canonical_target_name component target_var)
string(TOLOWER "${component}" component)
- if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9])?$")
+ if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9]{1,2})?$")
# handle pythonXY and numpyXY versioned components and also python X.Y, mpi_python etc.
set(${target_var} "Boost::${CMAKE_MATCH_1}${CMAKE_MATCH_2}" PARENT_SCOPE)
else()
Edited by Brad King