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

Add Fast dds #5968

Merged
merged 23 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from 18 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
10 changes: 10 additions & 0 deletions recipes/fast-dds/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are blocking older compilers this should not be required (it also blocks consumers from setting the cppstd settings)

Suggested change
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory("source_subfolder")
8 changes: 8 additions & 0 deletions recipes/fast-dds/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"2.3.2":
url: "https://github.com/eProsima/Fast-DDS/archive/refs/tags/v2.3.2.tar.gz"
sha256: "4D8183CF4D37C3DE9E6FD28D2850DD08023A9079001C4880B23C95F0D8C0B5CE"
patches:
"2.3.2":
- base_path: "source_subfolder"
patch_file: "patches/2.3.2-0001-fix-find-asio-and-tinyxml2.patch"
209 changes: 209 additions & 0 deletions recipes/fast-dds/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
from conans import ConanFile, CMake, tools
import os
from conans.errors import ConanInvalidConfiguration
import textwrap

class FastDDSConan(ConanFile):

name = "fast-dds"
license = "Apache-2.0"
homepage = "https://fast-dds.docs.eprosima.com/"
url = "https://github.com/conan-io/conan-center-index"
description = "The most complete OSS DDS implementation for embedded systems."
topics = ("DDS", "Middleware", "IPC")
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_ssl": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"with_ssl": False
}
generators = "cmake", "cmake_find_package"
_cmake = None
exports_sources = ["patches/**", "CMakeLists.txt"]

@property
def _pkg_share(self):
return os.path.join(
self.package_folder,
"share"
)

@property
def _pkg_tools(self):
return os.path.join(
self.package_folder,
"tools"
)

@property
def _pkg_bin(self):
return os.path.join(
self.package_folder,
"bin"
)

@property
def _module_subfolder(self):
return os.path.join(
"lib",
"cmake"
)

@property
def _module_file_rel_path(self):
return os.path.join(
self._module_subfolder,
"conan-target-properties.cmake"
)

@staticmethod
def _create_cmake_module_alias_targets(module_file, targets):
content = ""
for alias, aliased in targets.items():
content += textwrap.dedent("""\
if(TARGET {aliased} AND NOT TARGET {alias})
add_library({alias} INTERFACE IMPORTED)
set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased})
endif()
""".format(alias=alias, aliased=aliased))
tools.save(module_file, content)

@property
def _source_subfolder(self):
return "source_subfolder"

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

def configure(self):
if self.options.shared:
del self.options.fPIC

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["BUILD_MEMORY_TOOLS"] = False
self._cmake.definitions["NO_TLS"] = not self.options.with_ssl
self._cmake.definitions["SECURITY"] = self.options.with_ssl
self._cmake.definitions["EPROSIMA_INSTALLER_MINION"] = False
self._cmake.configure()
return self._cmake

def requirements(self):
self.requires("tinyxml2/7.1.0")
self.requires("asio/1.18.2")
self.requires("fast-cdr/1.0.21")
self.requires("foonathan-memory/0.7.0")
if self.options.with_ssl:
self.requires("openssl/1.1.1k")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True,
destination=self._source_subfolder)

def validate(self):
os = self.settings.os
compiler = self.settings.compiler
version = tools.Version(self.settings.compiler.version)
if compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if os == "Linux" and compiler == "gcc" and version < "5":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a template conan-io/conan#8002 you can reuse to also print a warning for the consumer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and btw - nice idea - to have a standard template here ;)

raise ConanInvalidConfiguration(
"Using Fast-DDS with gcc on Linux requires gcc 5 or higher.")
if os == "Linux" and compiler == "clang" and version < "5.0":
raise ConanInvalidConfiguration(
"Using Fast-DDS with clang on Linux requires clang 5 or higher.")
if os == "Windows" and compiler == "Visual Studio" and version < "16":
raise ConanInvalidConfiguration(
"Fast-DDS was tested on Windows with VS Compiler 16")

if self.settings.os == "Windows":
if ("MT" in self.settings.compiler.runtime and self.options.shared):
# This combination leads to an fast-dds error when linking
# linking dynamic '*.dll' and static MT runtime
raise ConanInvalidConfiguration("Mixing a dll eprosima library with a static runtime is a bad idea")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ConanInvalidConfiguration("Mixing a dll eprosima library with a static runtime is a bad idea")
raise ConanInvalidConfiguration("Mixing a dll {} library with a static runtime is a bad idea".format(self.name))



