CMake FIND_PACKAGE succeeds but returns wrong path

后端 未结 6 1403
日久生厌
日久生厌 2020-12-14 19:57

I\'m trying to have CMake 2.8.6 link to boost::program_options using the following code in my CMakeLists.txt

FIND_PACKAGE(Boost COMPONENTS program_options RE         


        
6条回答
  •  悲&欢浪女
    2020-12-14 21:00

    The problem is with the boost-devel distributed file: /usr/lib64/boost/Boost-relwithdebinfo.cmake

    The cmake-2.6 package does not use this file at all, because the FindBoost.cmake file returns (correct) full-paths to boost libraries. The cmake28-2.8.8 FindBoost.cmake file returns library strings like "boost_date_time-mt-shared", which are targets defined in /usr/lib64/boost/Boost-relwithdebinfo.cmake.

    At the very top of /usr/lib64/boost/Boost-relwithdebinfo.cmake, a variable named _IMPORT_PREFIX is defined from the location of the cmake file itself, and then used like so:

    #----------------------------------------------------------------
    # Generated CMake target import file for configuration "RelWithDebInfo".
    #----------------------------------------------------------------
    
    # Commands may need to know the format version.
    SET(CMAKE_IMPORT_FILE_VERSION 1)
    
    # Compute the installation prefix relative to this file.
    GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
    GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    
    # Import target "boost_date_time-static" for configuration "RelWithDebInfo"
    SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
    SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
      IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
      )
    

    This sets _IMPORT_PREFIX to "/usr/lib64", which is concatenated with another string that has /lib64/ in it as well. I found that if I simply change the file to include a 3rd GET_FILENAME_COMPONENT call, it works fine. Like so:

    #----------------------------------------------------------------
    # Generated CMake target import file for configuration "RelWithDebInfo".
    #----------------------------------------------------------------
    
    # Commands may need to know the format version.
    SET(CMAKE_IMPORT_FILE_VERSION 1)
    
    # Compute the installation prefix relative to this file.
    GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
    GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    GET_FILENAME_COMPONENT(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
    
    # Import target "boost_date_time-static" for configuration "RelWithDebInfo"
    SET_PROPERTY(TARGET boost_date_time-static APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
    SET_TARGET_PROPERTIES(boost_date_time-static PROPERTIES
      IMPORTED_LOCATION_RELWITHDEBINFO "${_IMPORT_PREFIX}/lib64/libboost_date_time.a"
      )
    

提交回复
热议问题