CMake解决方案子目录 [英] CMake solution sub-directory

查看:182
本文介绍了CMake解决方案子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型的CMake解决方案,其中包含5个项目。在此1个项目上创建Main可执行文件,在其余4个(3个静态+ 1个Dynamic)项目中创建与主项目链接的库。

I have a big CMake solution which contain 5 projects. On this 1 project creates Main executable and rest of the 4(3 static + 1 dynamic) projects creates libraries which are linked to the main project.

MainSolution:
 |-MainExecutablePrj
 |-StaticLib_1Prj
 |-StaticLib_2Prj
 |-StaticLib_3Prj
 |-DynamicLib_1Prj

整个项目将针对 Windows和Linux平台构建。现在,我需要在MainSolution下创建一个Sub目录,并创建一些使用 DynamicLib_1 (.lib / .so)的测试用例项目。到目前为止,我要做的是为每个测试用例提供不同的解决方案,并复制所需的.h文件和.lib(.so)文件,并构建测试用例解决方案。

The entire project is to be build for both windows and linux platforms. Now I need to create an Sub directory under MainSolution and create some testcase projects which uses the DynamicLib_1 (.lib/.so). So far what I have done is I will have different solution for each test cases and copy the required .h files and .lib(.so) files and build the test case solutions.

对我来说,维护源代码非常困难,每当动态库发生变化时,我都需要复制所有必要的文件并重新构建测试用例。
因此,我想在主项目中包含测试用例解决方案,以便每当更改动态库项目时,它也将构建测试用例项目。

Its very hard for me to maintain the source code and whenever there is an change on the dynamic library I need to copy all the necessary files and rebuild the test cases again. So I wanted to include the Test cases solutions inside my main project, so that whenever I change dynamic library project it builds the test case projects as well.

我非常想将这些测试用例解决方案添加为 MainSolution 下的项目,但我想创建子目录,并将所有测试用例项目放在该文件夹下。

I very well know to add those test case solutions as projects under the MainSolution but I wanted to create sub-directory and put all the test case projects under that folder.

MainSolution:
 |-TestCasesFolder
   |-TestCase_1Prj
   |-TestCase_2Prj
   |-...
 |-MainExecutablePrj 
 |-StaticLib_1Prj
 |-StaticLib_2Prj
 |-StaticLib_3Prj
 |-DynamicLib_1Prj

有人可以帮我吗

推荐答案

没有必要复制任何文件。

It should not be necessary to copy any files.


  • 让CMake找到 find_library 的库,并向子目录构建文件夹的路径添加提示

  • 让CMake包含子项目中带有<$的头文件c $ c> include_directories 。添加前缀以使其独立于平台。

  • Let CMake find the built libraries with find_library and add a hint to the path of subdirectories build folder
  • Let CMake include the header files from your subproject with include_directories. Add a prefix to make it platform independent.

关于测试:
子项目的所有单元测试都应位于该项目的结构,而不是根项目。将所有集成测试放在根项目中或作为根项目一部分的单独测试项目中。

Regarding the tests: All unit tests for a subproject should be places within the structure of this project and not in the root project. Place all integration tests in the root project or a separate test project as part of the root project.

示例结构

这篇关于CMake解决方案子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