Add versioned targets (Boost::python27) for compatibility

This commit is contained in:
Peter Dimov
2019-06-06 19:20:44 +03:00
parent 56e203e248
commit daa6552eae
2 changed files with 16 additions and 2 deletions
+10
View File
@@ -127,8 +127,18 @@ macro(boost_find_component comp req)
# FindBoost compatibility variables: Boost_LIBRARIES, Boost_<C>_LIBRARY
if(__boost_comp_found)
list(APPEND Boost_LIBRARIES Boost::${__boost_comp_nv})
set(Boost_${_BOOST_COMP}_LIBRARY Boost::${__boost_comp_nv})
if(NOT "${comp}" STREQUAL "${__boost_comp_nv}" AND NOT TARGET Boost::${comp})
# Versioned target alias (f.ex. Boost::python27) for compatibility
add_library(Boost::${comp} INTERFACE IMPORTED)
set_property(TARGET Boost::${comp} APPEND PROPERTY INTERFACE_LINK_LIBRARIES Boost::${__boost_comp_nv})
endif()
endif()
unset(_BOOST_REQUIRED)
+6 -2
View File
@@ -10,6 +10,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/../BoostVersion.cmake)
find_package(PythonLibs 2.7 REQUIRED)
set(component python)
if(USE_BOOST_PACKAGE)
# test the versioned pythonXY component for backward compatibility
@@ -19,7 +21,9 @@ if(USE_BOOST_PACKAGE)
list(GET PYTHONLIBS_VERSION_LIST 0 PYTHONLIBS_VERSION_MAJOR)
list(GET PYTHONLIBS_VERSION_LIST 1 PYTHONLIBS_VERSION_MINOR)
find_package(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS python${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR})
set(component python${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR})
find_package(Boost ${BOOST_VERSION} EXACT REQUIRED COMPONENTS ${component})
else()
@@ -31,7 +35,7 @@ else()
endif()
add_executable(main quick.cpp)
target_link_libraries(main Boost::python ${PYTHON_LIBRARIES})
target_link_libraries(main Boost::${component} ${PYTHON_LIBRARIES})
target_include_directories(main PRIVATE ${PYTHON_INCLUDE_DIRS})
enable_testing()