Porting source code mechanics

Build system adaptations

Some build systems, like CMake, support conditional statements, and the project build configuration files may define platform-specific sections.

That's why defining a variable named QNX in the toolchain file, allows you to properly manage the QNX platform when special handling is needed.

For example, in the following CMakeLists.txt snippet:

if(QNX)
    target_link_libraries(${TEST_EXECUTABLE} socket)
    if($ENV{QNX_SDP7})
        target_link_libraries(${TEST_EXECUTABLE} c++fs)
    endif()
endif()

We specify linking the socket library to the TEST_EXECUTABLE when building for QNX (regardless of the SDP version).

Additionally, we want to link the c++fs library, but only if the QNX_SDP7 environment variable is defined.

Filesystem support in the C++ library (introduced in C++17) was an experimental feature in SDP 7.1 and was deployed in a separate library, which had to be explicitly linked.

QNX_SDP7=1 cmake .. -DCMAKE_TOOLCHAIN_FILE=../qnx.nto.toolchain.cmake

Source code adaptations

When porting platform-specific code, you may encounter preprocessor conditional compilation directives, for example:

#if defined(\_\_unix\_\_)
    // unix specific code
#endif

Some of the preprocessor symbols are defined in the project, some may be set by the user, and some depend on the environment. For example, qcc defines the __QNX__ and __unix__ symbols. To see all symbols, add the -vv option to the qcc invocation.

When QNX OS-specific code needs to be added, you can handle it using the __QNX__ preprocessor symbol. For more information on this symbol, visit the "Including QNX OS-specific code" page in the Programmer's Guide.

Page updated: