Cmake CROSS COMPILE problem [PLEASE HELP, URGENT] #yocto #sdk #toolchain


Bel Hadj Salem Talel
 

Hi All,

I'm in serious task here and I need to cross compile a Cmake project.
I need to send an SDK to a client with steps to cross compile the project.
This project is compiling successfully via a Yocto recipe that inherits cmake.
I extracted an SDK from the main image adding TOOLCHAIN_HOST_TASK_append=" nativesdk-cmake" to add the Toolchain cmake file which is located under: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake :
Here is its content:

set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_C_FLAGS $ENV{CFLAGS} CACHE STRING "" FORCE )
set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS}  CACHE STRING "" FORCE )
set( CMAKE_ASM_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "" FORCE )
set( CMAKE_LDFLAGS_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE )
set( CMAKE_SYSROOT $ENV{OECORE_TARGET_SYSROOT} )
set( CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT} )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX "$ENV{OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}")
# Set CMAKE_SYSTEM_PROCESSOR from the sysroot name (assuming processor-distro-os).
if ($ENV{SDKTARGETSYSROOT} MATCHES "/sysroots/([a-zA-Z0-9_-]+)-.+-.+")
  set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_MATCH_1})
endif()
# Include the toolchain configuration subscripts
file( GLOB toolchain_config_files "${CMAKE_TOOLCHAIN_FILE}.d/*.cmake" )
foreach(config ${toolchain_config_files})
    include(${config})
endforeach()


The project is working with gRPC and Protobuf. There is a .cmake files that are responsible for searching for gRPC and Protobuf libs

Here is what I tried after sourcing the SDK environment:
1) A simple "cmake .." with no options:

Setting build type to 'RelWithDebInfo' as none was specified.
-- Toolchain file defaulted to '/home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc
-- Check for working C compiler: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++
-- Check for working CXX compiler: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.16/Modules/FindProtobuf.cmake:499 (message):
  Protobuf compiler version 3.12.3 doesn't match library version 3.11.4
Call Stack (most recent call first):
  CMakeLists.txt:23 (find_package)
-- Found Protobuf: /home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/lib/libprotobuf.so;-lpthread (found version "3.11.4")
-- Could NOT find gRPC (missing: GRPC_CPP_PLUGIN)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/talel/Desktop/sense_software_2/build

protobuf is found, but not gRPC, now when I make:
make[2]: *** No rule to make target 'GRPC_CPP_PLUGIN-NOTFOUND', needed by 'protos/sense_api_settings.grpc.pb.cc'.  Stop.
CMakeFiles/Makefile2:734: recipe for target 'protos/CMakeFiles/sense_api_settings_grpc.dir/all' failed
make[1]: *** [protos/CMakeFiles/sense_api_settings_grpc.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

I searched for a solution and I added the -DCMAKE_PREFIX_PATH=/home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr option to my SDK rootfs
Here is the result of cmake..:

-- Check for working C compiler: /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc -- broken
CMake Error at /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler
    "/home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc"
  is not able to compile a simple test program.
  It fails with the following output:
    Change Dir: /home/talel/Desktop/sense_software_2/build/CMakeFiles/CMakeTmp
    Run Build Command(s):/home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/make cmTC_2a27c/fast && /home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/make: 1: /home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/make: Syntax error: word unexpected (expecting ")")

I tried to add C and CXX options : -DCMAKE_C_COMPILER_WORKS=1 -DCMAKE_CXX_COMPILER_WORKS=1:
Now it shows this:

/home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/protoc: 1: /home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/protoc: ELF�@2@8: not found
/home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/protoc: 2: /home/talel/Documents/sensesdk/sysroots/aarch64-poky-linux/usr/bin/protoc: Syntax error: ")" unexpected
CMake Warning at /home/talel/Documents/sensesdk/sysroots/x86_64-pokysdk-linux/usr/share/cmake-3.16/Modules/FindProtobuf.cmake:499 (message):
  Protobuf compiler version doesn't match library version 3.11.4

and now when I make same error ; syntax error in protobuf

Here is the main CMakeLists:
cmake_minimum_required (VERSION 3.5)

set(ex_ver "01")

# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message("Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

project(ex VERSION ${ex_ver})

# set the C++ standard to C++ 11
set(CMAKE_CXX_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include(CompileProtos)
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)
#find_package(gRPC REQUIRED)

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
if(CMAKE_CROSSCOMPILING)
find_program(_PROTOBUF_PROTOC protoc)
find_program(_gRPC_CPP_PLUGIN grpc_cpp_plugin)
else()
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()
#message(STATUS "Using protobuf ${protobuf_VERSION}")

# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(GRPC REQUIRED)

set(_GRPC_GRPCPP_REFLECTION gRPC::grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()

# uncomment for PC
#find_package(fmt REQUIRED)
#add_compile_definitions(SPDLOG_FMT_EXTERNAL)

#Add sub-directories
add_subdirectory(protos)
add_subdirectory(systemd)
add_subdirectory(certs)
add_subdirectory(services)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(core)



Help me please on this. It is really urgent, I tried a lot.
Thanks, Talel