Some built-in macros inside CMakeSettings.json:

  • ${workspaceRoot} – provides the full path to the workspace folder
  • ${workspaceHash} – hash of workspace location; useful for creating a unique identifier for the current workspace (e.g. to use in folder paths)
  • ${projectFile} – the full path for the root CMakeLists.txt
  • ${projectDir} – the full path to the folder of the root CMakeLists.txt file
  • ${thisFile} – the full path to the CMakeSettings.json file
  • ${name} – the name of the configuration
  • ${generator} – the name of the CMake generator used in this configuration

CMake & Arm Cross compilation based Windows systems (Visual Studio)

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.12)
  2. project(network_information)
  3.  
  4. SET(CMAKE_SYSTEM_NAME Linux)
  5.  
  6. add_definitions("-std=c++17")
  7.  
  8. # specify the cross compiler
  9. SET(CMAKE_C_COMPILER   arm-linux-gnueabihf-gcc)
  10. SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  11.  
  12. if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
  13.     set(BOOST_ROOT "C:/MinGW/msys/1.0/home/d/boost_1_68_0")
  14. else()
  15.     set(BOOST_ROOT /root/Downloads/boost_1_68_0)
  16. endif()
  17.  
  18. set(Boost_USE_STATIC_LIBS ON)
  19. set(Boost_USE_MULTITHREADED ON)
  20.  
  21. include_directories(sdk/inc)
  22. link_directories("sdk/lib")
  23.  
  24. add_executable(network_information
  25. 		network_information.cpp
  26. 		)
  27. TARGET_LINK_LIBRARIES(network_information "-lpthread" "-ldl" "-lpos" "-lrt" "-lpng" "-liconv" "-lfreetype" "-lz")

GNUlinux_config.cmake

  1. set(GNULINUX_PLATFORM ON)
  2. set(CMAKE_SYSTEM_NAME "Linux")
  3. set(CMAKE_SYSTEM_PROCESSOR "arm")
  4.  
  5. if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
  6.    set(NE10_LINUX_TARGET_ARCH "armv7")
  7. else()
  8.    set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
  9. endif()
  10.  
  11. if(NE10_LINUX_TARGET_ARCH STREQUAL "armv7")
  12.    set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
  13.    set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  14.    set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
  15.    find_program(CMAKE_AR NAMES "arm-linux-gnueabihf-ar")
  16.    find_program(CMAKE_RANLIB NAMES "arm-linux-gnueabihf-ranlib")
  17. elseif(NE10_LINUX_TARGET_ARCH STREQUAL "aarch64")
  18.    set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
  19.    set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
  20.    set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
  21.    find_program(CMAKE_AR NAMES "aarch64-linux-gnu-ar")
  22.    find_program(CMAKE_RANLIB NAMES "aarch64-linux-gnu-ranlib")
  23. endif()
  24.  
  25. mark_as_advanced(CMAKE_AR)
  26. mark_as_advanced(CMAKE_RANLIB)

CMakeSettings.json

  1. {
  2.   "configurations": [
  3.     {
  4.       "environments": [
  5.         {
  6.           "MINGW64_ROOT": "C:\\MinGW\\msys\\1.0\\home\\d\\gcc-linaro-7.3.1-2018.05-i686-mingw32_arm-linux-gnueabihf",
  7.           "BIN_ROOT": "${env.MINGW64_ROOT}\\bin",
  8.           "FLAVOR": "x86_64-w64-mingw32",
  9.           "TOOLSET_VERSION": "7.3.0",
  10.           "PATH": "${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\local\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.MINGW64_ROOT}\\..\\bin;${env.PATH}",
  11.           "INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR}",
  12.           "environment": "mingw_64"
  13.         }
  14.       ],
  15.       "name": "Mingw64-Release",
  16.       "generator": "Ninja",
  17.       "configurationType": "Release",
  18.       "inheritEnvironments": [
  19.         "mingw_64"
  20.       ],
  21.       "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
  22.       "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
  23.       "cmakeCommandArgs": "",
  24.       "buildCommandArgs": "-v",
  25.       "ctestCommandArgs": "",
  26.       "intelliSenseMode": "linux-gcc-x64",
  27.       "variables": [
  28.         {
  29.           "name": "CMAKE_TOOLCHAIN_FILE",
  30.           "value": "GNUlinux_config.cmake"
  31.         },
  32.         {
  33.           "name": "CMAKE_C_COMPILER",
  34.           "value": "${env.BIN_ROOT}\\arm-linux-gnueabihf-gcc.exe"
  35.         },
  36.         {
  37.           "name": "CMAKE_CXX_COMPILER",
  38.           "value": "${env.BIN_ROOT}\\arm-linux-gnueabihf-g++.exe"
  39.         }
  40.       ]
  41.     }
  42.   ]
  43. }

