From 6938381a09144dd6729316c406046c3815638abf Mon Sep 17 00:00:00 2001 From: Nart Hna <42131264+warrenbocphet@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:47:50 +1000 Subject: [PATCH 1/5] Cmake and some compiling error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(net_socket): compare ans with NULL to check failed inet_ntop() call In getAddressAsString(), we are comparing ans <= 0 to check for failure. When compiling with g++ 11.2 (Ubuntu 22.02), this gave the following error: src/arch/linux/net_socket.cpp:170:15: error: ordered comparison of pointer with integer zero (‘const char*’ and ‘int’) inet_ntop returns a NULL pointer for failure and non-NULL otherwise. So in order to fix this, we can simply compare ans with NULL. * add CMake support * play around with exporting config * fix up cmake Co-authored-by: vitsensei --- .gitignore | 1 + CMakeLists.txt | 76 +++++++++++++++++++++++++++++++ cmake/rplidar_sdkConfig.cmake.in | 5 ++ sdk/src/arch/linux/net_socket.cpp | 2 +- 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/rplidar_sdkConfig.cmake.in diff --git a/.gitignore b/.gitignore index a1a2240..09454d1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ output *.sdf sdk/obj **/ipch +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ca708a0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +cmake_minimum_required(VERSION 3.18) +project(rplidar_sdk) + +if (NOT UNIX) + message(FATAL_ERROR "Only support Linux, sorry.") +endif() + +file(GLOB SRC_FILES + sdk/src/*.cpp + sdk/src/hal/*.cpp + sdk/src/arch/linux/*.cpp) + +file(GLOB INCLUDE_FILES + sdk/include/*.h + sdk/src/*.h + sdk/src/*.hpp + sdk/src/hal/*.h + sdk/src/hal/*.hpp + sdk/src/arch/linux/*.h + sdk/src/arch/linux/*.hpp) + +add_library(rplidar_sdk STATIC + ${SRC_FILES} + ${INCLUDE_FILES} +) + +target_include_directories(rplidar_sdk + PUBLIC + $ + $ + $ + # $ +) + +file(GLOB PUBLIC_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/sdk/include/*.h") +install(FILES ${PUBLIC_HEADER_FILES} + DESTINATION include +) + +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/sdk/src/hal/types.h" + DESTINATION include/hal +) + + +install(TARGETS rplidar_sdk + EXPORT ${PROJECT_NAME}-targets +) + +#################################################### +# Exports +#################################################### + +# This section is a boiler plate to ensure the targets are exported for use in other cmake projects via find_package +# See https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html for more info on what's going on here + +include(CMakePackageConfigHelpers) + +# Create a *Config.cmake file using the *.cmake.in file +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION lib/cmake/${PROJECT_NAME} +) + +# Install the *Config.cmake file we've just created +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake + DESTINATION lib/cmake/${PROJECT_NAME}/ +) + +# Install the targets exported by the earlier install commands +# for use by the *Config.cmake generate above +# This file is pulled in via the commands in the *Config.cmake.in template +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION lib/cmake/${PROJECT_NAME} +) \ No newline at end of file diff --git a/cmake/rplidar_sdkConfig.cmake.in b/cmake/rplidar_sdkConfig.cmake.in new file mode 100644 index 0000000..a221835 --- /dev/null +++ b/cmake/rplidar_sdkConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake) + +check_required_components(@PROJECT_NAME@) \ No newline at end of file diff --git a/sdk/src/arch/linux/net_socket.cpp b/sdk/src/arch/linux/net_socket.cpp index 36b9bec..5cc69b6 100644 --- a/sdk/src/arch/linux/net_socket.cpp +++ b/sdk/src/arch/linux/net_socket.cpp @@ -167,7 +167,7 @@ u_result SocketAddress::getAddressAsString(char * buffer, size_t buffersize) con break; } - return ans<=0?RESULT_OPERATION_FAIL:RESULT_OK; + return ans==NULL?RESULT_OPERATION_FAIL:RESULT_OK; } From ab07bef254296f1df83b5572a46b64836b719bdd Mon Sep 17 00:00:00 2001 From: Nart Hna <42131264+warrenbocphet@users.noreply.github.com> Date: Thu, 15 Sep 2022 13:53:45 +1000 Subject: [PATCH 2/5] -Wnarrowing (#2) --- sdk/src/sl_lidar_driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/sl_lidar_driver.cpp b/sdk/src/sl_lidar_driver.cpp index b82ed0c..b9584a1 100644 --- a/sdk/src/sl_lidar_driver.cpp +++ b/sdk/src/sl_lidar_driver.cpp @@ -553,7 +553,7 @@ namespace sl { { switch (_dataEvt.wait(timeout)) { - case rp::hal::Event::EVENT_TIMEOUT: + case static_cast(rp::hal::Event::EVENT_TIMEOUT): count = 0; return SL_RESULT_OPERATION_TIMEOUT; case rp::hal::Event::EVENT_OK: From 814e98fbd17c6e61e23026f4decb9f14fb92a759 Mon Sep 17 00:00:00 2001 From: Marcus Forte Date: Tue, 18 Jun 2024 19:40:08 +0200 Subject: [PATCH 3/5] cleanup --- CMakeLists.txt | 2 ++ app/custom_baudrate/main.cpp | 2 -- sdk/src/sl_udp_channel.cpp | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca708a0..7422651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ add_library(rplidar_sdk STATIC ${INCLUDE_FILES} ) +add_library(rplidar_sdk::rplidar_sdk ALIAS rplidar_sdk) + target_include_directories(rplidar_sdk PUBLIC $ diff --git a/app/custom_baudrate/main.cpp b/app/custom_baudrate/main.cpp index be11fc9..1223178 100644 --- a/app/custom_baudrate/main.cpp +++ b/app/custom_baudrate/main.cpp @@ -32,10 +32,8 @@ #include #include -#include #include -#include "sl_lidar.h" #include "sl_lidar_driver.h" #ifndef _countof #define _countof(_Array) (int)(sizeof(_Array) / sizeof(_Array[0])) diff --git a/sdk/src/sl_udp_channel.cpp b/sdk/src/sl_udp_channel.cpp index aa39d9e..cf18477 100644 --- a/sdk/src/sl_udp_channel.cpp +++ b/sdk/src/sl_udp_channel.cpp @@ -30,7 +30,6 @@ * */ -#pragma once #include "sl_lidar_driver.h" #include "hal/abs_rxtx.h" #include "hal/socket.h" From b9c70261392869ff922eb2b7548916d217140a92 Mon Sep 17 00:00:00 2001 From: Marcus Forte Date: Tue, 18 Jun 2024 20:15:55 +0200 Subject: [PATCH 4/5] fixes --- CMakeLists.txt | 28 ++++++++++++---------------- sdk/src/hal/locker.h | 4 ++-- sdk/src/hal/thread.cpp | 2 +- sdk/src/sdkcommon.h | 2 +- sdk/src/sl_serial_channel.cpp | 1 - sdk/src/sl_tcp_channel.cpp | 1 - 6 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7422651..69bc578 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,26 +2,23 @@ cmake_minimum_required(VERSION 3.18) project(rplidar_sdk) if (NOT UNIX) - message(FATAL_ERROR "Only support Linux, sorry.") + message(FATAL_ERROR "Only support Unix, sorry.") endif() -file(GLOB SRC_FILES - sdk/src/*.cpp - sdk/src/hal/*.cpp - sdk/src/arch/linux/*.cpp) - -file(GLOB INCLUDE_FILES - sdk/include/*.h - sdk/src/*.h - sdk/src/*.hpp - sdk/src/hal/*.h - sdk/src/hal/*.hpp - sdk/src/arch/linux/*.h - sdk/src/arch/linux/*.hpp) +if(LINUX) + file(GLOB SRC_FILES + sdk/src/*.cpp + sdk/src/hal/*.cpp + sdk/src/arch/linux/*.cpp) +else() # macOS + file(GLOB SRC_FILES + sdk/src/*.cpp + sdk/src/hal/*.cpp + sdk/src/arch/macOS/*.cpp) +endif() add_library(rplidar_sdk STATIC ${SRC_FILES} - ${INCLUDE_FILES} ) add_library(rplidar_sdk::rplidar_sdk ALIAS rplidar_sdk) @@ -43,7 +40,6 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/sdk/src/hal/types.h" DESTINATION include/hal ) - install(TARGETS rplidar_sdk EXPORT ${PROJECT_NAME}-targets ) diff --git a/sdk/src/hal/locker.h b/sdk/src/hal/locker.h index dd33a84..fa02433 100644 --- a/sdk/src/hal/locker.h +++ b/sdk/src/hal/locker.h @@ -71,7 +71,7 @@ class Locker } #else -#ifdef _MACOS +#ifdef __APPLE__ if (timeout !=0 ) { if (pthread_mutex_lock(&_lock) == 0) return LOCK_OK; } @@ -84,7 +84,7 @@ class Locker { if (pthread_mutex_trylock(&_lock) == 0) return LOCK_OK; } -#ifndef _MACOS +#ifndef __APPLE__ else { timespec wait_time; diff --git a/sdk/src/hal/thread.cpp b/sdk/src/hal/thread.cpp index bc68dd5..c6b3bf1 100644 --- a/sdk/src/hal/thread.cpp +++ b/sdk/src/hal/thread.cpp @@ -37,7 +37,7 @@ #if defined(_WIN32) #include "arch/win32/winthread.hpp" -#elif defined(_MACOS) +#elif defined(__APPLE__) #include "arch/macOS/thread.hpp" #elif defined(__GNUC__) #include "arch/linux/thread.hpp" diff --git a/sdk/src/sdkcommon.h b/sdk/src/sdkcommon.h index f928b42..6ecf80c 100644 --- a/sdk/src/sdkcommon.h +++ b/sdk/src/sdkcommon.h @@ -35,7 +35,7 @@ #if defined(_WIN32) #include "arch/win32/arch_win32.h" -#elif defined(_MACOS) +#elif defined(__APPLE__) #include "arch/macOS/arch_macOS.h" #elif defined(__GNUC__) #include "arch/linux/arch_linux.h" diff --git a/sdk/src/sl_serial_channel.cpp b/sdk/src/sl_serial_channel.cpp index 516cd4e..e743912 100644 --- a/sdk/src/sl_serial_channel.cpp +++ b/sdk/src/sl_serial_channel.cpp @@ -30,7 +30,6 @@ * */ -#pragma once #include "sl_lidar_driver.h" #include "hal/abs_rxtx.h" #include "hal/socket.h" diff --git a/sdk/src/sl_tcp_channel.cpp b/sdk/src/sl_tcp_channel.cpp index f4fd5ae..11e943a 100644 --- a/sdk/src/sl_tcp_channel.cpp +++ b/sdk/src/sl_tcp_channel.cpp @@ -30,7 +30,6 @@ * */ -#pragma once #include "sl_lidar_driver.h" #include "hal/abs_rxtx.h" #include "hal/socket.h" From 1bd81dd7aa45ef3d3c9c357749c3312803e3a06a Mon Sep 17 00:00:00 2001 From: Marcus Forte Date: Tue, 23 Jul 2024 21:51:12 +0200 Subject: [PATCH 5/5] fixed apple ifdef --- sdk/src/hal/event.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/hal/event.h b/sdk/src/hal/event.h index ada15a5..b558924 100644 --- a/sdk/src/hal/event.h +++ b/sdk/src/hal/event.h @@ -59,7 +59,7 @@ class Event #else pthread_mutex_init(&_cond_locker, NULL); pthread_condattr_init(&_cond_attr); -#ifdef _MACOS +#ifdef __APPLE__ // sadly, there is no monotonic clock support for pthread cond variable on MACOS // if time slew is a big issue, try to reimplement it using kqueue/kevent #else