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

Add CMAKE, linux/macos build. Updated for new versions #132

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ output
*.sdf
sdk/obj
**/ipch
build
*.obj
*.o
*.o
78 changes: 78 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
cmake_minimum_required(VERSION 3.18)
project(rplidar_sdk)

if (NOT UNIX)
message(FATAL_ERROR "Only support Unix, sorry.")
endif()

file(GLOB SRC_FILES
sdk/src/*.cpp
sdk/src/dataunpacker/*.cpp
sdk/src/dataunpacker/unpacker/*.cpp
sdk/src/hal/*.cpp)

if(LINUX)
file(GLOB EXTRA_SRC_FILES
sdk/src/arch/linux/*.cpp)
else() # macOS
file(GLOB EXTRA_SRC_FILES
sdk/src/arch/macOS/*.cpp)
endif()

list (APPEND SRC_FILES ${EXTRA_SRC_FILES})

add_library(rplidar_sdk STATIC
${SRC_FILES}
)
add_library(rplidar_sdk::rplidar_sdk ALIAS rplidar_sdk)

target_include_directories(rplidar_sdk
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sdk/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sdk/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/sdk/src/dataunpacker>
$<INSTALL_INTERFACE:include>
# $<INSTALL_INTERFACE:sdk/src>
)

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}
)
2 changes: 0 additions & 2 deletions app/custom_baudrate/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>

#include "sl_lidar.h"
#include "sl_lidar_driver.h"
#ifndef _countof
#define _countof(_Array) (int)(sizeof(_Array) / sizeof(_Array[0]))
Expand Down
5 changes: 5 additions & 0 deletions cmake/rplidar_sdkConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@[email protected])

check_required_components(@PROJECT_NAME@)
2 changes: 1 addition & 1 deletion sdk/src/hal/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/hal/locker.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Locker
}

#else
#ifdef _MACOS
#ifdef __APPLE__
if (timeout !=0 ) {
if (pthread_mutex_lock(&_lock) == 0) return LOCK_OK;
}
Expand All @@ -84,7 +84,7 @@ class Locker
{
if (pthread_mutex_trylock(&_lock) == 0) return LOCK_OK;
}
#ifndef _MACOS
#ifndef __APPLE__
else
{
timespec wait_time;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/hal/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/sdkcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down