def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(self._pkg_share)
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
tools.rename(
src=self._pkg_tools,
dst=os.path.join(self._pkg_bin, "tools")
)
tools.remove_files_by_mask(
directory=os.path.join(self.package_folder, "lib"),
pattern="*.pdb"
)
tools.remove_files_by_mask(
directory=os.path.join(self.package_folder, "bin"),
pattern="*.pdb"
)
self._create_cmake_module_alias_targets(
os.path.join(self.package_folder, self._module_file_rel_path),
{"fastrtps": "fastdds::fastrtps"}
)

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "fastdds"
self.cpp_info.names["cmake_find_multi_package"] = "fastdds"
# component fastrtps
self.cpp_info.components["fastrtps"].name = "fastrtps"
self.cpp_info.components["fastrtps"].libs = tools.collect_libs(self)
self.cpp_info.components["fastrtps"].requires = [
"fast-cdr::fast-cdr",
"asio::asio",
"tinyxml2::tinyxml2",
"foonathan-memory::foonathan-memory"
]
if self.settings.os in ["Linux", "Macos", "Neutrino"]:
self.cpp_info.components["fastrtps"].system_libs = [
"pthread"
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cpp_info.components["fastrtps"].system_libs = [
"pthread"
]
self.cpp_info.components["fastrtps"].system_libs.append("pthread")

if self.settings.os == "Linux":
self.cpp_info.components["fastrtps"].system_libs = [
"rt",
"dl",
"atomic"
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.cpp_info.components["fastrtps"].system_libs = [
"rt",
"dl",
"atomic"
]
self.cpp_info.components["fastrtps"].system_libs.extends(["rt", "dl", "atomic"])

elif self.settings.os == "Windows":
self.cpp_info.components["fastrtps"].system_libs = [
"iphlpapi",
"shlwapi"
]
if self.options.shared:
self.cpp_info.components["fastrtps"].defines.append("FASTRTPS_DYN_LINK")
if self.options.with_ssl:
self.cpp_info.components["fastrtps"].requires.append("openssl::openssl")
self.cpp_info.components["fastrtps"].builddirs.append(self._module_subfolder)
self.cpp_info.components["fastrtps"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
self.cpp_info.components["fastrtps"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
# component fast-discovery
self.cpp_info.components["fast-discovery"].name = "fast-discovery"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fast-discovery-server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Jesus.... Damn.... I would rise an issue and assign it to myself. And in a separate PR resolve the issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be resolved in #6429

self.cpp_info.components["fast-discovery"].bindirs = ["bin"]
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH env var for fast-dds::fast-discovery with : {}".format(bin_path)),
self.env_info.PATH.append(bin_path)
# component tools
self.cpp_info.components["tools"].name = "tools"
self.cpp_info.components["tools"].bindirs = [os.path.join("bin","tools")]
Comment on lines +206 to +207
Copy link
Contributor

@SpaceIm SpaceIm Jul 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As usual, too generic for a conan component name where pkg_config name is not overriden. Anyway this component doesn't exist upstream (there are tools, but their targets are not exported).

I advice also to be explicit on the type of "names" (names["cmake_find_package"] etc, this library doesn't provide official pkgconfig files for example).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be resolved in #6429

bin_path = os.path.join(self._pkg_bin, "tools")
self.output.info("Appending PATH env var for fast-dds::tools with : {}".format(bin_path)),
self.env_info.PATH.append(bin_path)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8a9cb0209..400c681e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -225,8 +225,8 @@ if(NOT BUILD_SHARED_LIBS)
endif()

eprosima_find_package(fastcdr REQUIRED)
-eprosima_find_thirdparty(Asio asio VERSION 1.10.8)
-eprosima_find_thirdparty(TinyXML2 tinyxml2)
+eprosima_find_thirdparty(asio REQUIRED)
+eprosima_find_thirdparty(tinyxml2 REQUIRED)

find_package(foonathan_memory REQUIRED)
message(STATUS "Found foonathan_memory: ${foonathan_memory_DIR}")
diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt
index 04d313bf2..c7d64f04d 100644
--- a/src/cpp/CMakeLists.txt
+++ b/src/cpp/CMakeLists.txt
@@ -455,7 +455,7 @@ elseif(NOT EPROSIMA_INSTALLER)
# Link library to external libraries.
target_link_libraries(${PROJECT_NAME} ${PRIVACY} fastcdr foonathan_memory
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}
- ${TINYXML2_LIBRARY}
+ tinyxml2::tinyxml2
$<$<BOOL:${LINK_SSL}>:OpenSSL::SSL$<SEMICOLON>OpenSSL::Crypto>
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
${THIRDPARTY_BOOST_LINK_LIBS}
10 changes: 10 additions & 0 deletions recipes/fast-dds/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(HelloWorldExample)
24 changes: 24 additions & 0 deletions recipes/fast-dds/all/test_package/HelloWorldExample/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.1)

find_package(fastdds REQUIRED)

file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CXX "*.cxx")
file(GLOB HELLOWORLD_EXAMPLE_SOURCES_CPP "*.cpp")

add_executable(test_package ${HELLOWORLD_EXAMPLE_SOURCES_CXX} ${HELLOWORLD_EXAMPLE_SOURCES_CPP})
# validate the alias
target_link_libraries(test_package fastrtps)
Loading