diff --git a/CMakeLists-implied-options.txt b/CMakeLists-implied-options.txt index d5cfdd9f2..c75407f62 100644 --- a/CMakeLists-implied-options.txt +++ b/CMakeLists-implied-options.txt @@ -47,7 +47,7 @@ if (LWS_PLAT_OPTEE) set(LWS_WITH_UDP 0) endif() -if (LWS_PLAT_FREERTOS) +if (LWS_PLAT_FREERTOS OR (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) message(STATUS "No LWS_WITH_DIR or LWS_WITH_LEJP_CONF") set(LWS_WITH_DIR OFF) set(LWS_WITH_LEJP_CONF OFF) diff --git a/cmake/LwsCheckRequirements.cmake b/cmake/LwsCheckRequirements.cmake index fa3fb9fdd..9fc76e69c 100644 --- a/cmake/LwsCheckRequirements.cmake +++ b/cmake/LwsCheckRequirements.cmake @@ -75,7 +75,9 @@ MACRO(require_pthreads result) if (WIN32) set(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES}) else() - set(PTHREAD_LIB pthread) + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "QNX") + set(PTHREAD_LIB pthread) + endif() endif() endif() ENDMACRO() diff --git a/contrib/cross-aarch64-qnx.cmake b/contrib/cross-aarch64-qnx.cmake new file mode 100644 index 000000000..404d1d989 --- /dev/null +++ b/contrib/cross-aarch64-qnx.cmake @@ -0,0 +1,50 @@ +# +# CMake Toolchain file for crosscompiling aarch64 for QNX. +# +# This can be used when running cmake in the following way: +# cd build/ +# cmake .. -DCMAKE_TOOLCHAIN_FILE=../cross-aarch64-qnx.cmake +# + +# adapt to your toolchain path +set(CROSS_PATH /var/toolchain/qnx5.4/host/linux/x86_64/usr) + +# Target operating system name. +set(CMAKE_SYSTEM_NAME QNX) +set(BUILD_SHARED_LIBS OFF) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +# Name of C compiler. +set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/ntoaarch64-gcc") +set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/ntoaarch64-g++") + +set(CMAKE_C_FLAGS "-Wno-error") +set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") + +# +# Different build system distros set release optimization level to different +# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 +# here. Actually the build system's local policy is completely unrelated to +# our desire for cross-build release optimization policy for code built to run +# on a completely different target than the build system itself. +# +# Since this goes last on the compiler commandline we have to override it to a +# sane value for cross-build here. Notice some gcc versions enable broken +# optimizations with -O3. +# +if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") +endif() + +# Where to look for the target environment. (More paths can be added here) +set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") + +# Adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Search headers and libraries in the target environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff --git a/lib/misc/getifaddrs.c b/lib/misc/getifaddrs.c index 98e768c78..125088e22 100644 --- a/lib/misc/getifaddrs.c +++ b/lib/misc/getifaddrs.c @@ -90,7 +90,11 @@ getifaddrs2(struct ifaddrs **ifap, int af, int siocgifconf, int siocgifflags, ret = ENOMEM; goto error_out; } +#if defined(__QNX__) + ifconf.ifc_len = (short)(int)buf_size; +#else ifconf.ifc_len = (int)buf_size; +#endif ifconf.ifc_buf = buf; /* diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c index 24fdb7040..07df994cc 100644 --- a/lib/plat/unix/unix-sockets.c +++ b/lib/plat/unix/unix-sockets.c @@ -236,7 +236,8 @@ lws_plat_set_socket_options_ip(lws_sockfd_type fd, uint8_t pri, int lws_flags) !defined(__OpenBSD__) && \ !defined(__sun) && \ !defined(__HAIKU__) && \ - !defined(__CYGWIN__) + !defined(__CYGWIN__) && \ + !defined(__QNX__) /* the BSDs don't have SO_PRIORITY */ diff --git a/minimal-examples-lowlevel/http-client/minimal-http-client-captive-portal/CMakeLists.txt b/minimal-examples-lowlevel/http-client/minimal-http-client-captive-portal/CMakeLists.txt index e7be79a96..f332dc5b9 100644 --- a/minimal-examples-lowlevel/http-client/minimal-http-client-captive-portal/CMakeLists.txt +++ b/minimal-examples-lowlevel/http-client/minimal-http-client-captive-portal/CMakeLists.txt @@ -10,6 +10,7 @@ set(SAMP lws-minimal-http-client-captive-portal) set(SRCS minimal-http-client-captive-portal.c) set(requirements 1) +require_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) require_lws_config(LWS_WITH_TLS 1 requirements) require_lws_config(LWS_WITH_CLIENT 1 requirements) @@ -19,9 +20,9 @@ if (NOT WIN32 AND requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread ${LIBWEBSOCKETS_DEP_LIBS}) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread ${LIBWEBSOCKETS_DEP_LIBS}) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff --git a/minimal-examples-lowlevel/raw/minimal-raw-serial/minimal-raw-file.c b/minimal-examples-lowlevel/raw/minimal-raw-serial/minimal-raw-file.c index 45d50af0a..57ba8f096 100644 --- a/minimal-examples-lowlevel/raw/minimal-raw-serial/minimal-raw-file.c +++ b/minimal-examples-lowlevel/raw/minimal-raw-serial/minimal-raw-file.c @@ -109,7 +109,11 @@ callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, #if defined(__linux__) CBAUD | #endif - CSIZE | CSTOPB | PARENB | CRTSCTS); + CSIZE | CSTOPB | PARENB +#if !defined(__QNX__) + | CRTSCTS +#endif + ); tio.c_cflag |= 0x1412 | CS8 | CREAD | CLOCAL; tcsetattr(vhd->filefd, TCSANOW, &tio);