cmake: fix build WITH_SYSTEM_BOOST=ON

FindBoost.cmake from upstream cmake now finds python libraries like

find_package(Boost 1.67 python36)

and it export targets like Boost::python36

but we are still linking against Boost::python, so to be compatible
with FindBoost.cmake, we need to update BuildBoost.cmake and
mgr/CMakeLists.txt accordingly. in other words, to export
Boost::python36 and to link Boost::python36.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2018-08-09 14:07:10 +08:00
parent bfd0cde8ff
commit 46c8b04a98
3 changed files with 28 additions and 20 deletions

View File

@ -485,6 +485,7 @@ if(WITH_MGR)
set(MGR_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
set(MGR_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
set(MGR_PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR})
set(MGR_PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR})
# Boost dependency check deferred to Boost section
endif(WITH_MGR)
@ -597,7 +598,8 @@ set(BOOST_COMPONENTS
set(BOOST_HEADER_COMPONENTS container)
if(WITH_MGR)
list(APPEND BOOST_COMPONENTS python)
list(APPEND BOOST_COMPONENTS
python${MGR_PYTHON_VERSION_MAJOR}${MGR_PYTHON_VERSION_MINOR})
endif()
if(WITH_BOOST_CONTEXT)
list(APPEND BOOST_COMPONENTS context coroutine)

View File

@ -65,9 +65,20 @@ function(do_build_boost version)
set(BOOST_CXXFLAGS "-fPIC -w") # check on arm, etc <---XXX
list(APPEND boost_features "cxxflags=${BOOST_CXXFLAGS}")
list(FIND Boost_BUILD_COMPONENTS "python" with_python)
list_replace(Boost_BUILD_COMPONENTS "unit_test_framework" "test")
string(REPLACE ";" "," boost_with_libs "${Boost_BUILD_COMPONENTS}")
set(boost_with_libs)
foreach(c ${Boost_BUILD_COMPONENTS})
if(c MATCHES "^python([0-9])\$")
set(with_python_version "${CMAKE_MATCH_1}")
list(APPEND boost_with_libs "python")
elseif(c MATCHES "^python([0-9])\\.?([0-9])\$")
set(with_python_version "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}")
list(APPEND boost_with_libs "python")
else()
list(APPEND boost_with_libs ${c})
endif()
endforeach()
list_replace(boost_with_libs "unit_test_framework" "test")
string(REPLACE ";" "," boost_with_libs "${boost_with_libs}")
# build b2 and prepare the project-config.jam for boost
set(configure_command
./bootstrap.sh --prefix=<INSTALL_DIR>
@ -97,12 +108,12 @@ function(do_build_boost version)
" : "
" : ${CMAKE_CXX_COMPILER}"
" ;\n")
if(with_python GREATER -1)
set(python_ver ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
if(with_python_version)
find_package(PythonLibs ${with_python_version} QUIET REQUIRED)
string(REPLACE ";" " " python_includes "${PYTHON_INCLUDE_DIRS}")
file(APPEND ${user_config}
"using python"
" : ${python_ver}"
" : ${with_python_version}"
" : ${PYTHON_EXECUTABLE}"
" : ${python_includes}"
" : ${PYTHON_LIBRARIES}"
@ -111,12 +122,8 @@ function(do_build_boost version)
list(APPEND b2 --user-config=${user_config})
list(APPEND b2 toolset=${toolset})
if(with_python GREATER -1)
if(NOT PYTHONLIBS_FOUND)
message(FATAL_ERROR "Please call find_package(PythonLibs) first for building "
"Boost.Python")
endif()
list(APPEND b2 python=${python_ver})
if(with_python_version)
list(APPEND b2 python=${with_python_version})
endif()
set(build_command
@ -197,17 +204,15 @@ macro(build_boost version)
add_library(Boost::${c} SHARED IMPORTED)
endif()
add_dependencies(Boost::${c} Boost)
if(c STREQUAL python)
set(buildid "${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
else()
set(buildid "")
if(c MATCHES "^python")
set(c "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
endif()
if(Boost_USE_STATIC_LIBS)
set(Boost_${upper_c}_LIBRARY
${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}boost_${c}${buildid}${CMAKE_STATIC_LIBRARY_SUFFIX})
${install_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}boost_${c}${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(Boost_${upper_c}_LIBRARY
${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}boost_${c}${buildid}${CMAKE_SHARED_LIBRARY_SUFFIX})
${install_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}boost_${c}${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
unset(buildid)
set_target_properties(Boost::${c} PROPERTIES

View File

@ -24,7 +24,8 @@ target_include_directories(ceph-mgr SYSTEM PRIVATE "${PYTHON_INCLUDE_DIRS}")
target_link_libraries(ceph-mgr
osdc client heap_profiler
global-static ceph-common
Boost::python ${MGR_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
Boost::python${MGR_PYTHON_VERSION_MAJOR}${MGR_PYTHON_VERSION_MINOR}
${MGR_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
set_target_properties(ceph-mgr PROPERTIES
POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
install(TARGETS ceph-mgr DESTINATION bin)