0

我有一个'int_tester' CMake 项目,它利用ExternalProject_Add它的'drv' 依赖项。现在,这个“drv”也是使用 CMake 构建的,它在其 include_directories() 中使用父目录。麻烦的是我不知道如何将这个父文件夹复制到里面ExternalProject_Add()

目录结构如下:

/  
|-common  
|-IP  
| |-int_tester  
| |-drv  

drv 的 CMakeLists.txt 看起来像:

add_library(SPT_driver STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)  
target_include_directories(SPT_driver
    PUBLIC  ${CMAKE_CURRENT_SOURCE_DIR}/api/
    PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../common/include/
)  

CMakeLists.txt 用于 int_tester,例如:

add_executable(int_tester ...)  
ExternalProject_Add(drv_ext
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/drv/drv_dir
    URL ${CMAKE_CURRENT_SOURCE_DIR}/../drv
    INSTALL_COMMAND ""
)
add_library(drv_import STATIC IMPORTED) #phony lib
add_dependencies (drv_import drv_ext) #link phony lib to the external proj
ExternalProject_Get_Property(drv_ext install_dir) #find out where the external proj is installed
set_property(TARGET drv_import PROPERTY IMPORTED_LOCATION ${install_dir}/src/drv_ext-build/obj/drv.a) #so that the phony lib can have a target
include_directories(${install_dir}/src/drv_ext/api) #and to make current executable dependent on api .h and .a of the externally built lib
target_link_libraries(int_tester drv_import)

可以看到, drv 取决于${CMAKE_CURRENT_SOURCE_DIR}/../../common/include/.

当'int_tester'构建'drv'(通过ExternalProject_Add)时,../../common/include/找不到文件夹(它不是由它带来的ExternalProject_Add)。即使我为这个公用文件夹添加了另一个伪造的 ExternProject,它的目录结构也不会与CMakeLists.txt“drv”所期望的目录结构相匹配。

请问我错过了什么?

4

1 回答 1

0

如果你想构建 'drv' 使用IP/drv它的源目录,明确指定SOURCE_DIR选项ExternalProject_Add

ExternalProject_Add(drv_ext
    PREFIX ${CMAKE_CURRENT_BINARY_DIR}/drv/drv_dir
    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../drv
    INSTALL_COMMAND ""
)

如果没有这个选项,源目录是从PREFX推导出来的(有关该推导的确切算法,请参阅文档)。


表示目录的选项URLExternalProject_Add应将其复制到源目录中。如果您不想复制,请不要使用该选项。

于 2017-06-06T16:00:07.457 回答