Compiling the SDK for QNX with CMake

Short descriptions on how to use the SDK, the build environment and giving hints on some tricky issues.
Post Reply
User avatar
Support Team
Hero Member
Hero Member
Posts: 3213
Joined: 18 Mar 2011, 15:09

Compiling the SDK for QNX with CMake

Post by Support Team »

This HowTo will show you how to compile the SDK with CMake, but will not explain CMake in depth. For the interested reader we recommend to read the CMake Tutorial and the CMake Documentation to get a full understanding of CMake.

Important: This HowTo shows the possibility of building the source SDK (this will NOT work for all examples even in EVAL packages).


Requirements
  • Unified Automation SDK with qnx platform
  • CMake (> 2.8.0)
  • qnx (optional: qnx Momentics IDE)
  • CMake toolchain files for qnx
Example of a CMake toolchain file for QNX
  • example for a toolchain file used on windows (assumed you have installed qnx to its default path):

    Code: Select all

    # this one is important
    SET(CMAKE_SYSTEM_NAME QNX)
    #this one not so much
    SET(CMAKE_SYSTEM_VERSION 641)
    
    # specify the cross compiler
    SET(CMAKE_C_COMPILER   C:/QNX641/host/win32/x86/usr/bin/i386-pc-nto-qnx6.4.0-gcc-4.3.3.exe)
    SET(CMAKE_CXX_COMPILER C:/QNX641/host/win32/x86/usr/bin/i386-pc-nto-qnx6.4.0-g++-4.3.3.exe)
    
    SET(CMAKE_AR "C:/QNX641/host/win32/x86/usr/bin/ntox86-ar.exe" CACHE PATH "QNX ar Program" )
    
    # which library to find
    SET(XML_LIBRARY xml2)
    SET(SSL_LIBRARY ssl)
    
    # where to search the lib
    SET(LIBRARY_ARCH x86)
    
    # where is the target environment 
    SET(CMAKE_FIND_ROOT_PATH  C:/QNX641/target/qnx6)
    
    # search for programs in the build host directories
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    # for libraries and headers in the target directories
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    
  • example for a toolchain file used on linux (assumed you have installed qnx to its default path):

    Code: Select all

    # this one is important
    SET(CMAKE_SYSTEM_NAME QNX)
    #this one not so much
    SET(CMAKE_SYSTEM_VERSION 641)
    
    # specify the cross compiler
    SET(CMAKE_C_COMPILER   /opt/qnx641/host/linux/x86/usr/bin/i386-pc-nto-qnx6.4.0-gcc-4.3.3)
    SET(CMAKE_CXX_COMPILER /opt/qnx641/host/linux/x86/usr/bin/i386-pc-nto-qnx6.4.0-g++-4.3.3)
    
    SET(CMAKE_AR "/opt/qnx641/host/linux/x86/usr/bin/ntox86-ar" CACHE PATH "QNX ar Program" )
    
    # which library to find
    SET(XML_LIBRARY xml2)
    SET(SSL_LIBRARY ssl)
    
    # where to search the lib
    SET(LIBRARY_ARCH x86)
    
    # where is the target environment 
    SET(CMAKE_FIND_ROOT_PATH  /opt/qnx641/target/qnx6)
    
    # search for programs in the build host directories
    SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    # for libraries and headers in the target directories
    SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    
  • The toolchain file is located in folder "toolchains" in your sdk. Available toolchain files are:
    1. toolchain-qnx-arm.cmake
    2. toolchain-qnx-mips.cmake
    3. toolchain-qnx-powerpc.cmake
    4. toolchain-qnx-sh.cmake
    5. toolchain-qnx-x86.cmake
Creating and Compiling Makefiles for QNX
  • Create a build folder where to build the sources (e.g.: "path/to/sdk/bld").
  • You can create the Makefiles for compiling on the command line as follows:

    Code: Select all

    cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=../dist -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake ../src
  • If you want to create Makefiles for the qnx Momentics IDE, use the following CMake command:

    Code: Select all

    cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_INSTALL_PREFIX=../dist -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain.cmake ../src
  • Now compile and install the sources:

    Code: Select all

    make
    make install
    

Post Reply