Skip to content

Commit

Permalink
modernize more & few fixes
Browse files Browse the repository at this point in the history
- fix config file name
- fix pkgconfig file name
- bump iceoryx & openssl
- require cmake only if recent version not available on build machine
- more elegant removal of vc runtime files
  • Loading branch information
SpaceIm committed Jan 23, 2023
1 parent 82ccf5f commit f594a04
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 90 deletions.
154 changes: 73 additions & 81 deletions recipes/cyclonedds/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools import files, build, scm
from conan.tools.microsoft import is_msvc
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rm, rmdir
from conan.tools.scm import Version
import os

required_conan_version = ">=1.53.0"

required_conan_version = ">=1.51.3"

class CycloneDDSConan(ConanFile):
name = "cyclonedds"
Expand All @@ -22,146 +24,128 @@ class CycloneDDSConan(ConanFile):
"fPIC": [True, False],
"with_ssl": [True, False],
"with_shm" : [True, False],
"enable_security" : [True, False]
"enable_security" : [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_ssl": False,
"with_shm": False,
"enable_security": False
"enable_security": False,
}

short_paths = True

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

@property
def _tmp_folder(self):
return os.path.join(self.package_folder,"tmp")

@property
def _license_folder(self):
return os.path.join(self.package_folder,"licenses")
def _min_cppstd(self):
return "14"

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"Visual Studio": "16.0",
"Visual Studio": "16",
"msvc": "192",
"clang": "7",
"apple-clang": "10",
}

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
files.copy(self,patch["patch_file"],self.recipe_folder, self.export_sources_folder)
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
cmake_layout(self,src_folder="src")

def requirements(self):
if self.options.with_shm:
self.requires("iceoryx/2.0.0")
self.requires("iceoryx/2.0.2")
if self.options.with_ssl:
self.requires("openssl/1.1.1q")

def build_requirements(self):
self.tool_requires("cmake/3.21.7")
self.requires("openssl/1.1.1s")

