This is an automated email from the ASF dual-hosted git repository.

pengzheng pushed a commit to branch feature/483-conan-2-support
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/483-conan-2-support by 
this push:
     new 60b59416 Drop generators unsupported by Conan 2.0
60b59416 is described below

commit 60b59416568f5143666cd6b9fc910586b8ad9649
Author: PengZheng <howto...@gmail.com>
AuthorDate: Sun Aug 20 13:47:07 2023 +0800

    Drop generators unsupported by Conan 2.0
    
    Drop generators unsupported by Conan 2.0
---
 .../discovery_configured/CMakeLists.txt            |  2 +-
 bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt     |  2 +-
 cmake/Modules/FindCppUTest.cmake                   | 12 ++---
 cmake/Modules/FindRapidJSON.cmake                  |  6 +--
 cmake/Modules/FindZeroMQ.cmake                     |  6 +--
 cmake/Modules/Findczmq.cmake                       |  8 ++--
 cmake/Modules/Findlibzip.cmake                     |  6 +--
 conanfile.py                                       | 55 ++++++++++++----------
 libs/utils/CMakeLists.txt                          | 16 +++----
 libs/utils/error_injector/zip/CMakeLists.txt       |  2 +-
 libs/utils/gtest/CMakeLists.txt                    |  2 +-
 11 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/bundles/cxx_remote_services/discovery_configured/CMakeLists.txt 
b/bundles/cxx_remote_services/discovery_configured/CMakeLists.txt
index 7be03970..aa894eb3 100644
--- a/bundles/cxx_remote_services/discovery_configured/CMakeLists.txt
+++ b/bundles/cxx_remote_services/discovery_configured/CMakeLists.txt
@@ -38,7 +38,7 @@ target_link_libraries(RsaConfiguredDiscovery PRIVATE
         Celix::framework
         Celix::rsa_spi
         Celix::log_helper
-        RapidJSON::RapidJSON
+        rapidjson
 )
 
 target_include_directories(RsaConfiguredDiscovery PRIVATE src)
diff --git a/bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt 
b/bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt
index 1d611951..9428a8be 100644
--- a/bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt
+++ b/bundles/pubsub/pubsub_admin_zmq/CMakeLists.txt
@@ -47,7 +47,7 @@ if (PUBSUB_PSA_ZMQ)
             )
 
     target_link_libraries(celix_pubsub_admin_zmq PRIVATE
-            Celix::log_helper ZeroMQ::ZeroMQ czmq::czmq libuuid::libuuid 
${OPTIONAL_OPENSSL_LIB})
+            Celix::log_helper libzmq czmq libuuid::libuuid 
${OPTIONAL_OPENSSL_LIB})
     target_link_libraries(celix_pubsub_admin_zmq PRIVATE Celix::shell_api)
     target_link_libraries(celix_pubsub_admin_zmq PRIVATE Celix::pubsub_spi 
Celix::pubsub_utils)
     target_include_directories(celix_pubsub_admin_zmq PRIVATE src)
