Skip to main content
Version: 1.1.1

教程: kmcmake 工程生成

本教程向您展示如何通过 CMake 和 kmcmake 创建使用 C++“Hello World”程序。您将一键生成一个基于CMake构建系统的简单的应用程序。

先决条件

重要

cmake 最低要求 3.24.3,请正确安装cmake

1 - 创建项目

创建项目目录:

mkdir hello

进入到目录中:

cd hello

2 - 初始化项目

初始化项目名称为 "hello" 的c++项目:

>kmcmake hello
kmpkg root directory "/data/package/kmpkg"
current project directory "/data/gitee/kumo-pub/pkg-temp"
your project name is hello
-- The CXX compiler identification is GNU 9.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /data/gitee/kumo-pub/pkg-temp/kmncmake_temp_build
-- Install configuration: ""
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb/postrm
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb/.gitignore
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb/preinst
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb/prerm
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/deb/postinst.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/hello_cpack_config.cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm/postrm
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm/.gitignore
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm/preinst
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm/prerm
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/rpm/postinst.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/hello_cxx_config.cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/hello_test.cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/hello_deps.cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./cmake/hello_config.cmake.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/examples/foo_ex.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/examples/CMakeLists.txt
-- Installing: /data/gitee/kumo-pub/pkg-temp/./CMakeLists.txt
-- Installing: /data/gitee/kumo-pub/pkg-temp/./LICENSE
-- Installing: /data/gitee/kumo-pub/pkg-temp/./README.md
-- Installing: /data/gitee/kumo-pub/pkg-temp/./benchmark
-- Installing: /data/gitee/kumo-pub/pkg-temp/./benchmark/CMakeLists.txt
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/README.md
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/copts
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/copts/generate_copts.py
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/copts/copts.py
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/kmcmake_module.cmake
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/package
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/package/pkg_dump_template.pc.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/package/CPack.STGZ_Header.sh.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/./kmcmake/package/README.md
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/api.h
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/CMakeLists.txt
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/foo.h
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/main.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/version.h.in
-- Installing: /data/gitee/kumo-pub/pkg-temp/hello/foo.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/foo_test.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/foo_doctest.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/args_test.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/CMakeLists.txt
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/pass_test.cc
-- Installing: /data/gitee/kumo-pub/pkg-temp/tests/raw_test.cc

3 - 编译以及运行项目

1 - 配置 cmake

配置cmake configure:

cmake -S . -B build

2 - 编译项目

编译项目命令:

cmake --build build -j 4

3 - 运行项目

编译项目命令:

./build/hello/shared_main