我有一个' 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/
)
int_tester的CMakeLists.txt如:
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,它的目录结构也不会匹配' drv'的CMakeLists.txt
所期望的目录结构。
我错过了什么?
答案 0 :(得分:0)
如果你想建立' drv'使用IP/drv
作为源目录,明确指定ExternalProject_Add
的 SOURCE_DIR 选项:
ExternalProject_Add(drv_ext
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/drv/drv_dir
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../drv
INSTALL_COMMAND ""
)
如果没有此选项,源目录将从 PREFX 推断出来(有关该扣除的确切算法,请参阅documentation。)
ExternalProject_Add
的选项网址表示目录,应该复制到源代码中。如果您不想复制,请不要使用该选项。