Coder Social home page Coder Social logo

cmaketest's Introduction

使用CMake构建具有菱形依赖关系的项目

项目文件结构:

[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

1. 项目依赖关系如下:

A<---B<---D
 ↑---C<---┘

最终构建的项目以A.cpp中的main函数为入口

2. 一些问题

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也是如此

3. 最后

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.