{"id":20734163,"url":"https://github.com/tmoonlight/lwm_migratetest","last_synced_at":"2026-03-19T17:16:51.790Z","repository":{"id":41455757,"uuid":"503786814","full_name":"tmoonlight/LWM_MigrateTest","owner":"tmoonlight","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-02T05:33:23.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-23T14:47:40.625Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tmoonlight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-15T13:53:31.000Z","updated_at":"2022-06-15T13:55:34.000Z","dependencies_parsed_at":"2022-08-22T20:01:39.868Z","dependency_job_id":null,"html_url":"https://github.com/tmoonlight/LWM_MigrateTest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"TheLartians/ModernCppStarter","purl":"pkg:github/tmoonlight/LWM_MigrateTest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmoonlight%2FLWM_MigrateTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmoonlight%2FLWM_MigrateTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmoonlight%2FLWM_MigrateTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmoonlight%2FLWM_MigrateTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tmoonlight","download_url":"https://codeload.github.com/tmoonlight/LWM_MigrateTest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tmoonlight%2FLWM_MigrateTest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29016665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T16:17:30.374Z","status":"ssl_error","status_checked_at":"2026-02-02T15:58:50.469Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T05:28:58.553Z","updated_at":"2026-02-02T18:03:08.518Z","avatar_url":"https://github.com/tmoonlight.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n \n# LWM_MigrateTest(搬运TheLartians/ModernCppStarter)\n\n## 前言\n    建立一个新的C++项目通常需要大量的准备工作和模板代码，对于带有测试、可执行文件和持续集成的现代C++项目更是如此。\n这个模板是在许多以前的项目中学习的结果，有助于减少建立现代C++项目所需的工作。\n\n## 特性\n\n- [现代化的CMake实践](https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/)\n- 兼容单头库以及任意规模的项目\n- 库和可执行代码完全分离\n- 集成测试套件\n- 通过[GitHub Actions](https://help.github.com/en/actions/)进行持续集成\n- 通过[codecov]进行代码覆盖(https://codecov.io)\n- 通过[Clang-format](https://clang.llvm.org/docs/ClangFormat.html)和[cmake-format](https://github.com/cheshirekow/cmake_format)的[Format.cmake](https://github.com/TheLartians/Format.cmake)强制执行代码格式化\n- 通过[CPM.cmake](https://github.com/TheLartians/CPM.cmake)进行可重复的依赖性管理\n- 通过[PackageProject.cmake](https://github.com/TheLartians/PackageProject.cmake)实现具有自动版本信息和头文件生成的可安装目标\n- 通过[Doxygen](https://www.doxygen.nl)和[GitHub Pages](https://pages.github.com)自动进行[文档](https://thelartians.github.io/ModernCppStarter)和部署\n- 支持[sanitizer工具，以及更多工具](#additional-tools)\n\n## 使用方法\n\n### 根据你的需要调整模板\n\n- 使用这个 repo [作为一个模板](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-from-a-template)。\n- 在相关的CMakeLists.txt中用你的项目名称替换所有出现的 \"Greeter\"。\n  - 这里的大写字母很重要。`Greeter`是指项目的名称，而`greeter`用于文件名。\n  - 记得重命名`include/greeter`目录，以使用你的项目的小写名称，并相应地更新所有相关的`#include`s。\n- 用你自己的源文件替换\n- 对于只用头的库：见[CMakeLists.txt](CMakeLists.txt)中的注释\n- 将[你的项目的codecov token](https://docs.codecov.io/docs/quick-start)添加到你的项目的github secrets的`CODECOV_TOKEN`下。\n- 编码愉快!\n\n最终，你可以删除任何不使用的文件，例如独立目录或与你的项目无关的github工作流程。\n随意用适合你的项目的许可证来替换。\n\n为了干净地分离库和子项目的代码，外部的`CMakeList.txt`只定义了库本身，而测试和其他子项目则自成一体，放在自己的目录里。\n在开发过程中，通常方便[一次性构建所有子项目]（#build-everything-at-once）。\n\n### 构建和运行独立的目标\n\n使用下面的命令来构建和运行可执行的目标。\n\n```bash\ncmake -S standalone -B build/standalone\ncmake --build build/standalone\n./build/standalone/Greeter --help\n```\n\n### 构建和运行测试套件\n\n在项目的根目录下使用以下命令来运行测试套件。\n\n```bash\ncmake -S test -B build/test\ncmake --build build/test\nCTEST_OUTPUT_ON_FAILURE=1 cmake --build build/test --target test\n\n# 或者直接调用可执行文件。\n./build/test/GreeterTests\n```\n\n\n要收集代码覆盖率信息，请使用`-DENABLE_TEST_COVERAGE=1`选项运行CMake。\n\n### 运行clang-format\n\n在项目的根目录下使用以下命令来检查和修复C++和CMake的源码风格。\n这需要在当前系统中安装_clang-format_、_cmake-format_和_pyyaml_。\n\n```bash\ncmake -S test -B build/test\n\n# 查看变化\ncmake --build build/test --target format\n\n# 应用改动\ncmake --build build/test --target fix-format\n```\n\n详见 [Format.cmake](https://github.com/TheLartians/Format.cmake)。\n\n### 构建文档\n\n每当[GitHub Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository)被创建时，文档就会被自动构建并[发布](https://thelartians.github.io/ModernCppStarter)。\n要手动构建文档，请调用以下命令。\n\n```bash\ncmake -S documentation -B build/doc\ncmake --build build/doc --target GenerateDocs\n# 查看文档\n打开 build/doc/doxygen/html/index.html\n```\n\n要在本地构建文档，你需要在你的系统上安装Doxygen、jinja2和Pygments。\n\n### 一次性构建所有东西\n\n该项目还包括一个`all`目录，允许同时构建所有目标。\n这在开发过程中很有用，因为它可以将所有的子项目暴露在你的IDE中，避免了库的重复构建。\n\n```bash\ncmake -S all -B build\ncmake --build build\n```\n# 运行测试\n./build/test/GreeterTests\n# 格式化代码\ncmake --build build --target fix-format\n# 运行单机\n./build/standalone/Greeter --help\n# 构建文档\n```\ncmake --build build --target GenerateDocs\n```\n\n### 额外的工具\n\n测试和独立子项目包括[tools.cmake](cmake/tools.cmake)文件，用于通过CMake配置参数按需导入额外工具。\n目前支持以下内容。\n\n#### Sanitizers\n\n可以通过在CMake中配置`-DUSE_SANITIZER=\u003cAddress | Memory | MemoryWithOrigins | Undefined | Thread | Leak | 'Address;Undefined'\u003e来启用Sanitizers。\n\n#### 静态分析器\n\n静态分析器可以通过设置`-DUSE_STATIC_ANALYZER=\u003cclang-tidy | iwyu | cppcheck\u003e`来启用，或者设置引号中的组合，用分号隔开。\n默认情况下，分析器会自动查找配置文件，如`.clang-format`。\n其他参数可以通过设置`CLANG_TIDY_ARGS`、`IWYU_ARGS`或`CPPCHECK_ARGS`变量传递给分析器。\n\n#### Ccache\n\n缓存可以通过配置`-DUSE_CCACHE=\u003cON | OFF\u003e`来启用。\n\n## FAQ\n\n\u003e 我可以将其用于仅有头文件的库吗？\n\n可以，但是你需要将库的类型改为 \"INTERFACE \"库，如[CMakeLists.txt](CMakeLists.txt)中所记载的。\n参见 [here](https://github.com/TheLartians/StaticTypeInfo) 以了解一个基于模板的纯头文件库的例子。\n\n\u003e 我不需要一个独立的目标/文档。我怎样才能去掉它？\n\n只需删除单机/文档目录和根据github工作流文件。\n\n\u003e 我可以在同一时间开发单机独立程序和测试程序吗？/ 我怎样才能告诉我的IDE所有的子项目？\n\n为了保持模板的模块化，所有从库中衍生出来的子项目都被分离到它们自己的CMake模块中。\n这种方法使第三方项目重新使用项目库的代码变得微不足道。\n为了让IDE看到项目的全部范围，该模板包括`all`目录，它将为所有子项目创建一个单一的构建。\n使用这个目录作为主目录以获得最佳的IDE支持。\n\n\u003e 我看到你在使用`GLOB`在CMakeLists.txt中添加源文件。这不是很邪恶吗？\n\nGlob被认为是不好的，因为对源文件结构的任何改变[可能不会被CMake的构建器自动捕获](https://cmake.org/cmake/help/latest/command/file.html#filesystem)，你需要在改变时手动调用CMake。\n  我个人更喜欢 \"GLOB \"解决方案，因为它很简单，但可以自由地将其改为明确列出源文件。\n\n\u003e 我想创建依赖我的库的额外目标。我应该修改主要的CMakeLists以包括它们吗？\n\n避免从库的CMakeLists中包括派生项目（尽管这在C++世界中很常见），因为这有效地颠倒了依赖关系树，使构建系统难以推理。\n相反，用CMakeLists创建一个新的目录或项目，将该库作为依赖关系加入（例如，像[standalone](standalone/CMakeLists.txt)目录）。\n根据不同的类型，可能有必要将这些组件移到一个单独的仓库中，并引用库的特定提交或版本。\n这样做的好处是单个库和组件可以独立改进和更新。\n\n\u003e 你建议使用CPM.cmake来添加外部依赖。这是否会迫使我的库的用户也使用 CPM.cmake？\n\n[CPM.cmake](https://github.com/TheLartians/CPM.cmake)对于库的用户来说应该是不可见的，因为它是一个独立的CMake脚本。\n如果出现问题，用户可以通过定义 CMake 或 env 变量 [`CPM_USE_LOCAL_PACKAGES`](https://github.com/cpm-cmake/CPM.cmake#options) 来选择退出，这将覆盖所有对 `CPMAddPackage` 的调用，并使用相应的 `find_package` 调用。\n这也使用户能够使用他们最喜欢的外部C++依赖管理器，如vcpkg或Conan来使用该项目。\n\n\u003e 我可以离线配置和构建我的项目吗？\n\n构建项目不需要互联网连接，但是当使用CPM时，缺失的依赖项会在配置时下载。\n为了避免重复下载，强烈建议设置一个CPM.cmake缓存目录，例如。`export CPM_SOURCE_CACHE=$HOME/.cache/CPM`。\n这将使浅层克隆成为可能，并允许离线配置的依赖性在缓存中已经可用。\n\n\u003e 我可以使用CPack为我的项目创建一个软件包安装程序吗？\n\n由于有很多可能的选项和配置，这不在本模板的范围内（尚未）。请参阅 [CPack 文档](https://cmake.org/cmake/help/latest/module/CPack.html) 以了解更多关于设置CPack安装器的信息。\n\n\u003e 这太多了，我只想玩玩C++代码和测试一些库。\n\n也许 [MiniCppStarter](https://github.com/TheLartians/MiniCppStarter) 是适合你的东西!\n\n## 相关项目和替代方案\n\n- [**ModernCppStarter \u0026 PVS-Studio Static Code Analyzer**](https://github.com/viva64/pvs-studio-cmake-examples/tree/master/modern-cpp-starter): 关于如何使用ModernCppStarter与PVS-Studio静态代码分析器的官方说明。\n- [**lefticus/cpp_starter_project**](https://github.com/lefticus/cpp_starter_project/)。一个流行的C++启动器项目，创建于2017年。\n- [**filipdutescu/modern-cpp-template**](https://github.com/filipdutescu/modern-cpp-template)。一个最近的启动项目，使用更传统的方法进行CMake结构和依赖性管理。\n- [**vector-of-bool/pitchfork**](https://github.com/vector-of-bool/pitchfork/)。Pitchfork是一套C++项目公约。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmoonlight%2Flwm_migratetest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftmoonlight%2Flwm_migratetest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftmoonlight%2Flwm_migratetest/lists"}