现代CMake-依赖传播

时间:2019-12-17 11:50:03

标签: cmake

我们具有以下文件夹结构,同意它有点怪异,但这就是事实

LIB
   Cmakelist1
Project
   MainProject
     CMakeList2
     SubProject1
       CMakeList3
     SubProject2
       CmakeList4

问题1:Cmakelist2包含以下内容:

add_subdirectory(LIB/CMakelist1)

这是可以接受的还是现代CMake风格中有更好的方法吗? 这个问题看起来很好。

问题2:Cmakelist1使用target_link_libraries / target_include_directory构造构建静态库。

构建可执行文件Subproject1时,我将LIB1包括为

add_executable( SUBPROJECT1 )
target_link_libraries(SUBPROJECT1 PRIVATE LIB1)

编译SubProject1时,出现boost / xyz和abc包含目录的编译错误。我在LIB1中包含的PUBLIC包含标题,如

target_include_directory(LIB1 
     PUBLIC lib/include
     PUBLIC boost/include
     PUBLIC XYZ/include
     PUBLIC abc/include

如果SUBPROJECT1引用了LIB1的包含库和链接库,我应该再次包括它们吗?

示例: LIB / CMakeList1:

add_library(lib1 STATIC)
target_include_directory(lib1 
     PUBLIC lib/include
     PUBLIC boost/include
     PUBLIC XYZ/include
     PUBLIC abc/include
)
target_link_libraries(lib1 PUBLIC boost/lib1 xyz.a abc.so)

MainProject / CMakeList2:

add_subdirectory(../LIB1) #this works fine relative path is just for reference
add_subdirectory(subproject1)
add_subdirectory(subproject2)

SubProject1 / CMakeList3

add_executable( Proj1 )
target_sources( Proj1 x.cpp y.cpp z.cpp ) # these file have link to Lib1/xyz ->x1.h/y1.h etc

target_link_libraries( Proj1 PRIVATE lib1 ) 

我不想为target_link_librariesboost/xyz打电话给abc。 问题3:我是否需要在target_link_directory中再次为boost/xyzabc显式添加SubProject1

0 个答案:

没有答案