Neutree / c_cpp_project_framework

CMake build system( framework) with kconfig support for C/CPP projects
https://neucrack.com/p/276
MIT License
159 stars 38 forks source link
build c cmake compile cpp framework gui-configuration kconfig kconfig-support make project template wasm

C CPP Project Framework (Template)

中文

Simple and configurable C/C++ project/SDK template

CMake build system and support Kconfig with GUI configuration

Based on this project, you can quickly build your project construction system and reduce many unnecessary troubles~

If it helps you, please give a little star in the upper right corner~~ If needs improvement, just create an issue. (´ε` ʃƪ)♡

The target developer of this project:

Features

Get Started

Structure

directory/file function
root directory root directory of this project, also SDK projects' SDK directory
assets store assets like image etc. you can delete it if not use it
components as a component/lib
examples project dir or demo dir; SDK projects' example/project dir, this directory can be separated from the SDK directory, just set environmentMY_SDK_PATH to SDK directory's path.
tools tools like cmakekconfigburn tool etc.
Kconfig root Kconfig configuration

1) Component

All 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

All 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:

2) Project Directory

The 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.

Files under the project directory:

How to put the project directory anywhere on the disk:

Store SDK and project directory separately

Normally, 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

In 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) To do this, only need:

git clone https://github.com/Neutree/c_cpp_project_framework --recursive

Note 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

If you did't update submodule, the compile will error!!!!

If you forget to add this parameter when cloning, you can also use the following command to update the submodule:

git submodule update --init --recursive

In 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):

git pull --recursive

or:

git pull
git submodule update --init --recursive

Of course, you can also just delete the .git directory, and start a git repository with no submodule~~~

Custom components path

Generally, the common components are placed in the SDK directory -> components directory, and the project-specific components are placed in the project directory. In addition, users can also customize the storage location of their common components by setting the system environment variable CUSTOM_COMPONENTS_PATH, for example: Linux:

export CUSTOM_COMPONENTS_PATH=/home/neucrack/my_components

Windows just add CUSTOM_COMPONENTS_PATH variable in the environment variable interface.

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.

Then you can directly use list(APPEND ADD_REQUIREMENTS component_name) to reference it in the project component.

Debug and Release version

By default, it is compiled in debug version. If you want to release version, you can use the following command:

python project.py distclean
python project.py build --release

Then the binary file built is the release version, and the compilation script does a few actions:

Change project generator

Sometimes you want to faster build speed or generate project for some IDE like Visual Studio, you can change generator to achieve this, default generator is Unix Makefiles.

There are many generator choices, such as Ninja, Visual Studio, Xcode, Eclipse, Unix Makefiles etc. Execute command cmake --help to see the generator choices, different system support different generators. Linux for example:

Generators

The following generators are available on this platform (* marks default):
  Green Hills MULTI            = Generates Green Hills MULTI files
                                 (experimental, work-in-progress).
* Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.

You can change it by config command

# clean all build files first(remove build dir)
python project.py distclean

python project.py -G Ninja config
# python project.py -G "Eclipse CDT4 - Ninja" config

python project.py build

Compile to WASM

Install toolchain first according to emscripten-core/emsdk

git clone https://github.com/emscripten-core/emsdk.git
./emsdk install latest
./emsdk activate latest

Just only set toolchain

python project.py distclean
python project.py --toolchain $EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake config
python project.py build

Then you will find demo1.html, demo1.js and demo1.wasm files in build directory, run command below you will see result in browser:

emrun demo1.html

Or just run by node

node demo1.js

Add command

By default we can use python project.py run to call tools/cmds/run.py file, and execute the binary file. If 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.

Online Debugging

VSCode + GDB Online Debugging

Here take PC with Linux system as an example:

VSCode + gdbserver Debugging on Embedded Device (/Remote Device with Linux System)

Here take PC with Linux system as an example:

License

MIT, see LICENSE

Open source projects used by this project

Repos used this framwork

Other Similar Reference