eclipse-cyclonedds / cyclonedds-cxx

Other
95 stars 75 forks source link

Cross compiling a dependent application with cmake - host idlc and cycloneddsidlcxx #364

Open Entropy512 opened 1 year ago

Entropy512 commented 1 year ago

This is somewhat of a continuation of the conversation in https://github.com/eclipse-cyclonedds/cyclonedds/issues/794#issuecomment-1205572397

I'm trying to start from @stan-guer 's comment, adapting it to use cyclonedds-cxx:

if(CMAKE_CROSSCOMPILING)
  include("${Cyclone_HOST_PREFIX}/lib/cmake/CycloneDDS-CXX/idlcxx/Generate.cmake")
endif()

idlcxx_generate(TARGET messages FILES HelloWorldData.idl WARNINGS no-implicit-extensibility)

(yes, I'm starting with trying to cross-compile hello world as a standalone dependent app with some restructuring of the file tree - since the example is dependent on being built within the cyclonedds source tree)

I've set Cyclone_HOST_PREFIX in my toolchain file to where I installed the host-architecture build of cyclonedds and cyclonedds-cxx (In my case, ~/cyclonedds_host)

The question is - how do I add Cyclone_HOST_PREFIX to the search path so that find_library() works for cycloneddsidlcxx? I get the following:

CMake Error at /home/adodd/cyclonedds_host/lib/cmake/CycloneDDS-CXX/idlcxx/Generate.cmake:27 (find_library):
  Could not find _idlcxx_shared_lib using the following names:
  cycloneddsidlcxx
Call Stack (most recent call first):
  idl/CMakeLists.txt:5 (idlcxx_generate)

Adding Cyclone_HOST_PREFIX to CMAKE_FIND_ROOT_PATH does not work.

Entropy512 commented 1 year ago

I've made a bit of progress, first - need to include idlc/Generate.cmake too:

if(CMAKE_CROSSCOMPILING)
  include("${Cyclone_HOST_PREFIX}/lib/cmake/CycloneDDS-CXX/idlcxx/Generate.cmake")
  include("${Cyclone_HOST_PREFIX}/lib/cmake/CycloneDDS/idlc/Generate.cmake")
endif()

In addition, after a bit of digging into cmake_fu, I figured out WHY my current protobuf cross-compile stuff is working in another project (One of the variables I set overrides find_program), and adapted it to the variables used by Generate.cmake:

set(Cyclone_HOST_PREFIX $ENV{HOME}/cyclonedds_host)
set(_idlcxx_shared_lib ${Cyclone_HOST_PREFIX}/lib/libcycloneddsidlcxx.so.0.11.0)
set(_idlc_executable ${Cyclone_HOST_PREFIX}/bin/idlc)

Now the problem is that the generator expects the -o option to work properly, but it does not - I am guessing this is due to https://github.com/eclipse-cyclonedds/cyclonedds-cxx/pull/148 not yet being adapted to https://github.com/eclipse-cyclonedds/cyclonedds/pull/1263

alexleel commented 1 year ago

Hi @Entropy512 I got a similar issue as "Could not find _idlc_executable using the following names: idlc" when I set -DBUILD_EXAMPLES=ON. Could you please help to trouble shooting it? I did not find cyclonedds_host in my machine