3

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!

tphelican
  • 151
  • 8
  • Drop the trailing `openssl` from `SET(OPENSSL_INCLUDE_DIR "../../ssl/usr/local/ssl/include/openssl/")`. Source files will `#include `, and combined it results in a header path of `.../ssl/usr/local/ssl/include/openssl/openssl/header.h`. You might also try using `make V=1` or `make VERBOSE=1`. It will give you more information than the traditional and nearly useless Cmake output. – jww Jul 20 '16 at 07:50
  • You may also want to include `-mthumb -mcpu=cortex-m4` in `CFLAGS` and `CXXFLAGS` for the Cortex-M4. And possibly `-mfloat-abi=softfp -mfpu=fpv4-sp-d16` if there's a soft floating point unit and `-mfloat-abi=hard -mfpu=fpv4-sp-d16` for a hard floating point unit. Also see [cmake CFLAGS CXXFLAGS modification](http://stackoverflow.com/q/10085945). – jww Jul 20 '16 at 08:31
  • Just debug the `/usr/share/cmake-3.5/Modules/FindOpenSSL.cmake` by using `message()` function to output variables. – Velkan Jul 21 '16 at 06:20

1 Answers1

1

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)
Luis
  • 3,451
  • 1
  • 27
  • 41