def validate(self):
if self.options.enable_security and not self.options.shared:
raise ConanInvalidConfiguration(f"{self.ref} currently do not support"\
"static build and security on")
if self.info.settings.compiler.cppstd:
build.check_min_cppstd(self, 14)
minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False)
if minimum_version and scm.Version(self.info.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(f"{self.ref} is just tested with minimal version "\
f"{minimum_version} of compiler {self.info.settings.compiler}.")
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def _cmake_new_enough(self, required_version):
try:
import re
from io import StringIO
output = StringIO()
self.run("cmake --version", output=output)
m = re.search(r"cmake version (\d+\.\d+\.\d+)", output.getvalue())
return Version(m.group(1)) >= required_version
except:
return False

def source(self):
files.get(self,**self.conan_data["sources"][self.version], strip_root=True,
destination=self.source_folder)
def build_requirements(self):
if not self._cmake_new_enough("3.16"):
self.tool_requires("cmake/3.25.1")

def layout(self):
cmake_layout(self,src_folder="src")
def source(self):
get(self, self,**self.conan_data["sources"][self.version], strip_root=True)

def generate(self):

tc = CMakeToolchain(self)
# TODO : determine how to do in conan :
# - idlc is a code generator that is used as tool (and so not cross compiled)
# - other tools like ddsperf is cross compiled for target
# - maybe separate package like cyclonedds_idlc
tc.variables["BUILD_IDLC"] = False
tc.variables["BUILD_IDLC_TESTING"] = False
tc.variables["BUILD_DDSPERF"] = False
tc.variables["BUILD_IDLC_TESTING"] = False
tc.variables["BUILD_IDLC"] = False
tc.variables["BUILD_IDLC_TESTING"] = False
tc.variables["BUILD_DDSPERF"] = False
tc.variables["BUILD_IDLC_TESTING"] = False
# variables which effects build
tc.variables["ENABLE_SSL"] = self.options.with_ssl
tc.variables["ENABLE_SHM"] = self.options.with_shm
tc.variables["ENABLE_SECURITY"] = self.options.enable_security
tc.variables["ENABLE_SSL"] = self.options.with_ssl
tc.variables["ENABLE_SHM"] = self.options.with_shm
tc.variables["ENABLE_SECURITY"] = self.options.enable_security
tc.generate()

cd = CMakeDeps(self)
cd.generate()

def build(self):
files.apply_conandata_patches(self)
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()
files.copy(self, "LICENSE", self.source_folder, self._license_folder)
files.rmdir(self, os.path.join(self.package_folder, "share"))
files.rmdir(self, os.path.join(self.package_folder, "lib","pkgconfig"))
files.rmdir(self, os.path.join(self.package_folder, "lib","cmake"))

# cyclonedds copies multiple windows dlls to bin folder
# these must be removed and just keep ddsc.dll
if self.settings.os == "Windows":
if self.options.shared:
files.mkdir(self, self._tmp_folder)
files.copy(self, "ddsc.dll", self._bin_package_folder, self._tmp_folder)
files.rmdir(self, self._bin_package_folder)
if self.options.shared:
files.mkdir(self,self._bin_package_folder)
files.copy(self,"ddsc.dll",self._tmp_folder,self._bin_package_folder)
files.rmdir(self, self._tmp_folder)
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
if self.settings.os == "Windows" and self.options.shared:
for dll in ("concrt*.dll", "msvcp*.dll", "vcruntime*.dll"):
rm(self, dll, os.path.join(self.package_folder, "bin"))
else:
rmdir(self, os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "cyclonedds")
self.cpp_info.filenames["cmake_find_package"] = "cyclonedds"
self.cpp_info.filenames["cmake_find_package_multi"] = "cyclonedds"
self.cpp_info.names["cmake_find_package"] = "CycloneDDS"
self.cpp_info.names["cmake_find_package_multi"] = "CycloneDDS"
self.cpp_info.components["CycloneDDS"].names["cmake_find_package"] = "ddsc"
self.cpp_info.components["CycloneDDS"].names["cmake_find_package_multi"] = "ddsc"
self.cpp_info.set_property("cmake_file_name", "CycloneDDS")
self.cpp_info.set_property("cmake_target_name", "CycloneDDS::ddsc")
self.cpp_info.set_property("pkg_config_name", "CycloneDDS")
# TODO: back to global scope in conan v2
self.cpp_info.components["CycloneDDS"].libs = ["ddsc"]
self.cpp_info.components["CycloneDDS"].set_property("cmake_target_name",
"CycloneDDS::ddsc")
requires = []
if self.options.with_shm:
requires.append("iceoryx::iceoryx_binding_c")
Expand All @@ -177,3 +161,11 @@ def package_info(self):
"bcrypt",
"iphlpapi"
]

# TODO: to remove in conan v2
self.cpp_info.names["cmake_find_package"] = "CycloneDDS"
self.cpp_info.names["cmake_find_package_multi"] = "CycloneDDS"
self.cpp_info.components["CycloneDDS"].names["cmake_find_package"] = "ddsc"
self.cpp_info.components["CycloneDDS"].names["cmake_find_package_multi"] = "ddsc"
self.cpp_info.components["CycloneDDS"].set_property("cmake_target_name", "CycloneDDS::ddsc")
self.cpp_info.components["CycloneDDS"].set_property("pkg_config_name", "CycloneDDS")
2 changes: 1 addition & 1 deletion recipes/cyclonedds/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(cyclonedds REQUIRED CONFIG)
find_package(CycloneDDS REQUIRED CONFIG)

add_executable(test_package test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE CycloneDDS::ddsc)
Expand Down
11 changes: 4 additions & 7 deletions recipes/cyclonedds/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

find_package(cyclonedds CONFIG REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE CycloneDDS::ddsc)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
2 changes: 1 addition & 1 deletion recipes/cyclonedds/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from conans import ConanFile, CMake
from conan.tools import build

class CycloneDDSTestConan(ConanFile):
class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = ["cmake", "cmake_find_package_multi"]

Expand Down

0 comments on commit f594a04

Please sign in to comment.