Kuigi asjade.net nüüd sisaldab juba näiteid cmake kasutamisest erinevatel platvormidel, siiski tahaks teha minimaalselt koodi sisaldava näite ning seejärel proovida kasutada Boost C++ libraries võimalusi.

Teen uue kausta C:\git-gtest\boostdemo ja lisan siia faili CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)

set(PROJECT_NAME_STR boostdemo)
project(${PROJECT_NAME_STR} C CXX)
MESSAGE("PROJECT_SOURCE_DIR:${PROJECT_SOURCE_DIR}")
MESSAGE("PROJECT_BINARY_DIR:${PROJECT_BINARY_DIR}")

include_directories(include)
file(GLOB SOURCES src/*.cpp include/*.h)

add_executable(${PROJECT_NAME_STR} ${SOURCES})


set_property(TARGET ${PROJECT_NAME_STR} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${PROJECT_NAME_STR} PROPERTY CXX_STANDARD 14)

Kausta C:\git-gtest\boostdemo\src panen faili main.cpp:

#include <iostream>
#include "main.h"
using namespace std;

int main(int argc, char *argv[]) {
	cout << "Hello, world !!!" << " \n";
}

Kausta C:\git-gtest\boostdemo\include panen lihtsalt tühja faili main.h.

Loon kausta C:\git-gtest\boostdemo\build ja avan seal käsurea ning käivitan cmake ..

Nüüd avan Visual Studios faili C:\git-gtest\boostdemo\build\boostdemo.sln, määran startup projektiks boostdemo ja käivitan lihtsa demo programmi.

Sama asi MinGW-ga:

mkdir mingw-build
cd mingw-build
cmake .. -G "MinGW Makefiles" mingw32-make ls ./boostdemo.exe

Nüüd sama asi Linuxis:

cd ~/git-gtest/boostdemo
mkdir linux-build
cd linux-build
cmake .. make ls ./boostdemo

Nüüd sama asi Androidiga. Loon kausta C:\git-gtest\boostdemo\jni ja panen siia failid Android.mk, Application.mk ja build.cmd.

Nende sisu:

Android.mk

TARGET_ARCH_ABI := armeabi-v7a
LOCAL_PATH := $(call my-dir)
$(info asukoht: $(LOCAL_PATH))

#siin on meie exe
include $(CLEAR_VARS)
LOCAL_MODULE := boostdemo
FILE_LIST := $(wildcard $(LOCAL_PATH)/../../src/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../include 
LOCAL_STATIC_LIBRARIES := boostdemo
include $(BUILD_EXECUTABLE)

Application.mk 

APP_STL := gnustl_shared
APP_PLATFORM := android-16
NDK_TOOLCHAIN_VERSION := 4.9
APP_CPPFLAGS += -std=c++14 -frtti -fexceptions

build.cmd

call "C:\Users\tiit\AppData\Local\Android\sdk\ndk-bundle\ndk-build.cmd"
if %errorlevel% neq 0 exit /b %errorlevel%

adb -d push ../libs/armeabi/libgnustl_shared.so /data/local/tmp/
adb -d push ../libs/armeabi/boostdemo /data/local/tmp/
adb -d shell chmod 775 /data/local/tmp/boostdemo
adb -d shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/boostdemo"

Avan käsurea ja käivitan build.cmd (PATH muutujas peab olema PATH=C:\Users\tiit\AppData\Local\Android\sdk\platform-tools):