CMake: how to use INTERFACE_INCLUDE_DIRECTORIES with ExternalProject?

前端 未结 1 1418
迷失自我
迷失自我 2021-02-02 02:09

I\'m trying to add external project as a library to my project using ExternalProject_Add:

ExternalProject_Add(
        xgboost
        GIT_REPOSITORY https://gi         


        
相关标签:
1条回答
  • 2021-02-02 02:42

    I'll post the final CMakeLists.txt to include xgboost into your project, it might be useful for someone, the solution to the problem above is to create directories during cmake configure phase (NOTE: I'm using OSX to build that, so you would need to use liblibxgboost.so for GNU/Linux instead of liblibxgboost.dylib):

    include(ExternalProject)
    
    ExternalProject_Add(
            xgboost
            GIT_REPOSITORY https://github.com/dmlc/xgboost.git
            GIT_TAG v0.60
            PREFIX ${CMAKE_CURRENT_BINARY_DIR}
            INSTALL_COMMAND ""
    )
    
    set(XGBOOST_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/src")
    set(XGBOOST_BINARY_PATH "${XGBOOST_PREFIX_PATH}/xgboost-build")
    
    set(XGBOOST_LIB_INCLUDE "${XGBOOST_PREFIX_PATH}/xgboost/include")
    set(DMLC_LIB_INCLUDE "${XGBOOST_PREFIX_PATH}/xgboost/dmlc-core/include")
    set(RABIT_LIB_INCLUDE "${XGBOOST_PREFIX_PATH}/xgboost/rabit/include")
    set(XGBOOST_BINARY_INCLUDE "${XGBOOST_LIB_INCLUDE};${DMLC_LIB_INCLUDE};${RABIT_LIB_INCLUDE}")
    
    # Hack to make it work, otherwise INTERFACE_INCLUDE_DIRECTORIES will not be propagated
    file(MAKE_DIRECTORY ${XGBOOST_LIB_INCLUDE})
    file(MAKE_DIRECTORY ${DMLC_LIB_INCLUDE})
    file(MAKE_DIRECTORY ${RABIT_LIB_INCLUDE})
    
    add_library(libxgboost IMPORTED STATIC GLOBAL)
    add_dependencies(libxgboost xgboost)
    
    set_target_properties(libxgboost PROPERTIES
            "IMPORTED_LOCATION" "${XGBOOST_BINARY_PATH}/liblibxgboost.dylib"
            "INTERFACE_INCLUDE_DIRECTORIES" "${XGBOOST_BINARY_INCLUDE}"
    )
    
    0 讨论(0)
提交回复
热议问题