You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pe...@apache.org on 2022/03/04 04:54:35 UTC
[celix] 05/05: Add initial conan support.
This is an automated email from the ASF dual-hosted git repository.
pengzheng pushed a commit to branch feature/conan_support
in repository https://gitbox.apache.org/repos/asf/celix.git
commit 1bbaba1c8cfdea74b244c243978c63d3e0f30b5a
Author: PengZheng <ho...@gmail.com>
AuthorDate: Fri Mar 4 12:51:03 2022 +0800
Add initial conan support.
There are still some rough edges in CMake in-project dependency management.
---
CMakeLists.txt | 8 +-
bundles/cxx_remote_services/CMakeLists.txt | 2 +-
conanfile.py | 182 +++++++++++++++++++++++++++++
examples/CMakeLists.txt | 1 -
libs/CMakeLists.txt | 4 +-
libs/utils/CMakeLists.txt | 2 +-
6 files changed, 193 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index deea4e5..599ba2c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -72,8 +72,12 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- set(CMAKE_C_FLAGS "-Wno-unused-result -Wno-format-truncation -Wno-stringop-overflow ${CMAKE_C_FLAGS}")
- set(CMAKE_CXX_FLAGS "-Wno-unused-result -Wno-format-truncation -Wno-stringop-overflow ${CMAKE_CXX_FLAGS}")
+ set(CMAKE_C_FLAGS "-Wno-unused-result ${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS "-Wno-unused-result ${CMAKE_CXX_FLAGS}")
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
+ set(CMAKE_C_FLAGS "-Wno-format-truncation -Wno-stringop-overflow ${CMAKE_C_FLAGS}")
+ set(CMAKE_CXX_FLAGS "-Wno-format-truncation -Wno-stringop-overflow ${CMAKE_CXX_FLAGS}")
+ endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
set(CMAKE_C_FLAGS "-Wno-stringop-truncation ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wno-stringop-truncation ${CMAKE_CXX_FLAGS}")
diff --git a/bundles/cxx_remote_services/CMakeLists.txt b/bundles/cxx_remote_services/CMakeLists.txt
index ac98684..1fde6fd 100644
--- a/bundles/cxx_remote_services/CMakeLists.txt
+++ b/bundles/cxx_remote_services/CMakeLists.txt
@@ -16,7 +16,7 @@
# under the License.
celix_subproject(REMOTE_SERVICE_ADMIN "Option to enable building the C++17 Remote Service Admin Service bundles" OFF)
-if (REMOTE_SERVICE_ADMIN)
+if (REMOTE_SERVICE_ADMIN AND CELIX_CXX)
message(STATUS "The C++ Remote Service Admin is still experimental; The API, SPI and implementation is not stable and will change")
add_subdirectory(rsa_spi)
diff --git a/conanfile.py b/conanfile.py
new file mode 100644
index 0000000..7657aea
--- /dev/null
+++ b/conanfile.py
@@ -0,0 +1,182 @@
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanException, ConanInvalidConfiguration
+import os
+
+
+required_conan_version = ">=1.32.0"
+
+
+class CelixConan(ConanFile):
+ name = "celix"
+ homepage = "https://celix.apache.org"
+ url = "https://github.com/apache/celix.git"
+ topics = ("conan", "celix", "osgi", "embedded", "linux", "C/C++")
+ exports_sources = "CMakeLists.txt", "bundles*", "cmake*", "!cmake-build*", "examples*", "libs*", "misc*", "LICENSE"
+ generators = "cmake_paths", "cmake_find_package"
+ settings = "os", "arch", "compiler", "build_type"
+ license = " Apache-2.0"
+ description = "Apache Celix is an implementation of the OSGi specification adapted to C and C++ (C++17). " \
+ "It is a framework to develop (dynamic) modular software applications " \
+ "using component and/or service-oriented programming."
+ # TODO: update according to latest codes
+ options = {
+ "enable_testing": [True, False],
+ "enable_address_sanitizer": [True, False],
+ "enable_undefined_sanitizer": [True, False],
+ "enable_code_coverage": [True, False],
+ "celix_add_openssl_dep": [True, False],
+ "build_deployment_admin": [True, False],
+ "build_device_access_example": [True, False],
+ "build_device_access": [True, False],
+ "build_http_admin": [True, False],
+ "build_log_service": [True, False],
+ "build_log_writer": [True, False],
+ "build_log_writer_syslog": [True, False],
+ "build_pubsub": [True, False],
+ "build_pubsub_psa_zmq": [True, False],
+ "build_zmq_security": [True, False],
+ "build_pubsub_tests": [True, False],
+ "build_remote_service_admin": [True, False],
+ "build_rsa_remote_service_admin_dfi": [True, False],
+ "build_rsa_discovery_configured": [True, False],
+ "build_rsa_discovery_etcd": [True, False],
+ "build_rsa_discovery_shm": [True, False],
+ "build_rsa_topology_manager": [True, False],
+ "build_rsa_examples": [True, False],
+ "build_shell": [True, False],
+ "build_remote_shell": [True, False],
+ "build_shell_bonjour": [True, False],
+ "build_shell_tui": [True, False],
+ "build_shell_wui": [True, False],
+ "build_examples": [True, False],
+ "build_launcher": [True, False],
+ "build_event_admin": [True, False],
+ "build_experimental": [True, False],
+ "celix_cxx": [True, False],
+ }
+ default_options = {
+ "enable_testing": False,
+ "enable_address_sanitizer": False,
+ "enable_undefined_sanitizer": False,
+ "enable_code_coverage": False,
+ "celix_add_openssl_dep": False,
+ "build_deployment_admin": False,
+ "build_device_access": True,
+ "build_device_access_example": False,
+ "build_http_admin": True,
+ "build_log_service": True,
+ "build_log_writer": True,
+ "build_log_writer_syslog": True,
+ "build_pubsub": True,
+ "build_pubsub_psa_zmq": False,
+ "build_zmq_security": False,
+ "build_pubsub_tests": False,
+ "build_remote_service_admin": True,
+ "build_rsa_remote_service_admin_dfi": True,
+ "build_rsa_discovery_configured": True,
+ "build_rsa_discovery_etcd": True,
+ "build_rsa_discovery_shm": False,
+ "build_rsa_topology_manager": True,
+ "build_rsa_examples": True,
+ "build_shell": True,
+ "build_remote_shell": True,
+ "build_shell_bonjour": False,
+ "build_shell_tui": True,
+ "build_shell_wui": False,
+ "build_examples": True,
+ "build_launcher": True,
+ "build_event_admin": False,
+ "build_experimental": False,
+ "celix_cxx": False,
+ }
+ _cmake = None
+
+ def validate(self):
+ if self.settings.os != "Linux" and self.settings.os != "Macos":
+ raise ConanInvalidConfiguration("Library MyLib is only supported for Linux")
+
+ def configure(self):
+ if not self.options.enable_testing:
+ self.options.build_pubsub_tests = False;
+ if not self.options.build_device_access:
+ self.options.build_device_access_example = False
+ if not self.options.build_log_writer:
+ self.options.build_log_writer_syslog = False
+ if not self.options.build_pubsub:
+ self.options.build_pubsub_psa_zmq = False
+ if not self.options.build_pubsub_psa_zmq:
+ self.options.build_zmq_security = False
+ if not self.options.build_remote_service_admin:
+ self.options.build_rsa_remote_service_admin_dfi = False
+ self.options.build_rsa_discovery_configured = False
+ self.options.build_rsa_discovery_etcd = False
+ self.options.build_rsa_discovery_shm = False
+ self.options.build_rsa_topology_manager = False
+ self.options.build_rsa_examples = False
+ if not self.options.build_shell:
+ self.options.build_remote_shell = False
+ self.options.build_shell_bonjour = False
+ self.options.build_shell_tui = False
+ self.options.build_shell_wui = False
+ if not self.options.build_experimental:
+ self.options.build_event_admin = False
+
+ def requirements(self):
+ # libffi/3.3@zhengpeng/testing is a workaround of the following buggy commit:
+ # https://github.com/conan-io/conan-center-index/pull/5085#issuecomment-847487808
+ #self.requires("libffi/3.3@zhengpeng/testing")
+ self.requires("libffi/[~3.2.1]")
+ self.requires("jansson/[~2.12]")
+ self.requires("libcurl/[~7.64.1]")
+ self.requires("zlib/[~1.2.8]")
+ self.requires("libuuid/1.0.3")
+ self.requires("libzip/1.8.0")
+ self.options['libffi'].shared = True
+ self.options['jansson'].shared = True
+ self.options['libcurl'].shared = True
+ self.options['zlib'].shared = True
+ self.options['libuuid'].shared = True
+ self.options['libzip'].shared = True
+ self.options['openssl'].shared = True
+ self.options['libxml2'].shared = True
+ if self.options.enable_testing:
+ self.requires("gtest/1.10.0")
+ self.requires("cpputest/4.0")
+ if self.options.celix_add_openssl_dep or self.options.build_zmq_security:
+ self.requires("openssl/1.1.1k")
+ if self.options.build_remote_service_admin or self.options.build_shell_bonjour:
+ self.requires("libxml2/[~2.9.9]")
+ if self.options.build_pubsub_psa_zmq:
+ self.requires("zeromq/4.3.2")
+ self.options['zeromq'].shared = True
+ self.requires("czmq/4.2.0")
+ self.options['czmq'].shared = True
+
+ def _configure_cmake(self):
+ if self._cmake:
+ return self._cmake
+ self._cmake = CMake(self)
+ for opt, val in self.options.values.items():
+ self._cmake.definitions[opt.upper()] = self.options.get_safe(opt, False)
+ self._cmake.definitions["CMAKE_PROJECT_Celix_INCLUDE"] = os.path.join(self.build_folder, "conan_paths.cmake")
+ self.output.info(self._cmake.definitions)
+ self._cmake.configure()
+ return self._cmake
+
+ def build(self):
+ # self._patch_sources()
+ cmake = self._configure_cmake()
+ cmake.build()
+
+ def package(self):
+ self.copy("LICENSE", dst="licenses", src=self.source_folder)
+ cmake = self._configure_cmake()
+ cmake.install()
+ # tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
+
+ def package_info(self):
+ self.cpp_info.builddirs = [os.path.join("share", self.name, "cmake")];
+ self.cpp_info.bindirs = ["bin", os.path.join("share", self.name, "bundles")]
+ self.cpp_info.build_modules["cmake"].append(os.path.join("share", self.name, "cmake", "cmake_celix", "UseCelix.cmake"))
+ self.cpp_info.build_modules["cmake"].append(os.path.join("share", self.name, "cmake", "Targets.cmake"))
+ self.cpp_info.build_modules["cmake"].append(os.path.join("share", self.name, "cmake", "CelixTargets.cmake"))
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 0dfaf7a..89884f9 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -32,6 +32,5 @@ cmake_policy(SET CMP0068 NEW)
project (CelixUse C CXX)
set(CMAKE_C_FLAGS "-D_GNU_SOURCE -std=gnu99 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_STANDARD 17)
-set(CELIX_CXX ON CACHE BOOL "C++ on")
find_package(Celix REQUIRED)
add_subdirectory(celix-examples examples)
diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt
index 88ddcfa..8238864 100644
--- a/libs/CMakeLists.txt
+++ b/libs/CMakeLists.txt
@@ -30,4 +30,6 @@ add_subdirectory(launcher)
#add_subdirectory(event_admin)# event_admin is unstable
add_subdirectory(dependency_manager)
-add_subdirectory(dependency_manager_cxx)
+if (CELIX_CXX)
+ add_subdirectory(dependency_manager_cxx)
+endif ()
diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt
index a7b5710..f394520 100644
--- a/libs/utils/CMakeLists.txt
+++ b/libs/utils/CMakeLists.txt
@@ -45,7 +45,7 @@ add_library(utils SHARED
${MEMSTREAM_SOURCES}
)
set_target_properties(utils PROPERTIES OUTPUT_NAME "celix_utils")
-target_link_libraries(utils PRIVATE libzip::libzip)
+target_link_libraries(utils PUBLIC libzip::libzip)
if (NOT OPEN_MEMSTREAM_EXISTS)
target_compile_definitions(utils PUBLIC -DNO_MEMSTREAM_AVAILABLE)