首页 > 解决方案 > 谷歌测试的 CMakeLists.txt 设置

问题描述

我创建了一个 Gtest 脚本,其中包含多个.h文件并测试文件中的函数.c。测试脚本在 VS2017 中运行良好,但是,我需要在 Ubuntu 中使用 CMake 构建它。我为我的文件创建了以下文件夹结构,它CMakeLists.txt在顶层有一个,以及两个源文件夹和测试文件夹,如下所示:

 CMakeLists.txt
├── source
│   ├── firstfile.c
│   ├── firstfile.h
│   ├── ...
│   ├── lastfile.c
│   ├── lastfile.h
│   └── CMakeLists.txt
├── test
│   ├── Test.cpp
│   └── CMakeLists.txt

Test.cpp文件调用源文件夹中的头文件,并使用 Gtest 测试.c文件中定义的函数。不熟悉CMake,请您指导我应该在三个CMakeLists.txt文件中包含哪些内容?我很感激。

标签: cmakegoogletest

解决方案


推荐阅读