CMake build system( framework) with kconfig support for C/CPP projects
MIT License
Simple and configurable C/C++
project/SDK template
CMake
build system and support Kconfig withGUI
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:
SDK
and need to write their own build systemCMake
, but want to learn CMake
IDE
supported projects.Makefile
or CMake
is required, and it is very simple to use only by modifying the value of the variable based on the templatelist(APPEND ADD_REQUIREMENTS component1)
), without setting extra variables such as INCLUDE path
to call the content of the dependent component in the source codeKconfig
to enable project components and code to be tailored and configured to facilitate the project to meet different needs.a
) and dynamic libraries (.so
) (such as list(APPEND ADD_STATIC_LIB "lib/libtest.a")
).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)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
)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
SDK
IDE
supported projects, then you can directly import to IDE as a projectWASM
(Web Assembly)git clone https://github.com/Neutree/c_cpp_project_framework --recursive
Arg
--recursive
is needed to clone all submodule, or code is not complete
Or create your github repository based on this template:You can create your github repository with this tempalte by click use this template
button
Start compilethere's two way, use project.py
script or use original CMake command
cd examples/demo1
# python project.py --toolchain /opt/toolchain/bin --toolchain-prefix mips-elf- config
python project.py menuconfig
python project.py build
# python project.py rebuild # when you add/remove source files, should use this command instead of build
# you can use --verbose arg to see more compile info, this is useful when error occurs
# python project.py build --verbose
python project.py run # or ./build/demo1
python project.py clean
python project.py distclean
# python project.py clean_conf
gcc
)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"
python project.py build
, or output verbose build info with command python project.py build --verbose
python project.py clean
, clean config generated by menuconfig
by python project.py distclean
, this command will not clean toolchain configpython project.py clean_conf
cd examples/demo1
# python project.py --toolchain /opt/toolchain/bin --toolchain-prefix mips-elf- config
mkdir build && cd build
cmake ..
make menuconfig
make -j10
./build/demo1
make clean
rm -rf ./*
gcc
)build
)cmake ..
, ..
means the project directorymake 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"
make
, or parallel build with make -jN, and output verbose build info with command make VERBOSE=1
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 cmake 、kconfig 、burn tool etc. |
Kconfig | root Kconfig configuration |
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:
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
.
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.
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:
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
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
.
Note: After modifying
config_defaults.mk
, you need to delete the files in thebuild
directory (or just delete themk
file in thebuild/config
directory) to regenerate, because the current build system will use the existing configuration file (build/config/global_config.mk
)
project.py
: tool script call entry, use python project.py menuconfig
python project.py build
and other commands to start buildingHow to put the project directory anywhere on the disk:
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 anywhereNormally, 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:
SDK
and put it in a directory, such as /home/neucrack/my_SDK
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~~~
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 startedexample/demo1
to /home/neucrack/temp/my_projects/demo1
python3 project.py distclean
python3 project.py menuconfig
python3 project.py build
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 theproject.py
andCMakeLists.txt
of the project.
Then you can directly use list(APPEND ADD_REQUIREMENTS component_name)
to reference it in the project component.
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:
CMAKE_BUILD_TYPE
to MinSizeRel
(default is Debug
)#define RELEASE 1
to the generated header file global_config.h
(default will add #define DEBUG 1
)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 versionSometimes 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
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
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.
Here take PC with Linux system as an example:
c_cpp_project_framework
(recommended for the first trial) or project directory to VSCode workspacecwd
field in .vscode/launch.json
according to whether .vscode
is under c_cpp_project_framework
or under the project directoryWindows is similar, just modify the relevant commands and paths in
.vscode
Here take PC with Linux system as an example:
gdbserver
program, and the PC has the gdb-multiarch
programlaunch.json
and build_run_gdbserver.sh
files, modify the paths and commands inside, as well as the username, etc.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.
build_run_gdbserver.sh
script needs to be executed every time you debug, and then press F5 in VSCode to start debuggingThe script will compile the project, then copy the executable file to the remote device, and start
gdbserver
. Press F5 to start debugging, VSCode uses GDB to connect togdbserver
on the remote device for debugging.
MIT, see LICENSE
Kconfig
's Python
implementationMicropython
port for AIOT
chip K210
MF1
AI module(board)