Cross compile with sftp-server to ARM

zlib

  1. tar xvf zlib-1.2.11.tar.xz
  2. cd zlib-1.2.11/
  3. ./configure --prefix=/root/Downloads/sftp-server/rootfs
  4.  
  5. [root@localhost zlib-1.2.11]# diff Makefile Makefile_bak 
  6. 19c19
  7. < CC=arm-linux-gnueabihf-gcc
  8. ---
  9. > CC=gcc
  10. 30,31c30,31
  11. < LDSHARED=arm-linux-gnueabihf-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
  12. < CPP=arm-linux-gnueabihf-gcc -E
  13. ---
  14. > LDSHARED=gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
  15. > CPP=gcc -E
  16. 39c39
  17. < AR=arm-linux-gnueabihf-ar
  18. ---
  19. > AR=ar
  20. 41c41
  21. < RANLIB=arm-linux-gnueabihf-ranlib
  22. ---
  23. > RANLIB=ranlib
  24.  
  25. make
  26. make install

openssh

  1. tar xzf openssh-6.9p1.tar.gz 
  2. cd openssh-6.9p1/
  3. ./configure --prefix= --host=arm-linux-gnueabihf --sysconfdir=/etc --with-zlib=/root/Downloads/sftp-server/rootfs
  4. make sftp-server
  5.  
  6. [root@localhost openssh-6.9p1]# file sftp-server
  7. sftp-server: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=3f3bb0178b0e2ff2e27553e4754bd58d78dffd4d, not stripped

CMake & Arm Cross compilation based Windows systems (CLion)

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.12)
  2. project(untitled1)
  3.  
  4. SET(CMAKE_SYSTEM_NAME Linux)
  5.  
  6. add_definitions("-std=c++17")
  7.  
  8. SET(CMAKE_C_COMPILER   arm-linux-gnueabihf-gcc)
  9. SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  10.  
  11. if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
  12.     set(BOOST_ROOT "C:/MinGW/msys/1.0/home/d/boost_1_68_0")
  13. else()
  14.     set(BOOST_ROOT /root/Downloads/boost_1_68_0)
  15. endif()
  16.  
  17. set(Boost_USE_STATIC_LIBS ON)
  18. set(Boost_USE_MULTITHREADED ON)
  19.  
  20. find_package(Boost COMPONENTS regex system date_time timer REQUIRED)
  21. if(Boost_FOUND)
  22.     include_directories(${Boost_INCLUDE_DIRS})
  23.     link_directories("${Boost_INCLUDE_DIRS}/stage/lib")
  24.     include_directories(sdk/inc)
  25.     link_directories("sdk/lib")
  26.     MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
  27.     MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
  28.     MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
  29.  
  30.     add_executable(untitled1 main.cpp)
  31.  
  32.     TARGET_LINK_LIBRARIES(untitled1 ${Boost_LIBRARIES} "-lpthread" "-lpos" "-lrt" "-lpng" "-liconv" "-lfreetype" "-lz" "-l:libboost_system.a")
  33. endif()

GNUlinux_config.cmake

  1. set(GNULINUX_PLATFORM ON)
  2. set(CMAKE_SYSTEM_NAME "Linux")
  3. set(CMAKE_SYSTEM_PROCESSOR "arm")
  4.  
  5. if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
  6.    set(NE10_LINUX_TARGET_ARCH "armv7")
  7. else()
  8.    set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
  9. endif()
  10.  
  11. if(NE10_LINUX_TARGET_ARCH STREQUAL "armv7")
  12.    set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
  13.    set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  14.    set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
  15.    find_program(CMAKE_AR NAMES "arm-linux-gnueabihf-ar")
  16.    find_program(CMAKE_RANLIB NAMES "arm-linux-gnueabihf-ranlib")
  17. elseif(NE10_LINUX_TARGET_ARCH STREQUAL "aarch64")
  18.    set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
  19.    set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
  20.    set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
  21.    find_program(CMAKE_AR NAMES "aarch64-linux-gnu-ar")
  22.    find_program(CMAKE_RANLIB NAMES "aarch64-linux-gnu-ranlib")
  23. endif()
  24.  
  25. mark_as_advanced(CMAKE_AR)
  26. mark_as_advanced(CMAKE_RANLIB)

The Most Important Thing on Windows

cmake -DCMAKE_TOOLCHAIN_FILE=GNUlinux_config.cmake ..

Apache Axis2/C Installation Guide (Windows)

First

