diff --git a/recipes/minmea/all/conandata.yml b/recipes/minmea/all/conandata.yml new file mode 100644 index 0000000000000..f6a2a3a0d5950 --- /dev/null +++ b/recipes/minmea/all/conandata.yml @@ -0,0 +1,12 @@ +sources: + "0.3.0.cci.20230620": + url: "https://github.com/kosma/minmea/archive/e368d847d75abd891c651f7d30ce5efb6681adb7.tar.gz" + sha256: "9b845dfc7f4475c17710a0ac0823b11a6946df7b20dfacd02b03921826eeab3a" +patches: + "0.3.0.cci.20230620": + - patch_file: "patches/001-disable-pkgconfig-libcheck.patch" + patch_description: "Do not search for libcheck - Exclusive for testing" + patch_type: "conan" + - patch_file: "patches/002-windows-support.patch" + patch_description: "Manage compat header file for Windows" + patch_type: "portability" diff --git a/recipes/minmea/all/conanfile.py b/recipes/minmea/all/conanfile.py new file mode 100644 index 0000000000000..30eb575863037 --- /dev/null +++ b/recipes/minmea/all/conanfile.py @@ -0,0 +1,82 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import copy, get, apply_conandata_patches, export_conandata_patches +from conan.tools.microsoft import is_msvc +from conan.errors import ConanInvalidConfiguration +import os + +required_conan_version = ">=1.53.0" + +class MinmeaConan(ConanFile): + name = "minmea" + description = "a lightweight GPS NMEA 0183 parser library in pure C" + license = ("WTFPL", "MIT", "LGPL-3.0-or-later") + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/kosma/minmea" + topics = ("gps", "NMEA", "parser") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + 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 validate(self): + # INFO: Windows mingw supported: https://github.com/kosma/minmea?tab=readme-ov-file#compatibility + # INFO: MSVC fails with error C2011: 'timespec': 'struct' type redefinition + if is_msvc(self): + raise ConanInvalidConfiguration(f"{self.ref} can not be built on Visual Studio and msvc. Use mingw instead or similar.") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + if self.settings.os == "Windows": + tc.preprocessor_definitions["MINMEA_INCLUDE_COMPAT"] = "1" + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build(target="minmea") + + def package(self): + copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "LICENSE.*", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy(self, "minmea.h", self.source_folder, os.path.join(self.package_folder, "include")) + copy(self, "libminmea.a", self.build_folder, os.path.join(self.package_folder, "lib")) + copy(self, "libminmea.so", self.build_folder, os.path.join(self.package_folder, "lib")) + copy(self, "libminmea.dylib", self.build_folder, os.path.join(self.package_folder, "lib")) + if self.settings.os == "Windows": + copy(self, "libminmea.dll.a", self.build_folder, os.path.join(self.package_folder, "lib")) + copy(self, "libminmea.dll", self.build_folder, os.path.join(self.package_folder, "bin")) + copy(self, "minmea_compat.h", self.source_folder, os.path.join(self.package_folder, "include")) + + def package_info(self): + self.cpp_info.libs = ["minmea"] + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs = ["m"] + if self.settings.os == "Windows": + self.cpp_info.defines = ["MINMEA_INCLUDE_COMPAT=1"] diff --git a/recipes/minmea/all/patches/001-disable-pkgconfig-libcheck.patch b/recipes/minmea/all/patches/001-disable-pkgconfig-libcheck.patch new file mode 100644 index 0000000000000..7e3f4636a811b --- /dev/null +++ b/recipes/minmea/all/patches/001-disable-pkgconfig-libcheck.patch @@ -0,0 +1,12 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b96e1d7..4674f49 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,7 +6,6 @@ project(minmea) + + find_package(Threads REQUIRED) # Workaround for https://github.com/libcheck/check/issues/48#issuecomment-322965461 + find_package(PkgConfig) +-pkg_check_modules(CHECK REQUIRED check) + link_directories(${CHECK_LIBRARY_DIRS}) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -Werror -std=c99") diff --git a/recipes/minmea/all/patches/002-windows-support.patch b/recipes/minmea/all/patches/002-windows-support.patch new file mode 100644 index 0000000000000..8f7360ca6288d --- /dev/null +++ b/recipes/minmea/all/patches/002-windows-support.patch @@ -0,0 +1,16 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4674f49..895b835 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -13,6 +13,11 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -D_D + + set(minmea_SRCS minmea.c minmea.h) + add_library(minmea ${minmea_SRCS}) ++target_include_directories(minmea PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) ++if (WIN32) ++ configure_file(compat/minmea_compat_windows.h ${CMAKE_CURRENT_SOURCE_DIR}/minmea_compat.h COPYONLY) ++ target_compile_definitions(minmea PRIVATE MINMEA_INCLUDE_COMPAT) ++endif() + + add_executable(example example.c) + target_link_libraries(example minmea) diff --git a/recipes/minmea/all/test_package/CMakeLists.txt b/recipes/minmea/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..62bf6147b6fb5 --- /dev/null +++ b/recipes/minmea/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(minmea REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE minmea::minmea) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_99) diff --git a/recipes/minmea/all/test_package/conanfile.py b/recipes/minmea/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ef5d7042163ec --- /dev/null +++ b/recipes/minmea/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/minmea/all/test_package/test_package.c b/recipes/minmea/all/test_package/test_package.c new file mode 100644 index 0000000000000..9c222e438c9ae --- /dev/null +++ b/recipes/minmea/all/test_package/test_package.c @@ -0,0 +1,16 @@ +#include +#include "minmea.h" + + +int main(void) { + char* nmea_data = "$GPGGA,155246.585,5231.171,N,01321.830,E,1,12,1.0,0.0,M,0.0,M,,*6F"; + + if (minmea_sentence_id(nmea_data, false) == MINMEA_SENTENCE_GGA) { + struct minmea_sentence_gga frame; + if (minmea_parse_gga(&frame, nmea_data)) { + printf("$GGA: fix quality: %d\n", frame.fix_quality); + } + } + + return 0; +} diff --git a/recipes/minmea/config.yml b/recipes/minmea/config.yml new file mode 100644 index 0000000000000..85c5d6a070371 --- /dev/null +++ b/recipes/minmea/config.yml @@ -0,0 +1,3 @@ +versions: + "0.3.0.cci.20230620": + folder: all