diff --git a/cmake/Modules/FindCppUTest.cmake b/cmake/Modules/FindCppUTest.cmake
index 26d14514..8b4c54e0 100644
--- a/cmake/Modules/FindCppUTest.cmake
+++ b/cmake/Modules/FindCppUTest.cmake
@@ -44,18 +44,18 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(CppUTest DEFAULT_MSG 
CppUTest_LIBRARY CppUTest
 IF(CppUTest_FOUND)
     SET(CppUTest_LIBRARIES ${CppUTest_LIBRARY})
     SET(CppUTest_INCLUDE_DIRS ${CppUTest_INCLUDE_DIR})
-    if(NOT TARGET CppUTest::CppUTest)
-        add_library(CppUTest::CppUTest STATIC IMPORTED)
-        set_target_properties(CppUTest::CppUTest PROPERTIES
+    if(NOT TARGET CppUTest)
+        add_library(CppUTest STATIC IMPORTED)
+        set_target_properties(CppUTest PROPERTIES
                 IMPORTED_LOCATION "${CppUTest_LIBRARY}"
                 INTERFACE_INCLUDE_DIRECTORIES "${CppUTest_INCLUDE_DIR}"
                 )
     endif()
     SET(CppUTest_EXT_LIBRARIES ${CppUTest_EXT_LIBRARY})
     SET(CppUTest_EXT_INCLUDE_DIRS ${CppUTest_EXT_INCLUDE_DIR})
-    if(NOT TARGET CppUTest::CppUTestExt)
-        add_library(CppUTest::CppUTestExt STATIC IMPORTED)
-        set_target_properties(CppUTest::CppUTestExt PROPERTIES
+    if(NOT TARGET CppUTestExt)
+        add_library(CppUTestExt STATIC IMPORTED)
+        set_target_properties(CppUTestExt PROPERTIES
                 IMPORTED_LOCATION "${CppUTest_EXT_LIBRARY}"
                 INTERFACE_INCLUDE_DIRECTORIES "${CppUTest_EXT_INCLUDE_DIR}"
                 )
diff --git a/cmake/Modules/FindRapidJSON.cmake 
b/cmake/Modules/FindRapidJSON.cmake
index b31f0b2d..083d9c41 100644
--- a/cmake/Modules/FindRapidJSON.cmake
+++ b/cmake/Modules/FindRapidJSON.cmake
@@ -28,8 +28,8 @@ find_package_handle_standard_args(RapidJSON DEFAULT_MSG
 
 mark_as_advanced(RapidJSON_INCLUDE_DIR)
 
-if(RapidJSON_FOUND AND NOT TARGET RapidJSON::RapidJSON)
-    add_library(RapidJSON::RapidJSON INTERFACE IMPORTED)
-    set_target_properties(RapidJSON::RapidJSON PROPERTIES 
INTERFACE_INCLUDE_DIRECTORIES
+if(RapidJSON_FOUND AND NOT TARGET rapidjson)
+    add_library(rapidjson INTERFACE IMPORTED)
+    set_target_properties(rapidjson PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
             "${RapidJSON_INCLUDE_DIRS}")
 endif()
diff --git a/cmake/Modules/FindZeroMQ.cmake b/cmake/Modules/FindZeroMQ.cmake
index ca0f5d52..e6f5d021 100644
--- a/cmake/Modules/FindZeroMQ.cmake
+++ b/cmake/Modules/FindZeroMQ.cmake
@@ -42,9 +42,9 @@ find_package_handle_standard_args(ZeroMQ  DEFAULT_MSG
 
 mark_as_advanced(ZEROMQ_INCLUDE_DIR ZEROMQ_LIBRARY )
 
-if (ZeroMQ_FOUND AND NOT TARGET ZeroMQ::ZeroMQ)
-    add_library(ZeroMQ::ZeroMQ SHARED IMPORTED)
-    set_target_properties(ZeroMQ::ZeroMQ PROPERTIES
+if (ZeroMQ_FOUND AND NOT TARGET libzmq)
+    add_library(libzmq SHARED IMPORTED)
+    set_target_properties(libzmq PROPERTIES
             IMPORTED_LOCATION "${ZEROMQ_LIBRARY}"
             INTERFACE_INCLUDE_DIRECTORIES "${ZEROMQ_INCLUDE_DIR}"
     )
diff --git a/cmake/Modules/Findczmq.cmake b/cmake/Modules/Findczmq.cmake
index 2cc5a05a..8a3edf5b 100644
--- a/cmake/Modules/Findczmq.cmake
+++ b/cmake/Modules/Findczmq.cmake
@@ -22,7 +22,7 @@
 #  CZMQ_INCLUDE_DIRS - The czmq include directories
 #  CZMQ_LIBRARIES - The libraries needed to use czmq
 #  CZMQ_DEFINITIONS - Compiler switches required for using czmq
-#  czmq::czmq - Imported CMake target for the library (include path + library)
+#  czmq - Imported CMake target for the library (include path + library)
 
 find_path(CZMQ_INCLUDE_DIR czmq.h
           /usr/include
@@ -42,9 +42,9 @@ find_package_handle_standard_args(czmq  DEFAULT_MSG
 
 mark_as_advanced(CZMQ_INCLUDE_DIR CZMQ_LIBRARY)
 
-if (czmq_FOUND AND NOT TARGET czmq::czmq)
-    add_library(czmq::czmq SHARED IMPORTED)
-    set_target_properties(czmq::czmq PROPERTIES
+if (czmq_FOUND AND NOT TARGET czmq)
+    add_library(czmq SHARED IMPORTED)
+    set_target_properties(czmq PROPERTIES
             IMPORTED_LOCATION "${CZMQ_LIBRARY}"
             INTERFACE_INCLUDE_DIRECTORIES "${CZMQ_INCLUDE_DIR}"
     )
diff --git a/cmake/Modules/Findlibzip.cmake b/cmake/Modules/Findlibzip.cmake
index 0d67aee4..5cf2725c 100644
--- a/cmake/Modules/Findlibzip.cmake
+++ b/cmake/Modules/Findlibzip.cmake
@@ -37,9 +37,9 @@ include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(libzip  DEFAULT_MSG
         LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR)
 
-if(libzip_FOUND AND NOT TARGET libzip::libzip)
-    add_library(libzip::libzip IMPORTED STATIC GLOBAL)
-    set_target_properties(libzip::libzip PROPERTIES
+if(libzip_FOUND AND NOT TARGET libzip::zip)
+    add_library(libzip::zip IMPORTED STATIC GLOBAL)
+    set_target_properties(libzip::zip PROPERTIES
             IMPORTED_LOCATION "${LIBZIP_LIBRARY}"
             INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_INCLUDE_DIR}"
     )
diff --git a/conanfile.py b/conanfile.py
index 622a34a0..a98a4294 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -15,8 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
-from conans import ConanFile, CMake, tools
-from conans.errors import ConanInvalidConfiguration
+from conan import ConanFile, tools
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain
+from conan.tools.scm import Version
 import os
 
 
@@ -30,14 +32,14 @@ class CelixConan(ConanFile):
     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", "virtualrunenv"
+    generators = "CMakeDeps", "VirtualRunEnv"
     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."
 
-    options = {
+    _celix_options = {
         "enable_testing": [True, False],
         "enable_code_coverage": [True, False],
         "enable_address_sanitizer": [True, False],
@@ -97,11 +99,13 @@ class CelixConan(ConanFile):
         "celix_cxx17": [True, False],
         "celix_install_deprecated_api": [True, False],
         "celix_use_compression_for_bundle_zips": [True, False],
-        "celix_err_buffer_size": "ANY",
+        "celix_err_buffer_size": ["ANY"],
         "enable_cmake_warning_tests": [True, False],
         "enable_testing_on_ci": [True, False],
         "framework_curlinit": [True, False],
     }
+
+    options = _celix_options
     default_options = {
         "enable_testing": False,
         "enable_code_coverage": False,
@@ -209,7 +213,7 @@ class CelixConan(ConanFile):
 
     def configure(self):
         if self.options.build_all:
-            for opt, val in self.options.values.items():
+            for opt in self._celix_options.keys():
                 if opt.startswith('build_'):
                     setattr(self.options, opt, True)
 
@@ -427,29 +431,32 @@ class CelixConan(ConanFile):
             self.requires("mdnsresponder/1310.140.1")
         self.validate()
 
-    def _enable_error_injectors(self):
-        for k in self.deps_cpp_info.deps:
-            if k == "mdnsresponder":
-                self._cmake.definitions["BUILD_ERROR_INJECTOR_MDNSRESPONDER"] 
= "ON"
+    def generate(self):
+        tc = CMakeToolchain(self)
+        for opt in self._celix_options.keys():
+            tc.cache_variables[opt.upper()] = self.options.get_safe(opt, False)
+        if self.options.enable_testing:
+            for k in self.deps_cpp_info.deps:
+                if k == "mdnsresponder":
+                    tc.cache_variables["BUILD_ERROR_INJECTOR_MDNSRESPONDER"] = 
"ON"
+        tc.cache_variables["CELIX_ERR_BUFFER_SIZE"] = 
self.options.celix_err_buffer_size
+        # tc.cache_variables["CMAKE_PROJECT_Celix_INCLUDE"] = 
os.path.join(self.build_folder, "conan_paths.cmake")
+        # the following is workaround for 
https://github.com/conan-io/conan/issues/7192
+        if self.settings.os == "Linux":
+            tc.cache_variables["CMAKE_EXE_LINKER_FLAGS"] = 
"-Wl,--unresolved-symbols=ignore-in-shared-libs"
+        elif self.settings.os == "Macos":
+            tc.cache_variables["CMAKE_EXE_LINKER_FLAGS"] = "-Wl,-undefined 
-Wl,dynamic_lookup"
+        v = Version(self.version)
+        tc.cache_variables["CELIX_MAJOR"] = v.major.value
+        tc.cache_variables["CELIX_MINOR"] = v.minor.value
+        tc.cache_variables["CELIX_MICRO"] = v.patch.value
+        tc.generate()
 
     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)
-        if self.options.enable_testing:
-            self._enable_error_injectors()
-        self._cmake.definitions["CELIX_ERR_BUFFER_SIZE"] = 
self.options.celix_err_buffer_size
-        self._cmake.definitions["CMAKE_PROJECT_Celix_INCLUDE"] = 
os.path.join(self.build_folder, "conan_paths.cmake")
-        # the following is workaround for 
https://github.com/conan-io/conan/issues/7192
-        if self.settings.os == "Linux":
-            self._cmake.definitions["CMAKE_EXE_LINKER_FLAGS"] = 
"-Wl,--unresolved-symbols=ignore-in-shared-libs"
-        elif self.settings.os == "Macos":
-            self._cmake.definitions["CMAKE_EXE_LINKER_FLAGS"] = 
"-Wl,-undefined -Wl,dynamic_lookup"
-        self.output.info(self._cmake.definitions)
-        v = tools.Version(self.version)
-        self._cmake.configure(defs={'CELIX_MAJOR': v.major, 'CELIX_MINOR': 
v.minor, 'CELIX_MICRO': v.patch})
+        self._cmake.configure()
         return self._cmake
 
     def build(self):
diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt
index d22ebae7..9ee10c32 100644
--- a/libs/utils/CMakeLists.txt
+++ b/libs/utils/CMakeLists.txt
@@ -52,7 +52,7 @@ if (UTILS)
             src/celix_cleanup.c
             ${MEMSTREAM_SOURCES}
             )
-    set(UTILS_PRIVATE_DEPS libzip::libzip)
+    set(UTILS_PRIVATE_DEPS libzip::zip)
     set(UTILS_PUBLIC_DEPS)
 
     add_library(utils SHARED ${UTILS_SRC})
@@ -140,33 +140,33 @@ if (UTILS)
 
             add_executable(hash_map_test private/test/hash_map_test.cpp)
             target_include_directories(hash_map_test PRIVATE 
include_deprecated)
-            target_link_libraries(hash_map_test utils_cut CppUTest::CppUTest 
pthread)
+            target_link_libraries(hash_map_test utils_cut CppUTest pthread)
 
             add_executable(array_list_test private/test/array_list_test.cpp)
             target_include_directories(array_list_test PRIVATE 
include_deprecated)
-            target_link_libraries(array_list_test utils_cut CppUTest::CppUTest 
pthread)
+            target_link_libraries(array_list_test utils_cut CppUTest pthread)
 
             add_executable(linked_list_test private/test/linked_list_test.cpp)
             target_include_directories(linked_list_test PRIVATE 
include_deprecated)
-            target_link_libraries(linked_list_test utils_cut 
CppUTest::CppUTest pthread)
+            target_link_libraries(linked_list_test utils_cut CppUTest pthread)
 
             add_executable(properties_test private/test/properties_test.cpp)
             target_include_directories(properties_test PRIVATE 
include_deprecated)
-            target_link_libraries(properties_test CppUTest::CppUTest 
CppUTest::CppUTestExt utils_cut pthread)
+            target_link_libraries(properties_test CppUTest CppUTestExt 
utils_cut pthread)
 
             add_executable(ip_utils_test private/test/ip_utils_test.cpp)
             target_include_directories(ip_utils_test PRIVATE 
include_deprecated)
-            target_link_libraries(ip_utils_test CppUTest::CppUTest  utils_cut 
pthread)
+            target_link_libraries(ip_utils_test CppUTest  utils_cut pthread)
 
             add_executable(version_test private/test/version_test.cpp)
             target_include_directories(version_test PRIVATE include_deprecated)
-            target_link_libraries(version_test CppUTest::CppUTest utils_cut 
pthread)
+            target_link_libraries(version_test CppUTest utils_cut pthread)
 
 
             if (LINKER_WRAP_SUPPORTED)
                 add_executable(version_ei_test private/test/version_ei_test.cc)
                 target_include_directories(version_ei_test PRIVATE 
include_deprecated)
-                target_link_libraries(version_ei_test CppUTest::CppUTest 
utils_cut Celix::malloc_ei Celix::utils_ei pthread)
+                target_link_libraries(version_ei_test CppUTest utils_cut 
Celix::malloc_ei Celix::utils_ei pthread)
                 add_test(NAME version_ei_test COMMAND version_ei_test)
             endif ()
 
diff --git a/libs/utils/error_injector/zip/CMakeLists.txt 
b/libs/utils/error_injector/zip/CMakeLists.txt
index 85873756..f07c2436 100644
--- a/libs/utils/error_injector/zip/CMakeLists.txt
+++ b/libs/utils/error_injector/zip/CMakeLists.txt
@@ -19,7 +19,7 @@ find_package(libzip REQUIRED)
 add_library(zip_ei STATIC src/zip_ei.cc)
 
 target_include_directories(zip_ei PUBLIC include)
-target_link_libraries(zip_ei PUBLIC Celix::error_injector libzip::libzip)
+target_link_libraries(zip_ei PUBLIC Celix::error_injector libzip::zip)
 # It plays nicely with address sanitizer this way.
 
 target_link_options(zip_ei INTERFACE
diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt
index f4c776cc..3ff391bd 100644
--- a/libs/utils/gtest/CMakeLists.txt
+++ b/libs/utils/gtest/CMakeLists.txt
@@ -41,7 +41,7 @@ add_executable(test_utils
         ${CELIX_UTIL_TEST_SOURCES_FOR_CXX_HEADERS}
 )
 
-target_link_libraries(test_utils PRIVATE utils_cut Celix::utils GTest::gtest 
GTest::gtest_main libzip::libzip)
+target_link_libraries(test_utils PRIVATE utils_cut Celix::utils GTest::gtest 
GTest::gtest_main libzip::zip)
 target_include_directories(test_utils PRIVATE ../src) #for version_private 
(needs refactoring of test)
 celix_deprecated_utils_headers(test_utils)
 

Reply via email to