Hi all! I glad to show my template of project Hello world that uses CMake build system, it's named as
My last sample was use GNU Autotools, it's a difficult system. Today we have many projects with CMake (cmake.org). For new projects I recommend use CMake. But it will have problems with cross-compilation for beginners. Let's find it out!
Step 1. Creating you own CMake project
First you have to install
cmake applications in the host if there are none.
Next follow into you projects directory in the host, e.g.
$HOME/projects and clone there my CMake template
myapptemplate project. Then enter new project directory and remove
.git dir from there.
git clone --single-branch --branch CMake https://bitbucket.org/hlorka/myapptemplate.git <my_app_name>
rm -rf ./.git
myapptemplate.vcxproj for MS Visual Studio IDE and can be deleted too.
Step 2A. General compilation for the host machine
It's very simple. First you have to configure and make cache CMake's files. Look at the command below:
cmake . [--config Debug]
--config Debug will append debug information (symbols) and postfix
-d to the output binary file (
Then you can build (compile) project, using next commands below
Step 2B. Cross-compilation using OpenWRT SDK
First open file
cross-compile/openwrt-mips-toolchain.cmake for modify.
Fragment of this file below:
# Локальные переменные
# Экспортируемая переменная, в скрипт `xcmake.sh`
You have to check/modify OpenWRT SDK paths.
cmake with parameters:
cmake -DCMAKE_TOOLCHAIN_FILE=./cross-compile/openwrt-mips-toolchain.cmake [--config Debug] [-DREMOTE_INSTALL_IP=<remote-IP> -DREMOTE_INSTALL_USER=root]
REMOTE_INSTALL_* will make targets to help you copy binary files to the Omega via
rsync. You also need SSH access by key.
To build (cross-compile) project you have to run script:
./xcmake.sh --build . [--clean-first]
Step 3 (optional). Remote-installation
If you set
REMOTE_INSTALL_* parameters, after build you able using
remote-uninstall targets for example below:
cmake --build . --target remote-install
Step 4 (optional). Making IPK-package
After cross-compilation you will see files
openwrt-manifest-local.mk in the root project directory. There are two variants of manifest (renamed Makefile).
openwrt-manifest-git.mk - variant of manifest file of project to make package that sources will be download from Git repository.
openwrt-manifest-local.mk - variant of manifest file of project to make package localy. It's useful for debugging or internal using.
To make package, first you have to create feed directory outside this project, e.g.
$HOME/my-openwrt-packages. Create sub-directory in it with you project name, e.g.
Then make symlink there for one of the Manifest file, e.g.:
ln -sf $HOME/projects/<my_app_name>/openwrt-manifest-local.mk $HOME/my-openwrt-packages/<my_app_name>/Makefile
Next change working dir to the root of OpenWRT SDK. Open file
feeds.conf.default in any text editor and append your own feed there like below string.
src-link my_packages /home/<my_user_name>/projects/my-openwrt-packages
Then run once sequence of commands:
./scripts/feeds update my_packages
./scripts/feeds install <my_app_name>
Now you can build IPK-package:
Your IPK-files you can find in the directory
<OpenWRT_SDK_dir>/bin/packages/mipsel_24kc/my_packages. It will named like
To install package from IPK-file in the Omega, run next command:
opkg install ./<my_app_name>_1.0-1_mipsel_24kc.ipk