Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minmea: add new recipe #24546

Merged
merged 13 commits into from
Sep 12, 2024
13 changes: 13 additions & 0 deletions recipes/minmea/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.4)
project(wrapper LANGUAGES CXX)

add_subdirectory(${MINMEA_SRC_DIR})

include(GNUInstallDirs)

install(TARGETS minmea
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES ${MINMEA_SRC_DIR}/minmea.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
9 changes: 9 additions & 0 deletions recipes/minmea/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"cci.20230620":
toge marked this conversation as resolved.
Show resolved Hide resolved
url: "https://github.com/kosma/minmea/archive/e368d847d75abd891c651f7d30ce5efb6681adb7.tar.gz"
sha256: "9b845dfc7f4475c17710a0ac0823b11a6946df7b20dfacd02b03921826eeab3a"
patches:
"cci.20230620":
- patch_file: "patches/0001-fix-cmake.patch"
patch_description: "correct the order of cmake min and project, disable example and test"
patch_type: "conan"
74 changes: 74 additions & 0 deletions recipes/minmea/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
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"
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,
}
exports_sources = ["CMakeLists.txt"]

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):
if is_msvc(self):
raise ConanInvalidConfiguration(f"{self.ref} can not be built on Visual Studio and msvc.(yet)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is breaking the build on MSVC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this sentences in README.md.
https://github.com/kosma/minmea/blob/e368d847d75abd891c651f7d30ce5efb6681adb7/README.md#compatibility

I will try to support MSVC.


def build_requirements(self):
self.tool_requires("pkgconf/2.2.0")
toge marked this conversation as resolved.
Show resolved Hide resolved

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MINMEA_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["minmea"]
50 changes: 50 additions & 0 deletions recipes/minmea/all/patches/0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b96e1d7..1fe282a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,30 +1,30 @@
cmake_minimum_required(VERSION 3.3)

-enable_testing()
+# enable_testing()

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})
-
+# 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})
+if(NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -Werror -std=c99")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_C_SOURCE=199309L -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE")
-
+endif()
set(minmea_SRCS minmea.c minmea.h)
add_library(minmea ${minmea_SRCS})

-add_executable(example example.c)
-target_link_libraries(example minmea)
+# add_executable(example example.c)
+# target_link_libraries(example minmea)

-add_executable(tests tests.c)
-target_link_libraries(tests minmea ${CHECK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
-target_include_directories(tests PUBLIC ${CHECK_INCLUDE_DIRS})
-target_compile_options(tests PUBLIC ${CHECK_CFLAGS_OTHER})
+# add_executable(tests tests.c)
+# target_link_libraries(tests minmea ${CHECK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+# target_include_directories(tests PUBLIC ${CHECK_INCLUDE_DIRS})
+# target_compile_options(tests PUBLIC ${CHECK_CFLAGS_OTHER})

-add_test(NAME tests COMMAND $<TARGET_FILE:tests>)
-list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
+# add_test(NAME tests COMMAND $<TARGET_FILE:tests>)
+# list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")

find_program(SCAN_FOUND scan-build)

7 changes: 7 additions & 0 deletions recipes/minmea/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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)
26 changes: 26 additions & 0 deletions recipes/minmea/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
69 changes: 69 additions & 0 deletions recipes/minmea/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <stdio.h>
#include "minmea.h"

char* nmea_data[] = {
"$GPGGA,155246.585,5231.171,N,01321.830,E,1,12,1.0,0.0,M,0.0,M,,*6F",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there has been a shift towards simpler test_package executables lately, this one could probably be reduced to parsing just a single NMEA string as a test as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I am going to make test_package.c simpler.

"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155246.585,A,5231.171,N,01321.830,E,5768.0,100.5,120224,000.0,W*44",
"$GPGGA,155247.585,5230.707,N,01324.349,E,1,12,1.0,0.0,M,0.0,M,,*68",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155247.585,A,5230.707,N,01324.349,E,5522.0,077.3,120224,000.0,W*48",
"$GPGGA,155248.585,5231.236,N,01326.712,E,1,12,1.0,0.0,M,0.0,M,,*69",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155248.585,A,5231.236,N,01326.712,E,3306.0,067.4,120224,000.0,W*49",
"$GPGGA,155249.585,5231.753,N,01327.959,E,1,12,1.0,0.0,M,0.0,M,,*6E",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155249.585,A,5231.753,N,01327.959,E,1752.9,291.8,120224,000.0,W*47",
"$GPGGA,155250.585,5232.020,N,01327.289,E,1,12,1.0,0.0,M,0.0,M,,*60",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155250.585,A,5232.020,N,01327.289,E,8124.7,266.3,120224,000.0,W*4A",
"$GPGGA,155251.585,5231.785,N,01323.602,E,1,12,1.0,0.0,M,0.0,M,,*69",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155251.585,A,5231.785,N,01323.602,E,5026.3,260.0,120224,000.0,W*4C",
"$GPGGA,155252.585,5231.399,N,01321.398,E,1,12,1.0,0.0,M,0.0,M,,*67",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155252.585,A,5231.399,N,01321.398,E,3905.6,194.0,120224,000.0,W*41",
"$GPGGA,155253.585,5230.328,N,01321.130,E,1,12,1.0,0.0,M,0.0,M,,*6D",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155253.585,A,5230.328,N,01321.130,E,3905.6,000.0,120224,000.0,W*47",
"$GPGGA,155254.585,5230.328,N,01321.130,E,1,12,1.0,0.0,M,0.0,M,,*6A",
"$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30",
"$GPRMC,155254.585,A,5230.328,N,01321.130,E,000.0,000.0,120224,000.0,W*79",
};

int main(void) {
for (int i = 0; i < sizeof(nmea_data) / sizeof(nmea_data[0]); i++) {
char* line = nmea_data[i];
switch (minmea_sentence_id(line, false)) {
case MINMEA_SENTENCE_RMC: {
struct minmea_sentence_rmc frame;
if (minmea_parse_rmc(&frame, line)) {
printf("$RMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n", frame.latitude.value, frame.latitude.scale, frame.longitude.value, frame.longitude.scale, frame.speed.value,
frame.speed.scale);
printf("$RMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n", minmea_rescale(&frame.latitude, 1000), minmea_rescale(&frame.longitude, 1000),
minmea_rescale(&frame.speed, 1000));
printf("$RMC floating point degree coordinates and speed: (%f,%f) %f\n", minmea_tocoord(&frame.latitude), minmea_tocoord(&frame.longitude), minmea_tofloat(&frame.speed));
}
} break;

case MINMEA_SENTENCE_GGA: {
struct minmea_sentence_gga frame;
if (minmea_parse_gga(&frame, line)) {
printf("$GGA: fix quality: %d\n", frame.fix_quality);
}
} break;

case MINMEA_SENTENCE_GSV: {
struct minmea_sentence_gsv frame;
if (minmea_parse_gsv(&frame, line)) {
printf("$GSV: message %d of %d\n", frame.msg_nr, frame.total_msgs);
printf("$GSV: satellites in view: %d\n", frame.total_sats);
for (int i = 0; i < 4; i++)
printf("$GSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n", frame.sats[i].nr, frame.sats[i].elevation, frame.sats[i].azimuth, frame.sats[i].snr);
}
} break;
}
}

return 0;
}
3 changes: 3 additions & 0 deletions recipes/minmea/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20230620":
folder: all
Loading