diff --git a/recipes/baical-p7/all/CMakeLists.txt b/recipes/baical-p7/all/CMakeLists.txt deleted file mode 100644 index c921d02a0d877e..00000000000000 --- a/recipes/baical-p7/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory("source_subfolder") diff --git a/recipes/baical-p7/all/conandata.yml b/recipes/baical-p7/all/conandata.yml index f73e5ee20ebb0f..7bc581c0478355 100644 --- a/recipes/baical-p7/all/conandata.yml +++ b/recipes/baical-p7/all/conandata.yml @@ -2,3 +2,8 @@ sources: "5.6": url: "http://baical.net/files/libP7Client_v5.6.zip" sha256: "7503bdf739b9c2aea297b49fa0aa0162b7090830aee1cbd4cf7be5d3c75600de" +patches: + "5.6": + - patch_file: "patches/0001-fix-cmake.patch" + patch_description: "Fix CMakeLists" + patch_type: "conan" diff --git a/recipes/baical-p7/all/conanfile.py b/recipes/baical-p7/all/conanfile.py index 94fb1036053e3a..bbfbd1d561a269 100644 --- a/recipes/baical-p7/all/conanfile.py +++ b/recipes/baical-p7/all/conanfile.py @@ -1,8 +1,11 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get import os -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration -required_conan_version = ">=1.29.1" +required_conan_version = ">=1.53.0" + class BaicalP7Conan(ConanFile): name = "baical-p7" @@ -11,17 +14,19 @@ class BaicalP7Conan(ConanFile): homepage = "http://baical.net/p7.html" topics = ("p7", "baical", "logging", "telemetry") description = "Baical P7 client" - settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - exports_sources = "CMakeLists.txt" - generators = "cmake" - _cmake = None + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } - @property - def _source_subfolder(self): - return "source_subfolder" + def export_sources(self): + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -29,46 +34,39 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + + def validate(self): if self.settings.os not in ["Linux", "Windows"]: raise ConanInvalidConfiguration("P7 only supports Windows and Linux at this time") def source(self): - tools.get(**self.conan_data["sources"][self.version], destination= self._source_subfolder) + get(self, **self.conan_data["sources"][self.version]) - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - self._cmake.definitions["P7_TESTS_BUILD"] = False - self._cmake.definitions["P7_BUILD_SHARED"] = self.options.shared - self._cmake.definitions["P7_EXAMPLES_BUILD"] = False - self._cmake.configure() - return self._cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["P7_TESTS_BUILD"] = False + tc.cache_variables["P7_BUILD_SHARED"] = self.options.shared + tc.variables["P7_EXAMPLES_BUILD"] = False + tc.generate() def build(self): - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder) - self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "Headers")) - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - tools.remove_files_by_mask(os.path.join(self.package_folder, "include"), "*.cmake") def package_info(self): - self.cpp_info.names["cmake_find_package"] = "p7" - self.cpp_info.names["cmake_find_package_multi"] = "p7" - - if self.options.shared: - self.cpp_info.components["p7"].name = "p7-shared" - self.cpp_info.components["p7"].libs = ["p7-shared"] - else: - self.cpp_info.components["p7"].name = "p7" - self.cpp_info.components["p7"].libs = ["p7"] - - if self.settings.os == "Linux": - self.cpp_info.components["p7"].system_libs .extend(["rt", "pthread"]) - if self.settings.os == "Windows": - self.cpp_info.components["p7"].system_libs .append("Ws2_32") + self.cpp_info.libs = ["p7-shared" if self.options.shared else "p7"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.extend(["rt", "pthread"]) + elif self.settings.os == "Windows": + self.cpp_info.system_libs.append("ws2_32") diff --git a/recipes/baical-p7/all/patches/0001-fix-cmake.patch b/recipes/baical-p7/all/patches/0001-fix-cmake.patch new file mode 100644 index 00000000000000..dbedad975e252b --- /dev/null +++ b/recipes/baical-p7/all/patches/0001-fix-cmake.patch @@ -0,0 +1,86 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1,6 +1,6 @@ + cmake_minimum_required(VERSION 3.0 FATAL_ERROR) + +-#project(p7lib) ++project(p7lib) + + #>>Build options ********************************************************************** + option(P7_TESTS_BUILD "Build test" OFF) +@@ -25,7 +25,6 @@ if(NOT DEFINED ROOT_P7_PATH) + set(ROOT_P7_PATH ${PROJECT_SOURCE_DIR} CACHE INTERNAL "") + set(PATH_P7 ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") + set(PATH_P7_API "${PROJECT_SOURCE_DIR}/Headers" CACHE INTERNAL "") +-else(expression) + endif(NOT DEFINED ROOT_P7_PATH) + + if(MSVC) +--- a/Sources/CMakeLists.txt ++++ b/Sources/CMakeLists.txt +@@ -7,7 +7,7 @@ include_directories(${PATH_SHARED_PLATFORM}) + include_directories(${PATH_P7_API}) + + if(WIN32) +- set(P7_PLATFORM_LIBS Ws2_32) ++ set(P7_PLATFORM_LIBS ws2_32) + elseif(UNIX) + set(P7_PLATFORM_LIBS rt pthread) + else() +@@ -16,29 +16,38 @@ endif() + + aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} P7_SOURCES) + ++if(NOT P7_BUILD_SHARED) + add_library(${PROJECT_NAME} STATIC ${P7_SOURCES}) + target_link_libraries(${PROJECT_NAME} PUBLIC ${P7_PLATFORM_LIBS}) ++endif() + + if(P7_BUILD_SHARED) + add_library(${PROJECT_NAME}-shared SHARED ${P7_SOURCES}) + target_link_libraries(${PROJECT_NAME}-shared ${P7_PLATFORM_LIBS}) + endif() + ++if(NOT P7_BUILD_SHARED) + set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON) ++endif() + + if(P7_BUILD_SHARED) + set_property(TARGET ${PROJECT_NAME}-shared PROPERTY POSITION_INDEPENDENT_CODE ON) + endif() + + ++if(NOT P7_BUILD_SHARED) + target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/") ++endif() + if(P7_BUILD_SHARED) + target_include_directories(${PROJECT_NAME}-shared PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/") + endif() + ++if(NOT P7_BUILD_SHARED) + target_include_directories(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/../Headers/") + target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/") ++endif() + ++if(NOT P7_BUILD_SHARED) + if(WIN32) + target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../Shared/Platforms/Windows_x86/") + elseif(UNIX) +@@ -51,14 +60,15 @@ install(TARGETS ${PROJECT_NAME} + RUNTIME DESTINATION bin + ) + +-if(P7_BUILD_SHARED) ++else() + install(TARGETS ${PROJECT_NAME}-shared + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) + endif() ++install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../Headers/ DESTINATION include FILES_MATCHING PATTERN "*.h") + +-if(COMMAND set_ide_folder) ++if(0) + set_ide_folder(${PROJECT_NAME}) + if(P7_BUILD_SHARED) + set_ide_folder(${PROJECT_NAME}-shared) diff --git a/recipes/baical-p7/all/test_package/CMakeLists.txt b/recipes/baical-p7/all/test_package/CMakeLists.txt index bb7cd3a2818654..8eba5be9b5dc91 100644 --- a/recipes/baical-p7/all/test_package/CMakeLists.txt +++ b/recipes/baical-p7/all/test_package/CMakeLists.txt @@ -1,15 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package CXX) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -find_package(p7 REQUIRED CONFIG) +find_package(baical-p7 REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) - -if(P7_SHARED) - target_link_libraries(${PROJECT_NAME} p7::p7-shared) -else() - target_link_libraries(${PROJECT_NAME} p7::p7) -endif() +target_link_libraries(${PROJECT_NAME} PRIVATE baical-p7::baical-p7) diff --git a/recipes/baical-p7/all/test_package/conanfile.py b/recipes/baical-p7/all/test_package/conanfile.py index c7a27ceb10b4e9..98ab55852ad565 100644 --- a/recipes/baical-p7/all/test_package/conanfile.py +++ b/recipes/baical-p7/all/test_package/conanfile.py @@ -1,18 +1,26 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package_multi" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) - cmake.definitions["P7_SHARED"] = self.options["baical-p7"].shared cmake.configure() cmake.build() def test(self): - if not tools.cross_building(self.settings): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/baical-p7/all/test_v1_package/CMakeLists.txt b/recipes/baical-p7/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..0d20897301b68b --- /dev/null +++ b/recipes/baical-p7/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/baical-p7/all/test_v1_package/conanfile.py b/recipes/baical-p7/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..38f4483872d47f --- /dev/null +++ b/recipes/baical-p7/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)