CMake & Arm Cross compilation based Windows systems

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

boost::program_options demo

A Simple Demo

  1. //
  2. // Created by Water on 2018/6/9.
  3. //
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <boost/program_options.hpp>
  8. namespace  bpo = boost::program_options;
  9.  
  10. int main(int argc, char const *argv[])
  11. {
  12.     bpo::options_description opts("all options");
  13.     bpo::variables_map vm;
  14.  
  15.     opts.add_options()
  16.             ("filename", bpo::value<std::string>(), "the file name which want to be found")
  17.             ("help", "this is a program to find a specified file");
  18.  
  19.     try{
  20.         bpo::store(bpo::parse_command_line(argc, argv, opts), vm);
  21.     }
  22.     catch(...){
  23.         std::cout << "undefined option!\n";
  24.         return 0;
  25.     }
  26.  
  27.     if(vm.count("help") ){
  28.         std::cout << opts << std::endl;
  29.     }
  30.     if(vm.count("filename") ){
  31.         std::cout << "find " << vm["filename"].as<std::string>() << std::endl;
  32.     }
  33.     if(vm.empty() ){
  34.         std::cout << "no options found \n";
  35.     }
  36.     return 0;
  37. }

Test

How to Set Default Value

  1. //
  2. // Created by Water on 2018/6/9.
  3. //
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8. #include <boost/program_options.hpp>
  9. namespace bpo = boost::program_options;
  10.  
  11. int main(int argc, char const *argv[])
  12. {
  13.     std::vector<std::string> v_para;
  14.     std::string port;
  15.     int baud = 0;
  16.     int timeout = 0;
  17.     bpo::options_description opt("all options");
  18.  
  19.     opt.add_options()
  20.             ("v_para,v", bpo::value<std::vector<std::string> >()->multitoken(), "Serial v_para")
  21.             ("port,p", bpo::value<std::string>(&port)->default_value("COM1"), "Serial Port")
  22.             ("baud,b", bpo::value<int>(&baud)->default_value(115200), "Serial Baud")
  23.             ("timeout,t", bpo::value<int>(&timeout)->default_value(5000), "Timeout")
  24.             ("help", "a demo ( default value )");
  25.  
  26.     bpo::variables_map vm;
  27.  
  28.     try{
  29.         bpo::store(parse_command_line(argc, argv, opt), vm);
  30.     }
  31.     catch(...){
  32.         std::cout << "undefined option!\n";
  33.         return 0;
  34.     }
  35.  
  36.     bpo::notify(vm);
  37.  
  38.     if(vm.count("help") ){
  39.         std::cout << opt << std::endl;
  40.         return 0;
  41.     }
  42.     if(vm.count("v_para") ){
  43.         std::cout << "v_para:";
  44.         for(auto& str : vm["v_para"].as<std::vector<std::string> >() )
  45.             std::cout << str << " ";
  46.         std::cout << std::endl;
  47.     }
  48.     std::cout << "port:" << port << std::endl;
  49.     std::cout << "baud:" << baud << std::endl;
  50.     std::cout << "timeout:" << timeout << std::endl;
  51.     return 0;
  52. }

Test