Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake errors when cross-compiling libwebsockets for arm cortex-m4

Let me preface this question: I've spent hours today researching this problem, with many hits on stackoverflow. I feel like I'm close, but there's always something in the way. I wouldn't be asking if I didn't feel like I've exhausted what Google has to offer. I know my target intimately and have cross-compiled many open source packages successfully, however, given that libwebsockets uses cmake, which I'm unfamiliar with, the errors are quite alien to me; I suppose I could pour through cmake documentation, but I doubt I'd find the answer within the timeframe I have.

I'm trying to cross-compile libwebsockets for an ARM-Cortex-M4 platform. I've followed the instructions from the libwebsockets documentation: 1) create a "build" directory above the libwebsockets source directory. 2) From within the build directory, call cmake:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../cross.cmake

3) I've used their ARM template to create cross.cmake

#
# CMake Toolchain file for crosscompiling on ARM.
#
# This can be used when running cmake in the following way:
#  cd build/
#  cmake .. -DCMAKE_TOOLCHAIN_FILE=../cross-arm-linux-gnueabihf.cmake
#


# Name of C compiler.
SET(CMAKE_C_COMPILER "arm-uclinuxeabi-gcc")
SET(CMAKE_CXX_COMPILER "arm-uclinuxeabi-g++")


# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(BUILD_SHARED_LIBS OFF)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  ../../../../A2F ../../../../tools ../../../xv-nic)
SET(ZLIB_INCLUDE_DIR "../lzo-2.09/")
SET(ZLIB_LIBRARY "../../lib/libz.a")
SET(OPENSSL_ROOT_DIR "../../ssl")
SET(OPENSSL_LIBRARIES "../../ssl/usr/local/ssl/lib/")
SET(OPENSSL_INCLUDE_DIR "../../ssl/usr/local/ssl/include/openssl/")

# 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)

4) This fails with this complaint

Compiling with SSL support
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: **OPENSSL_LIBRARIES**)
Call Stack (most recent call first):
  /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.5/Modules/FindOpenSSL.cmake:370 (find_package_handle_standard_args)
  CMakeLists.txt:816 (find_package)

Now, what's curious/frustrating is that I do have openssl installed where I claim to; further, if I remove

SET(ZLIB_INCLUDE_DIR "../lzo-2.09/")

, I get a complaint similar to the libraries complaint. Further, cmake seems to find zlib which is present in a similar way. I've compiled several other applications with this ssl setup without trouble, though I'm unfamiliar with cmake in general.

I've tried to be as verbose as possible without crafting a post too long to read, so if I've left something out, I'd be happy to provide more detail if anyone has fought through this. Thanks in advance!

like image 546
tphelican Avatar asked Dec 10 '25 06:12

tphelican


1 Answers

I had the same issue. Setting the following variables in my toolchain.cmake file did the trick:

SET(ZLIB_INCLUDE_DIR ../../../build/buildroot-build/staging/usr/include)
SET(ZLIB_LIBRARY ../../../build/buildroot-build/target/usr/lib/libz.so)

SET(OPENSSL_ROOT_DIR ../../../build/buildroot-build/target/usr)
SET(OPENSSL_LIBRARIES ../../../build/buildroot-build/target/usr/lib)
SET(OPENSSL_INCLUDE_DIR ../../../build/buildroot-build/staging/usr/include/openssl)
SET(OPENSSL_CRYPTO_LIBRARY ../../../build/buildroot-build/target/usr/lib/libcrypto.so)
SET(OPENSSL_SSL_LIBRARY ../../../build/buildroot-build/target/usr/lib/libssl.so)
like image 84
Luis Avatar answered Dec 12 '25 20:12

Luis