{"id":15579864,"url":"https://github.com/neutree/c_cpp_project_framework","last_synced_at":"2025-10-10T01:05:53.467Z","repository":{"id":45527086,"uuid":"190180781","full_name":"Neutree/c_cpp_project_framework","owner":"Neutree","description":" CMake build system( framework)  with kconfig support for C/CPP projects","archived":false,"fork":false,"pushed_at":"2024-03-31T09:56:51.000Z","size":1928,"stargazers_count":185,"open_issues_count":0,"forks_count":42,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-08-22T13:04:04.868Z","etag":null,"topics":["build","c","cmake","compile","cpp","framework","gui-configuration","kconfig","kconfig-support","make","project","template","wasm"],"latest_commit_sha":null,"homepage":"https://neucrack.com/p/276","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neutree.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-04T10:34:08.000Z","updated_at":"2025-07-25T01:57:47.000Z","dependencies_parsed_at":"2024-03-31T10:46:12.941Z","dependency_job_id":null,"html_url":"https://github.com/Neutree/c_cpp_project_framework","commit_stats":{"total_commits":108,"total_committers":2,"mean_commits":54.0,"dds":0.03703703703703709,"last_synced_commit":"435427099998a90fa61e27af48a6565da82a29fe"},"previous_names":[],"tags_count":1,"template":true,"template_full_name":null,"purl":"pkg:github/Neutree/c_cpp_project_framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neutree%2Fc_cpp_project_framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neutree%2Fc_cpp_project_framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neutree%2Fc_cpp_project_framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neutree%2Fc_cpp_project_framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neutree","download_url":"https://codeload.github.com/Neutree/c_cpp_project_framework/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neutree%2Fc_cpp_project_framework/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002408,"owners_count":26083373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["build","c","cmake","compile","cpp","framework","gui-configuration","kconfig","kconfig-support","make","project","template","wasm"],"created_at":"2024-10-02T19:21:30.378Z","updated_at":"2025-10-10T01:05:53.433Z","avatar_url":"https://github.com/Neutree.png","language":"Python","readme":"C CPP Project Framework (Template)\n===================\n\n[中文](./README_ZH.md)\n\n**Simple** and **configurable** `C/C++` project/SDK template \n\u003e `CMake` build system and support Kconfig with `GUI` configuration\n\nBased on this project, you can quickly build your project construction system and reduce many unnecessary troubles~\n\nIf it helps you, please give a little star in the upper right corner~~ If needs improvement, just create an [issue](https://github.com/Neutree/c_cpp_project_framework/issues/new).  `(´ε｀ ʃƪ)♡`\n\n\nThe target developer of this project:\n\n* Developers who are preparing to write `SDK` and need to write their own build system\n* Preparing to start writing a project who needs to write a build system\n* Who don't know much about `CMake`, but want to learn `CMake`\n* Who want to refactor the code engineering build system, maybe because of th bad old messy build system\n* Who want to add a very useful configuration system to the build system, you can quickly add and delete code modules as needed, and it is best to have an GUI configuration.\n* Who want the project to generate a variety of `IDE` supported projects.\n\n\n![](assets/image/build.gif)\n\n\n## Features\n\n* The syntax is simple, no knowledge of `Makefile` or `CMake` is required, and it is very simple to use only by modifying the value of the variable based on the template\n* Project structure based on the concept of component, which is convenient for building a project structure with a clear hierarchical structure\n* Calling between components only requires one statement to specify the dependencies (such as `list(APPEND ADD_REQUIREMENTS component1)`), without setting extra variables such as `INCLUDE path` to call the content of the dependent component in the source code\n* Use `Kconfig` to enable project components and code to be tailored and configured to facilitate the project to meet different needs\n* Conveniently introduce static libraries (`.a`) and dynamic libraries (`.so`) (such as `list(APPEND ADD_STATIC_LIB \"lib/libtest.a\")`)\n* Conveniently generate static libraries (`.a`) and dynamic libraries (`.so`) (by default, static libraries are generated. If you need components to generate dynamic libraries, you can use `register_component(DYNAMIC)` to register the module)\n* Using the `Python` script as an aid, you can easily add commands and tools, and you only need to execute simple commands to compile (such as `python project.py build` `python project.py menuconfig`)\n* Conveniently used as `SDK`, the project example can be placed directly in the `SDK` directory, or it can be placed anywhere on the disk separately, just set the environment variable `MY_SDK_PATH`\n* Cross-compilation friendly, well as an embedded device `SDK`\n* Generate a variety of `IDE` supported projects, then you can directly import to IDE as a project\n* Support compile to `WASM`(Web Assembly)\n\n## Get Started\n\n* Clone code by:\n```\ngit clone https://github.com/Neutree/c_cpp_project_framework --recursive\n```\n\u003e Arg `--recursive` is needed to clone all submodule, or code is not complete\n\n* Or create your github repository based on this template:\u003c/br\u003eYou can create your github repository with this tempalte by click `use this template` button\u003c/br\u003e![](assets/image/use_template.png)\n\n* Start compile\u003c/br\u003ethere's two way, use `project.py` script or use original CMake command\n  * With project.py(recommend)\n    ```\n    cd examples/demo1\n    # python project.py --toolchain /opt/toolchain/bin --toolchain-prefix mips-elf- config\n    python project.py menuconfig\n    python project.py build\n    # python project.py rebuild    # when you add/remove source files, should use this command instead of build\n    # you can use --verbose arg to see more compile info, this is useful when error occurs\n    # python project.py build --verbose\n    python project.py run        # or ./build/demo1\n    python project.py clean\n    python project.py distclean\n    # python project.py clean_conf\n    ```\n    * Change dir to project directory\n    * Set toolchain path(don't need set if use `gcc`)\n    * Config project by command `python project.py menuconfig`, it will generate `global_config` files at `build/config` directory, so we can use it in component's `CMakelists.txt` directly， or in `C/CPP` source files by `#include \"global_config.h\"`\n    * Build project by command `python project.py build`, or output verbose build info with command `python project.py build --verbose`\n    * Clean build by `python project.py clean`, clean config generated by `menuconfig` by `python project.py distclean`, this command will not clean toolchain config\n    * Clean toolchain config by `python project.py clean_conf`\n  * With original CMake command\n    ```\n    cd examples/demo1\n    # python project.py --toolchain /opt/toolchain/bin --toolchain-prefix mips-elf- config\n    mkdir build \u0026\u0026 cd build\n    cmake ..\n    make menuconfig\n    make -j10\n    ./build/demo1\n    make clean\n    rm -rf ./*\n    ```\n    * Change dir to project directory\n    * Set toolchain path(don't need set if use `gcc`)\n    * Make a temporary directory and switch the current path to this directory(`build`)\n    * Generate makefile by command `cmake ..`, `..` means the project directory\n    * Config project by command `make menuconfig`, it will generate `global_config` files at `build/config` directory, so we can use it in component's `CMakelists.txt` directly， or in `C/CPP` source files by `#include \"global_config.h\"`\n    * Build project by command `make`, or parallel build with [make -jN](http://www.gnu.org/software/make/manual/make.html#Parallel)， and output verbose build info with command `make VERBOSE=1`\n\n\n\n## Structure\n\n| directory/file | function |\n| -------------- | -------- |\n| root directory | root directory of this project, also `SDK` projects' `SDK` directory |\n| assets         | store assets like image etc. you can delete it if not use it |\n| components     | as a component/lib |\n| examples       | project dir or demo dir； `SDK` projects' example/project dir, this directory can be separated from the `SDK` directory, just set environment`MY_SDK_PATH` to `SDK` directory's path. |\n| tools          | tools like `cmake`、`kconfig`、`burn tool` etc. |\n| Kconfig        | root `Kconfig` configuration |\n\n\n### 1) Component\n\nAll libraries are placed as components in the `components` directory or under the project directory. Each component uses a directory. This directory is the name of the component. In order to make the project look more concise, the components are not nested. All components are a hierarchy, and the relationships between components depend on dependencies to maintain\n\nAll source files must be in a component. Each project must contain a component called `main` (ie `examples/demo1/main` directory). Each component contains the following files:\n\n* `CMakeLists.txt`: Must exist, declare the component source file and the dependent component, and call the registration function to register itself. For details, please refer to `CMakeLists.txt` of `components/component1` and `components/component2`.\n\n* `Kconfig`: Optional, contains configuration options for this component. In this component or other `CMakeLists.txt` that depends on the component of this component, you can use these configuration items after adding a `CONFIG_` prefix. e.g. In `components/component2`, there is a `COMPONENT2_ENABLED` option in `Kconfig`. We use this variable `if(CONFIG_COMPONENT2_ENABLED)` in its `CMakeLists.txt` to determine if the user configuration want to register this component or not.\n\n### 2) Project Directory\n\nThe project directory is in the `examples` directory. Of course, the name of this directory can be modified according to actual needs. The following can contain multiple actual project directories. You can compile when you need to compile the project and switch to the corresponding directory. As mentioned above, there must be a `main` component in each project directory. Of course, you can also put a lot of custom components. More refer to the `examples/demo1` project directory.\n\nFiles under the project directory:\n\n* `CMakeLists.txt`: must exist, project properties file, you must first include `include(${SDK_PATH}/tools/cmake/compile.cmake)`, then use the `project` function to declare project name, such as `project(demo1)`, Of course, you can also write other conditions or variables, etc., using the `CMake` syntax, refer to the `examples/demo1/CMakeLists.txt`\n\n* `config_defaults.mk`: Optional, project default configuration file, the default configuration will be loaded when `cmake` execute. The format of the configuration is `Makefile`. You can use the terminal GUI configuration (`make menuconfig`) to generate the configuration file, the generated configuration file is in `build/config/global_config.mk`, then copy to `config_defaults.mk`.\n\u003e Note: After modifying `config_defaults.mk`, you need to delete the files in the `build` directory (or just delete the `mk` file in the `build/config` directory) to regenerate, because the current build system will use the existing configuration file (`build/config/global_config.mk`)\n\n* `project.py`: tool script call entry, use `python project.py menuconfig` `python project.py build` and other commands to start building\n\nHow to put the project directory anywhere on the disk:\n\n* Change the `MY_SDK_PATH` in `CMakeLists.txt` and `project.py` to the name of the environment variable you like, and then set the value of this environment variable in the terminal to the path of the `SDK`, you can change the project directory It can be compiled anywhere\n\n\n## Store SDK and project directory separately\n\nNormally, you only need to modify the name of the `example` directory according to your needs, such as changing it to `projects`, or creating a new directory in the project root directory, such as `projects/hello_world`, and copy files in the `examples/demo1`'s content to start a project\n\nIn addition, the project directory and the SDK directory can also be stored separately. This is especially used for open source projects, a copy of SDK, users develop based on this SDK, which is more conducive to the spread of routines, users do not need to copy a copy of the SDK, just specify the use SDK version (git commit number)\nTo do this, only need:\n\n* Download `SDK` and put it in a directory, such as `/home/neucrack/my_SDK`\n\n```\ngit clone https://github.com/Neutree/c_cpp_project_framework --recursive\n```\nNote that the `--recursive` parameter is used here, because sub-modules are used in the project. The advantage of sub-modules is that each project is managed separately. For example, `Kconfiglib` is used as a sub-module to provide `menuconfig` with interface function configuration\n\n**If you did't update submodule, the compile will error!!!!**\n\nIf you forget to add this parameter when cloning, you can also use the following command to update the submodule:\n```\ngit submodule update --init --recursive\n```\nIn addition, when the remote repository is updated, the user also needs to use the following command to update the code (ie update the submodule code at the same time):\n```shell\ngit pull --recursive\n```\nor:\n```\ngit pull\ngit submodule update --init --recursive\n```\n\nOf course, you can also just delete the `.git` directory, and start a git repository with no submodule~~~\n\n\n* Then export the variable `export MY_SDK_PATH=/home/neucrack/my_SDK` in the terminal, which can be placed in the `~/.bashrc` or `~/.zshrc` file, so that this variable will be automatically added every time the terminal is started\n* Then create a project anywhere, such as copy the entire content of the folder of `example/demo1` to `/home/neucrack/temp/my_projects/demo1`\n* Then clear the previous build cache (if there is one, ignore it if there is none)\n```\npython3 project.py distclean\n```\n* Then configure and build\n```\npython3 project.py menuconfig\npython3 project.py build\n```\n\n## Custom components path\n\nGenerally, the common components are placed in the `SDK directory -\u003e components directory`, and the project-specific components are placed in the `project directory`.\nIn addition, users can also customize the storage location of their common components by setting the system environment variable `CUSTOM_COMPONENTS_PATH`, for example:\nLinux:\n```\nexport CUSTOM_COMPONENTS_PATH=/home/neucrack/my_components\n```\nWindows just add `CUSTOM_COMPONENTS_PATH` variable in the environment variable interface.\n\u003e The name `CUSTOM_COMPONENTS_PATH` can be modified according to your project name or preference in the `project.py` and `CMakeLists.txt` of the project.\n\nThen you can directly use `list(APPEND ADD_REQUIREMENTS component_name)` to reference it in the project component.\n\n## Debug and Release version\n\nBy default, it is compiled in debug version. If you want to release version, you can use the following command:\n```shell\npython project.py distclean\npython project.py build --release\n```\n\nThen the binary file built is the release version, and the compilation script does a few actions:\n* Set the CMake environment variable `CMAKE_BUILD_TYPE` to `MinSizeRel` (default is `Debug`)\n* Add `#define RELEASE 1` to the generated header file `global_config.h` (default will add `#define DEBUG 1`)\n* Automatically add the macro definition `RELEASE=1` when compiling, so the code actually does not need to import `global_config.h` can also through `RELEASE` and `DEBUG` macro definition to determine whether the current is release version or debug version\n\n## Change project generator\n\nSometimes you want to faster build speed or generate project for some IDE like Visual Studio,\nyou can change generator to achieve this, default generator is `Unix Makefiles`.\n\nThere are many generator choices, such as `Ninja`, `Visual Studio`, `Xcode`, `Eclipse`, `Unix Makefiles` etc.\nExecute command `cmake --help` to see the generator choices, different system support different generators.\nLinux for example:\n```\nGenerators\n\nThe following generators are available on this platform (* marks default):\n  Green Hills MULTI            = Generates Green Hills MULTI files\n                                 (experimental, work-in-progress).\n* Unix Makefiles               = Generates standard UNIX makefiles.\n  Ninja                        = Generates build.ninja files.\n  Ninja Multi-Config           = Generates build-\u003cConfig\u003e.ninja files.\n  Watcom WMake                 = Generates Watcom WMake makefiles.\n  CodeBlocks - Ninja           = Generates CodeBlocks project files.\n  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.\n  CodeLite - Ninja             = Generates CodeLite project files.\n  CodeLite - Unix Makefiles    = Generates CodeLite project files.\n  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.\n  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.\n  Kate - Ninja                 = Generates Kate project files.\n  Kate - Unix Makefiles        = Generates Kate project files.\n  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.\n  Sublime Text 2 - Unix Makefiles\n                               = Generates Sublime Text 2 project files.\n```\n\nYou can change it by `config` command\n```\n# clean all build files first(remove build dir)\npython project.py distclean\n\npython project.py -G Ninja config\n# python project.py -G \"Eclipse CDT4 - Ninja\" config\n\npython project.py build\n```\n\n## Compile to WASM\n\nInstall toolchain first according to [emscripten-core/emsdk](https://github.com/emscripten-core/emsdk)\n```\ngit clone https://github.com/emscripten-core/emsdk.git\n./emsdk install latest\n./emsdk activate latest\n```\n\nJust only set toolchain\n```\npython project.py distclean\npython project.py --toolchain $EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake config\npython project.py build\n```\n\nThen you will find `demo1.html`, `demo1.js` and `demo1.wasm` files in `build` directory, run command below you will see result in browser:\n```\nemrun demo1.html\n```\n\nOr just run by `node`\n```\nnode demo1.js\n```\n\n## Add command\n\nBy default we can use `python project.py run` to call [tools/cmds/run.py](./tools/run.py) file, and execute the binary file.\nIf you want to add commands for your SDK, just create new `py` file in tools directory, write a script and content refer to [tools/cmds/run.py](./tools/cmds/run.py).\n\n## Online Debugging\n\n### VSCode + GDB Online Debugging\n\nHere take PC with Linux system as an example:\n\n* Add `c_cpp_project_framework` (recommended for the first trial) or project directory to VSCode workspace\n* Copy the [./assets/vscode_local_debug/.vscode](./assets/vscode_local_debug/.vscode) directory to the working directory of the previous step\n* Edit the `cwd` field in `.vscode/launch.json` according to whether `.vscode` is under `c_cpp_project_framework` or under the project directory\n* Press F5 on the keyboard to start debugging\n\u003e Windows is similar, just modify the relevant commands and paths in `.vscode`\n\n### VSCode + gdbserver Debugging on Embedded Device (/Remote Device with Linux System)\n\nHere take PC with Linux system as an example:\n\n* Firstly, Ensure that the remote device has the `gdbserver` program, and the PC has the `gdb-multiarch` program\n* Copy the [./assets/vscode_remote_debug/.vscode](./assets/vscode_remote_debug/.vscode) directory to the project directory\n* Edit the `launch.json` and `build_run_gdbserver.sh` files, modify the paths and commands inside, as well as the username, etc.\n\u003e It is recommended to add the PC's ssh key to the `~/.ssh/authorized_keys` file of the remote device first, so you don't need to enter a password.\n* The `build_run_gdbserver.sh` script needs to be executed every time you debug, and then press F5 in VSCode to start debugging\n\u003e The script will compile the project, then copy the executable file to the remote device, and start `gdbserver`.\n\u003e Press F5 to start debugging, VSCode uses GDB to connect to `gdbserver` on the remote device for debugging.\n\n\n## License\n\n**MIT**， see [LICENSE](./LICENSE)\n\n\n## Open source projects used by this project\n\n* [Kconfiglib](https://github.com/ulfalizer/Kconfiglib)： `Kconfig`'s `Python` implementation\n\n## Repos used this framwork\n\n* [Maix-Speech](https://github.com/sipeed/Maix-Speech): AI speech recognization lib for embedded devices\n* [MaixPy](https://github.com/sipeed/MaixPy/): `Micropython` port for `AIOT` chip `K210`\n* [libmaix](https://github.com/sipeed/libmaix): A lib for embeded AI model running with hardware accelaration\n* [MF1_SDK](https://github.com/sipeed/MF1_SDK): SDK for `MF1` AI module(board)\n\n## Other Similar Reference\n\n* [ESP_IDF](https://github.com/espressif/esp-idf)：  `SDK` of `ESP32`, Written very well\n* [RT-Thread](https://github.com/RT-Thread/rt-thread)：not `CMake`, but also use component\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneutree%2Fc_cpp_project_framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneutree%2Fc_cpp_project_framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneutree%2Fc_cpp_project_framework/lists"}