Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignition-msgs5: Add support for cross-compilation #11538

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ports/ignition-modularscripts/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Source: ignition-modularscripts
Version: 2020-05-16
Port-Version: 1
Version: 2020-09-05
Description: Vcpkg helpers to package ignition libraries
133 changes: 73 additions & 60 deletions ports/ignition-modularscripts/ignition_modular_library.cmake
Original file line number Diff line number Diff line change
@@ -1,61 +1,3 @@

function(ignition_modular_build_library NAME MAJOR_VERSION SOURCE_PATH CMAKE_PACKAGE_NAME DEFAULT_CMAKE_PACKAGE_NAME IML_DISABLE_PKGCONFIG_INSTALL)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DBUILD_TESTING=OFF
)

vcpkg_install_cmake()

# If necessary, move the CMake config files
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/cmake")
# Some ignition libraries install library subcomponents, that are effectively additional cmake packages
# with name ${CMAKE_PACKAGE_NAME}-${COMPONENT_NAME}, so it is needed to call vcpkg_fixup_cmake_targets for them as well
file(GLOB COMPONENTS_CMAKE_PACKAGE_NAMES
LIST_DIRECTORIES TRUE
RELATIVE "${CURRENT_PACKAGES_DIR}/lib/cmake/"
"${CURRENT_PACKAGES_DIR}/lib/cmake/*")

foreach(COMPONENT_CMAKE_PACKAGE_NAME IN LISTS COMPONENTS_CMAKE_PACKAGE_NAMES)
vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/${COMPONENT_CMAKE_PACKAGE_NAME}"
TARGET_PATH "share/${COMPONENT_CMAKE_PACKAGE_NAME}"
DO_NOT_DELETE_PARENT_CONFIG_PATH)
endforeach()

file(GLOB_RECURSE CMAKE_RELEASE_FILES
"${CURRENT_PACKAGES_DIR}/lib/cmake/${CMAKE_PACKAGE_NAME}/*")

file(COPY ${CMAKE_RELEASE_FILES} DESTINATION
"${CURRENT_PACKAGES_DIR}/share/${CMAKE_PACKAGE_NAME}/")
endif()

# Remove unused files files
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/include
${CURRENT_PACKAGES_DIR}/debug/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/share)

# Make pkg-config files relocatable
if(NOT IML_DISABLE_PKGCONFIG_INSTALL)
if(VCPKG_TARGET_IS_LINUX)
set(SYSTEM_LIBRARIES SYSTEM_LIBRARIES pthread)
endif()
vcpkg_fixup_pkgconfig(${SYSTEM_LIBRARIES})
else()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/pkgconfig
${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig)
endif()

# Find the relevant license file and install it
if(EXISTS "${SOURCE_PATH}/LICENSE")
set(LICENSE_PATH "${SOURCE_PATH}/LICENSE")
elseif(EXISTS "${SOURCE_PATH}/README.md")
set(LICENSE_PATH "${SOURCE_PATH}/README.md")
endif()
file(INSTALL ${LICENSE_PATH} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
endfunction()

## # ignition_modular_library
##
## Download and build a library from the Ignition Robotics project ( https://ignitionrobotics.org/ ).
Expand Down Expand Up @@ -101,6 +43,13 @@ endfunction()
## ### DISABLE_PKGCONFIG_INSTALL
## If present, disable installation of .pc pkg-config configuration files.
##
## ### CMAKE_OPTIONS
## A list of options to be passed to the CMake invocation.
## This is forwarded to the `vcpkg_configure_cmake` command.
##
## ### TOOL_NAMES
## A list of executable tools that need to be handled by this port.
## If present, this option is forwarded to the `vcpkg_copy_tools` command.
##
## ## Examples:
##
Expand All @@ -110,7 +59,7 @@ endfunction()
function(ignition_modular_library)
set(options DISABLE_PKGCONFIG_INSTALL)
set(oneValueArgs NAME VERSION SHA512 REF HEAD_REF CMAKE_PACKAGE_NAME)
set(multiValueArgs PATCHES)
set(multiValueArgs PATCHES CMAKE_OPTIONS TOOL_NAMES)
cmake_parse_arguments(IML "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

string(REPLACE "." ";" IML_VERSION_LIST ${IML_VERSION})
Expand All @@ -132,6 +81,11 @@ function(ignition_modular_library)
set(IML_CMAKE_PACKAGE_NAME ${DEFAULT_CMAKE_PACKAGE_NAME})
endif()

# If the CMAKE_OPTIONS option is omitted set it to an empty
if(NOT DEFINED IML_CMAKE_OPTIONS)
set(IML_CMAKE_OPTIONS "")
endif()

# Download library from github, to support also the --head option
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
Expand All @@ -143,5 +97,64 @@ function(ignition_modular_library)
)

# Build library
ignition_modular_build_library(${IML_NAME} ${IML_MAJOR_VERSION} ${SOURCE_PATH} ${IML_CMAKE_PACKAGE_NAME} ${DEFAULT_CMAKE_PACKAGE_NAME} ${IML_DISABLE_PKGCONFIG_INSTALL})
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DBUILD_TESTING:BOOL=OFF ${IML_CMAKE_OPTIONS}
)

vcpkg_install_cmake()

