Skip to content

Commit

Permalink
ignition-msgs5: Add support for crosscompilation
Browse files Browse the repository at this point in the history
Similar to the protobuf case, when cross-compiling it is required
that the port is already installed in the host machine triplet,
for now just x86-windows as for protobuf.
  • Loading branch information
traversaro committed Sep 5, 2020
1 parent cfd98a6 commit 6921ebe
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 9 deletions.
70 changes: 70 additions & 0 deletions ports/ignition-msgs5/02-support-crosscompilation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
From 8d3735616c34fdc266b45c614c6d179d72732066 Mon Sep 17 00:00:00 2001
From: Silvio Traversaro <silvio.traversaro@iit.it>
Date: Sat, 23 May 2020 12:09:15 +0200
Subject: [PATCH] Add CMake options to support cross-compilation

This commit adds two CMake options:
* INSTALL_IGN_MSGS_GEN_EXECUTABLE if this option is enabled, the
ign_msgs_gen protobuf executable plugin is also installed, so
that this option can be enabled in host builds to permit
cross-compilation builds to use it to generate the messages.
As this executable is not side by side installable with other
ignition-msgs installations with different major versions and is an
advanced option meant just for packaging, by default it is set to OFF.
* IGN_MSGS_GEN_EXECUTABLE: this string variable can be set to
have ign-msgs use a ign_msgs_gen executable plugin that was not
build by the project, to enable cross-compilation scenarios.

Signed-off-by: Silvio Traversaro <silvio.traversaro@iit.it>
---
CMakeLists.txt | 13 ++++++++++++-
src/CMakeLists.txt | 6 +++++-
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62b56b1..1641489 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,18 @@ ign_configure_project()
# Set project-specific options
#============================================================================

-# ignition-msgs currently has no options that are unique to it
+option(
+ INSTALL_IGN_MSGS_GEN_EXECUTABLE
+ "Install the ign_msgs_gen executable."
+ OFF)
+mark_as_advanced(INSTALL_IGN_MSGS_GEN_EXECUTABLE)
+
+set(
+ IGN_MSGS_GEN_EXECUTABLE
+ "$<TARGET_FILE:ign_msgs_gen>"
+ CACHE STRING
+ "ign_msgs_gen executable used in the ign_msgs_protoc CMake function.")
+mark_as_advanced(IGN_MSGS_GEN_EXECUTABLE)

#============================================================================
# Search for project-specific dependencies
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f68bf3d..1eb5e36 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -11,6 +11,9 @@ if (UNIX)
target_link_libraries(ign_msgs_gen pthread)
endif()

+if(INSTALL_IGN_MSGS_GEN_EXECUTABLE)
+ install(TARGETS ign_msgs_gen DESTINATION ${IGN_BIN_INSTALL_DIR})
+endif()

##################################################
# A function that calls protoc on a protobuf file
@@ -57,7 +61,7 @@ function(ign_msgs_protoc)
list(APPEND ${ign_msgs_protoc_OUTPUT_CPP_CC_VAR} ${output_source})
list(APPEND output_files ${output_header})
list(APPEND output_files ${output_source})
- list(APPEND protoc_args "--plugin=protoc-gen-ignmsgs=$<TARGET_FILE:ign_msgs_gen>")
+ list(APPEND protoc_args "--plugin=protoc-gen-ignmsgs=${IGN_MSGS_GEN_EXECUTABLE}")
list(APPEND protoc_args "--cpp_out=dllexport_decl=IGNITION_MSGS_VISIBLE:${ign_msgs_protoc_OUTPUT_CPP_DIR}")
list(APPEND protoc_args "--ignmsgs_out" "${ign_msgs_protoc_OUTPUT_CPP_DIR}")
set(${ign_msgs_protoc_OUTPUT_CPP_HH_VAR} ${${ign_msgs_protoc_OUTPUT_CPP_HH_VAR}} PARENT_SCOPE)
2 changes: 1 addition & 1 deletion ports/ignition-msgs5/CONTROL
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Version: 5.1.0
Port-Version: 1
Build-Depends: ignition-modularscripts, ignition-cmake2, ignition-math6, protobuf, tinyxml2
Description: Middleware protobuf messages for robotics
Supports: !(arm|linux|uwp)
Supports: !(linux)
42 changes: 34 additions & 8 deletions ports/ignition-msgs5/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
# Explicitly disable cross-compilation until the upstream discussion
# https://github.com/ignitionrobotics/ign-msgs/issues/34 is solved
vcpkg_fail_port_install(ON_ARCH "arm" ON_TARGET "linux" "uwp")
vcpkg_fail_port_install(ON_TARGET "linux")

include(${CURRENT_INSTALLED_DIR}/share/ignitionmodularscripts/ignition_modular_library.cmake)

if(CMAKE_HOST_WIN32 AND NOT VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND NOT VCPKG_TARGET_ARCHITECTURE MATCHES "x86")
set(ignition_msgs_CROSSCOMPILING ON)
else()
set(ignition_msgs_CROSSCOMPILING OFF)
endif()

if(CMAKE_HOST_WIN32)
set(HOST_EXECUTABLE_SUFFIX ".exe")
else()
set(HOST_EXECUTABLE_SUFFIX "")
endif()

# This port needs to generate protobuf messages with a custom plugin generator,
# so it needs to have in Windows the relative protobuf dll available in the PATH
set(path_backup $ENV{PATH})
vcpkg_add_to_path(${CURRENT_INSTALLED_DIR}/bin)
vcpkg_add_to_path(${CURRENT_INSTALLED_DIR}/debug/bin)
if(NOT ignition_msgs_CROSSCOMPILING)
set(path_backup $ENV{PATH})
vcpkg_add_to_path(${CURRENT_INSTALLED_DIR}/bin)
vcpkg_add_to_path(${CURRENT_INSTALLED_DIR}/debug/bin)
set(CMAKE_OPTIONS "-DINSTALL_IGN_MSGS_GEN_EXECUTABLE:BOOL=ON")
set(TOOL_NAMES_OPTION TOOL_NAMES ign_msgs_gen)
else()
if(NOT EXISTS ${CURRENT_INSTALLED_DIR}/../x86-windows/tools/${PORT})
message(FATAL_ERROR "Cross-targetting ${PORT} requires the x86-windows ${PORT} to be available. Please install ${PORT}:x86-windows first.")
endif()
set(CMAKE_OPTIONS "-DIGN_MSGS_GEN_EXECUTABLE=${CURRENT_INSTALLED_DIR}/../x86-windows/tools/${PORT}/ign_msgs_gen${HOST_EXECUTABLE_SUFFIX}")
set(TOOL_NAMES_OPTION "")
endif()

ignition_modular_library(NAME msgs
VERSION "5.1.0"
SHA512 db485f737c465b310602342a1a751c561473e330eb18d1b322b32d13de246536fe6a7efdf245faaaa9be1c9bfce662b2d39d1bb7cffc37e52690893cb47cc2ee
PATCHES
"01-protobuf.patch")
"01-protobuf.patch"
# Backport https://github.com/ignitionrobotics/ign-msgs/pull/60
"02-support-crosscompilation.patch"
CMAKE_OPTIONS "${CMAKE_OPTIONS}"
${TOOL_NAMES_OPTION})

# Restore old path
set(ENV{PATH} "${path_backup}")
if(NOT ignition_msgs_CROSSCOMPILING)
set(ENV{PATH} "${path_backup}")
endif()

0 comments on commit 6921ebe

Please sign in to comment.