http://archive.apache.org/dist/ws/axis2/c/1_6_0/axis2c-bin-1.6.0-win32.zip
ftp://ftp.zlatkovic.com/libxml/libxml2-2.7.8.win32.zip
ftp://ftp.zlatkovic.com/libxml/iconv-1.9.2.win32.zip
ftp://ftp.zlatkovic.com/libxml/zlib-1.2.5.win32.zip
http://archive.apache.org/dist/httpd/binaries/win32/httpd-2.2.25-win32-x86-openssl-0.9.8y.msi

Install Axis2/C

  1. Extract the binary distribution to a folder of your choice.(example: C:\axis2c-bin-1.6.0-win32)
  2. Copy the iconv.dll, libxml2.dll and zlib1.dll to C:\axis2c-bin-1.6.0-win32\lib
  3. Set the variable AXIS2C_HOME to the deploy folder (C:\axis2c-bin-1.6.0-win32)
  4. Add the path to lib directory to the PATH variable (%AXIS2C_HOME%\lib)

Install Apache 2.2

  1. Copy C:\axis2c-bin-1.6.0-win32\lib\mod_axis2.dll C:\Apache22\modules\mod_axis2.so
  2. Edit the Apache2’s configuration file (generally httpd.conf) and add the following directives
  3. LoadModule axis2_module modules/mod_axis2.so
    Axis2RepoPath C:/axis2c-bin-1.6.0-win32
    Axis2LogFile C:/axis2c-bin-1.6.0-win32/logs
    Axis2MaxLogFileSize 40
    Axis2LogLevel warn
  4. Restart apache2 and test whether mod_axis2 module is loaded by typing the URL http://localhost/axis2/services in your Web browser

Cross compile with Node.js C++ Addons to ARM

Set ENV

  1. export HOST=arm-linux-gnueabihf
  2. export CPP="${HOST}-gcc -E"
  3. export STRIP="${HOST}-strip"
  4. export OBJCOPY="${HOST}-objcopy"
  5. export AR="${HOST}-ar"
  6. export RANLIB="${HOST}-ranlib"
  7. export LD="${HOST}-ld"
  8. export OBJDUMP="${HOST}-objdump"
  9. export CC="${HOST}-gcc"
  10. export CXX="${HOST}-g++"
  11. export NM="${HOST}-nm"
  12. export AS="${HOST}-as"
  13. export LD="$CXX"
  14. export LINK="$CXX"
  15. export GYP_DEFINES="armv7=0"

Build

  1. node-gyp --arch arm configure build

Test

  1. root@imx6ul7d:~# node hello.js      
  2. world

TIP 0

  1. {
  2.   "targets": [
  3.     {
  4.       "target_name": "addon",
  5.       "sources": [ "test_api.cc" ],
  6. 	  "include_dirs" : ["sdk/inc"],
  7. 	  "link_settings": {"libraries": [ "-L/mnt/hgfs/tmp0511/sdk/lib"] },
  8. 	  "libraries": [ "-lpos", "-lpthread", "-lrt", "-lpng", "-liconv", "-lfreetype", "-lz" ],
  9.     }
  10.   ]
  11. }

TIP 1

  1. using v8::FunctionCallbackInfo;
  2. using v8::Isolate;
  3. using v8::Local;
  4. using v8::Object;
  5. using v8::String;
  6. using v8::Value;
  7. using v8::Number;
  8. using v8::Exception;
  9.  
  10. void js_Exchange(const FunctionCallbackInfo<Value>& args) {
  11.   Isolate* isolate = args.GetIsolate();
  12.  
  13.   int slot = args[0]->NumberValue();
  14.  
  15.   String::Utf8Value param1(args[1]->ToString());  
  16.   char *szApdu = *param1;  
  17.  
  18.   uint8_t apdu[300] = "\0";
  19.   MyAHex((uint8_t *)szApdu, apdu, strlen(szApdu));
  20.  
  21.   uint8_t rpdu[300] = "\0";
  22.   uint32_t rpdu_len = 0;
  23.   char szResult[300] = "\0";
  24.  
  25.   int ret = Exchange(slot, apdu, strlen(szApdu) / 2, rpdu, &rpdu_len);
  26.   if(0 == ret) {
  27.     MyHexA(rpdu, (uint8_t *)szResult, rpdu_len);
  28.     args.GetReturnValue().Set(String::NewFromUtf8(isolate, szResult));
  29.   } else {
  30.     args.GetReturnValue().Set(String::NewFromUtf8(isolate, ""));
  31.   }
  32. }

Node.js C++ Addons

Install node-gyp

  1. npm install -g node-gyp

Prepare SourceCode

  1. [root@localhost test_nodejs]# ls
  2. binding.gyp  hello.cc  hello.js

