Search code examples
gccbuildarmcross-compilinglibwebsockets

Building cross-compiled ARM files for libwebsockets, in addition to GCC files


I am implementing a web server using libwebsockets (LWS) for an embedded ARM processor. I am testing the server on gcc in Ubuntu as I learn about LWS. I have the server working as a gcc build, but now want to build the cross-compiled version for the ARM board.

I created a toolchain file:

// Set the path to ARM directories to just above the bin directory
set(CROSS_PATH usr/local/opt/crosstool/arm-linux/gcc-3.3.4-glibc-2.3.2)

// Target operating system name
set(CMAKE_SYSTEM_NAME Linux)

// Name of C compiler
set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-linux-gcc")
set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-linux-g++")

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

I created a build directory at the same level as my gcc build directory.

GCC:  libwebsockets > build
ARM:  libwebsockets > buildx

The file required by cmake, CMakeList.txt, is in "libwebsockets" which is referenced when cmake is invoked (for gcc):

cmake ..

or for arm-linux-gcc:

cmake .. -DCMAKE_TOOLCHAIN_FILE=../arm-linuc-gcc.cmake

But running this last line updates a few file (like cmake cache) and does not create the build files.

How do I build the ARM files? Am I required to delete the existing gcc build before a new build can be created?

Thanks for your help!


Solution

  • The instructions for the lwsws .exe for libwebsockets (warmcat) posted on github specify that you start with an empty build directory. I took that to mean within the existing LWS framework.

    But you cannot build for a different compiler within the existing compiler.

    So, I cloned LWS in my cross compiler path and created new build files with a new copy of cmake (CMakeLists.txt) that was loaded with LWS.

    This solved the problem of being able to create new build files, but my toolchain set-up is still compiling for gcc instead of arm-linux-gcc. But that is a problem for a new stackoverflow question (coming soon...).

    The website that helped me (obliquely) is: https://gist.github.com/maoueh/14ef25a03d5722bc1e03 There is a section on LWS that shows creating a new LWS build.