[project]
-- A.cpp
-- CMakeLists.txt
-- [B]
-- B.h
-- B.cpp
-- CMakeLists.txt
-- [C]
-- C.h
-- C.cpp
-- CMakeLists.txt
-- [D]
-- D.h
-- D.cpp
-- CMakeLists.txt
A<---B<---D
↑---C<---┘
最终构建的项目以A.cpp中的main函数为入口
B依赖D,但是D不是B的子目录,因此B目录下的CMakeLists.txt中如此添加D依赖:add_subdirectory(../D buildD1)
,必须指定第二个参数build_dir="buildD1"
,否则cmake报错 add_subdirectory not given a binary directory but the given sourcedirectory is not a subdirectory of...
C依赖D也是如此
cmake项目报错:
CMake Error at D/CMakeLists.txt:1 (add_library):add_library cannot create target "D" because another target with the same name already exists. The existing target is a static library created in source directory D. See documentation for policy CMP0002 for more details.