hello.cc

  1. #include <node.h>
  2.  
  3. namespace demo {
  4.  
  5. using v8::FunctionCallbackInfo;
  6. using v8::Isolate;
  7. using v8::Local;
  8. using v8::Object;
  9. using v8::String;
  10. using v8::Value;
  11.  
  12. void Method(const FunctionCallbackInfo<Value>& args) {
  13.   Isolate* isolate = args.GetIsolate();
  14.   args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
  15. }
  16.  
  17. void init(Local<Object> exports) {
  18.   NODE_SET_METHOD(exports, "hello", Method);
  19. }
  20.  
  21. NODE_MODULE(NODE_GYP_MODULE_NAME, init)
  22.  
  23. }  // namespace demo

hello.js

  1. // hello.js
  2. const addon = require('./build/Release/addon');
  3.  
  4. console.log(addon.hello());
  5. // Prints: 'world'

binding.gyp

  1. {
  2.   "targets": [
  3.     {
  4.       "target_name": "addon",
  5.       "sources": [ "hello.cc" ]
  6.     }
  7.   ]
  8. }

Compile & Test

  1. [root@localhost test_nodejs]# node-gyp configure
  2. gyp info it worked if it ends with ok
  3. gyp info using node-gyp@3.6.2
  4. gyp info using node@8.11.1 | linux | x64
  5. gyp info spawn /usr/bin/python2
  6. gyp info spawn args [ '/usr/local/node-v8.11.1-linux-x64/lib/node_modules/node-gyp/gyp/gyp_main.py',
  7. gyp info spawn args   'binding.gyp',
  8. gyp info spawn args   '-f',
  9. gyp info spawn args   'make',
  10. gyp info spawn args   '-I',
  11. gyp info spawn args   '/mnt/hgfs/linux_tmp/test_nodejs/build/config.gypi',
  12. gyp info spawn args   '-I',
  13. gyp info spawn args   '/usr/local/node-v8.11.1-linux-x64/lib/node_modules/node-gyp/addon.gypi',
  14. gyp info spawn args   '-I',
  15. gyp info spawn args   '/root/.node-gyp/8.11.1/include/node/common.gypi',
  16. gyp info spawn args   '-Dlibrary=shared_library',
  17. gyp info spawn args   '-Dvisibility=default',
  18. gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.11.1',
  19. gyp info spawn args   '-Dnode_gyp_dir=/usr/local/node-v8.11.1-linux-x64/lib/node_modules/node-gyp',
  20. gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.11.1/<(target_arch)/node.lib',
  21. gyp info spawn args   '-Dmodule_root_dir=/mnt/hgfs/linux_tmp/test_nodejs',
  22. gyp info spawn args   '-Dnode_engine=v8',
  23. gyp info spawn args   '--depth=.',
  24. gyp info spawn args   '--no-parallel',
  25. gyp info spawn args   '--generator-output',
  26. gyp info spawn args   'build',
  27. gyp info spawn args   '-Goutput_dir=.' ]
  28. gyp info ok 
  29. [root@localhost test_nodejs]# 
  30. [root@localhost test_nodejs]# ls
  31. binding.gyp  build  hello.cc  hello.js
  32. [root@localhost test_nodejs]# ls build/
  33. addon.target.mk  binding.Makefile  config.gypi  Makefile
  34.  
  35. [root@localhost test_nodejs]# node-gyp build
  36. gyp info it worked if it ends with ok
  37. gyp info using node-gyp@3.6.2
  38. gyp info using node@8.11.1 | linux | x64
  39. gyp info spawn make
  40. gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  41. make: Entering directory `/mnt/hgfs/linux_tmp/test_nodejs/build'
  42.   CXX(target) Release/obj.target/addon/hello.o
  43.   SOLINK_MODULE(target) Release/obj.target/addon.node
  44.   COPY Release/addon.node
  45. make: Leaving directory `/mnt/hgfs/linux_tmp/test_nodejs/build'
  46. gyp info ok 
  47.  
  48. [root@localhost test_nodejs]# ls build/
  49. addon.target.mk  binding.Makefile  config.gypi  Makefile  Release
  50. [root@localhost test_nodejs]# ls build/Release/
  51. addon.node  obj.target
  52.  
  53. [root@localhost test_nodejs]# node hello.js
  54. world

OpenCV3 On ARM

Source Code Dir

CMake-GUI Configure

Configure/Generate

Unix Makefiles
Specify options for cross-compiling

Choose ARM – LINUX

Operating System : arm-linux
C Compilers :
C++ Compilers :
Target Root : The Cross Compiler BIN Directory

CMAKE_INSTALL_PREFIX

make & make install

  1. make
  2. make install

Maybe Need It !


<>

The END

  1. tar jcvf opencv-arm.tar.bz2 opencv-arm/