# If necessary, move the CMake config files
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/cmake")
# Some ignition libraries install library subcomponents, that are effectively additional cmake packages
# with name ${CMAKE_PACKAGE_NAME}-${COMPONENT_NAME}, so it is needed to call vcpkg_fixup_cmake_targets for them as well
file(GLOB COMPONENTS_CMAKE_PACKAGE_NAMES
LIST_DIRECTORIES TRUE
RELATIVE "${CURRENT_PACKAGES_DIR}/lib/cmake/"
"${CURRENT_PACKAGES_DIR}/lib/cmake/*")

foreach(COMPONENT_CMAKE_PACKAGE_NAME IN LISTS COMPONENTS_CMAKE_PACKAGE_NAMES)
vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/${COMPONENT_CMAKE_PACKAGE_NAME}"
TARGET_PATH "share/${COMPONENT_CMAKE_PACKAGE_NAME}"
DO_NOT_DELETE_PARENT_CONFIG_PATH)
endforeach()

file(GLOB_RECURSE CMAKE_RELEASE_FILES
"${CURRENT_PACKAGES_DIR}/lib/cmake/${CMAKE_PACKAGE_NAME}/*")

file(COPY ${CMAKE_RELEASE_FILES} DESTINATION
"${CURRENT_PACKAGES_DIR}/share/${CMAKE_PACKAGE_NAME}/")
endif()

# Remove unused files files
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/include
${CURRENT_PACKAGES_DIR}/debug/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/share)

# Make pkg-config files relocatable
if(NOT IML_DISABLE_PKGCONFIG_INSTALL)
if(VCPKG_TARGET_IS_LINUX)
set(SYSTEM_LIBRARIES SYSTEM_LIBRARIES pthread)
endif()
vcpkg_fixup_pkgconfig(${SYSTEM_LIBRARIES})
else()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/pkgconfig
${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig)
endif()

# Find the relevant license file and install it
if(EXISTS "${SOURCE_PATH}/LICENSE")
set(LICENSE_PATH "${SOURCE_PATH}/LICENSE")
elseif(EXISTS "${SOURCE_PATH}/README.md")
set(LICENSE_PATH "${SOURCE_PATH}/README.md")
endif()
file(INSTALL ${LICENSE_PATH} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

# Handle tools
if(DEFINED IML_TOOL_NAMES)
vcpkg_copy_tools(TOOL_NAMES ${IML_TOOL_NAMES} AUTO_CLEAN)
endif()

endfunction()
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)
NancyLi1013 marked this conversation as resolved.
Show resolved Hide resolved
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()
1 change: 0 additions & 1 deletion ports/protobuf/CONTROL
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Version: 3.13.0
Port-Version: 2
Homepage: https://github.com/protocolbuffers/protobuf
Description: Protocol Buffers - Google's data interchange format
JackBoosY marked this conversation as resolved.
Show resolved Hide resolved

Feature: zlib
Description: ZLib based features like Gzip streams
Build-Depends: zlib
12 changes: 6 additions & 6 deletions ports/protobuf/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ vcpkg_from_github(
)

if(CMAKE_HOST_WIN32 AND NOT VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND NOT VCPKG_TARGET_ARCHITECTURE MATCHES "x86")
set(protobuf_BUILD_PROTOC_BINARIES OFF)
set(protobuf_CROSSCOMPILING ON)
elseif(CMAKE_HOST_WIN32 AND NOT VCPKG_TARGET_IS_MINGW AND NOT (VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_UWP))
set(protobuf_BUILD_PROTOC_BINARIES OFF)
set(protobuf_CROSSCOMPILING ON)
else()
set(protobuf_BUILD_PROTOC_BINARIES ON)
set(protobuf_CROSSCOMPILING OFF)
endif()

if(NOT protobuf_BUILD_PROTOC_BINARIES AND NOT EXISTS ${CURRENT_INSTALLED_DIR}/../x86-windows/tools/protobuf)
if(protobuf_CROSSCOMPILING AND NOT EXISTS ${CURRENT_INSTALLED_DIR}/../x86-windows/tools/protobuf)
message(FATAL_ERROR "Cross-targetting protobuf requires the x86-windows protoc to be available. Please install protobuf:x86-windows first.")
endif()

Expand Down Expand Up @@ -52,7 +52,7 @@ vcpkg_configure_cmake(
-Dprotobuf_MSVC_STATIC_RUNTIME=${VCPKG_BUILD_STATIC_CRT}
-Dprotobuf_BUILD_TESTS=OFF
-DCMAKE_INSTALL_CMAKEDIR:STRING=share/protobuf
-Dprotobuf_BUILD_PROTOC_BINARIES=${protobuf_BUILD_PROTOC_BINARIES}
-Dprotobuf_BUILD_PROTOC_BINARIES=ON
${FEATURE_OPTIONS}
)

Expand Down Expand Up @@ -94,7 +94,7 @@ endif()
protobuf_try_remove_recurse_wait(${CURRENT_PACKAGES_DIR}/debug/share)

if(CMAKE_HOST_WIN32)
if(protobuf_BUILD_PROTOC_BINARIES)
if(NOT protobuf_CROSSCOMPILING)
vcpkg_copy_tools(TOOL_NAMES protoc)
else()
file(COPY ${CURRENT_INSTALLED_DIR}/../x86-windows/tools/${PORT} DESTINATION ${CURRENT_PACKAGES_DIR}/tools)
Expand Down