Skip to content

Commit

Permalink
Merge pull request #5 from hepingood/dev
Browse files Browse the repository at this point in the history
feat: add cmake
  • Loading branch information
libdriver authored Oct 3, 2022
2 parents 6616d5f + 4fe1227 commit 4e970fb
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 38 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ LibDriver MPU6050 is the full function driver of mpu6050 launched by LibDriver.

/src includes LibDriver MPU6050 source files.

/interface includes LibDriver MPU6050 IIC platform independent template
/interface includes LibDriver MPU6050 IIC platform independent template.

/test includes LibDriver MPU6050 driver test code and this code can test the chip necessary function simply
/test includes LibDriver MPU6050 driver test code and this code can test the chip necessary function simply.

/example includes LibDriver MPU6050 sample code.

/doc includes LibDriver MPU6050 offline document.

/datasheet includes MPU6050 datasheet
/datasheet includes MPU6050 datasheet.

/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.

Expand All @@ -52,6 +52,8 @@ Add /src, /interface and /example to your project.
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```C
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
6 changes: 6 additions & 0 deletions README_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Fügen Sie /src, /interface und /example zu Ihrem Projekt hinzu.
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```c
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
6 changes: 6 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ LibDriver MPU6050は、LibDriverによって起動されたmpu6050の全機能
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```c
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
6 changes: 6 additions & 0 deletions README_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ LibDriver MPU6050은 LibDriver에서 출시한 mpu6050의 전체 기능 드라
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```c
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
6 changes: 6 additions & 0 deletions README_zh-Hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ LibDriver MPU6050是LibDriver推出的MPU6050的全功能驱动,该驱动提
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```C
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
6 changes: 6 additions & 0 deletions README_zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ LibDriver MPU6050是LibDriver推出的MPU6050的全功能驅動,該驅動提
#### example basic

```C
#include "driver_mpu6050_basic.h"

uint8_t res;
uint32_t i;
uint32_t times;
Expand Down Expand Up @@ -122,6 +124,8 @@ return 0;
#### example fifo

```C
#include "driver_mpu6050_fifo.h"

uint32_t i;
uint32_t times;
uint16_t len;
Expand Down Expand Up @@ -203,6 +207,8 @@ return 0;
#### example dmp
```C
#include "driver_mpu6050_dmp.h"
uint32_t i;
uint32_t times;
uint32_t cnt;
Expand Down
212 changes: 212 additions & 0 deletions project/raspberrypi4b/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#
# Copyright (c) 2015 - present LibDriver All rights reserved
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

# set the cmake minimum version
cmake_minimum_required(VERSION 3.0)

# set the project name and language
project(mpu6050 C)

# read the version from files
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VERSION ${CMAKE_PROJECT_NAME}_VERSION)

# set the project version
set(PROJECT_VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# set c standard c99
set(CMAKE_C_STANDARD 99)

# enable c standard required
set(CMAKE_C_STANDARD_REQUIRED True)

# set release level
set(CMAKE_BUILD_TYPE Release)

# set the release flags of c
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")

# include cmake package config helpers
include(CMakePackageConfigHelpers)

# find the pkgconfig and use this tool to find the third party packages
find_package(PkgConfig REQUIRED)

# find the third party packages with pkgconfig
pkg_search_module(GPIOD REQUIRED libgpiod)

# include all library header directories
set(LIB_INC_DIRS
${GPIOD_INCLUDE_DIRS}
)

# include all linked libraries
set(LIBS
${GPIOD_LIBRARIES}
)

# include all header directories
set(INC_DIRS
${LIB_INC_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../interface
${CMAKE_CURRENT_SOURCE_DIR}/../../example
${CMAKE_CURRENT_SOURCE_DIR}/../../test
${CMAKE_CURRENT_SOURCE_DIR}/interface/inc
)

# include all installed headers
file(GLOB INSTL_INCS
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.h
)

# include all sources files
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.c
)

# include executable source
file(GLOB MAIN
${SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../../example/*.c
${CMAKE_CURRENT_SOURCE_DIR}/../../test/*.c
${CMAKE_CURRENT_SOURCE_DIR}/interface/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/driver/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
)

# enable output as a static library
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRCS})

# set the static library include directories
target_include_directories(${CMAKE_PROJECT_NAME}_static PRIVATE ${INC_DIRS})

# set the static library link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}_static
m
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} libs
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# set the static library version
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# enable output as a dynamic library
add_library(${CMAKE_PROJECT_NAME} SHARED ${SRCS})

# set the executable program include directories
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC $<INSTALL_INTERFACE:include/${CMAKE_PROJECT_NAME}>
PRIVATE ${INC_DIRS}
)

# set the dynamic library link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
m
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} libs
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# include the public header
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${INSTL_INCS}")

# set the dynamic library version
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# enable the executable program
add_executable(${CMAKE_PROJECT_NAME}_exe ${MAIN})

# set the executable program include directories
target_include_directories(${CMAKE_PROJECT_NAME}_exe PRIVATE ${INC_DIRS})

# set the executable program link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}_exe
${LIBS}
m
pthread
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} exe
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# install the binary
install(TARGETS ${CMAKE_PROJECT_NAME}_exe
RUNTIME DESTINATION bin
)

# install the static library
install(TARGETS ${CMAKE_PROJECT_NAME}_static
ARCHIVE DESTINATION lib
)

# install the dynamic library
install(TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME}
)

# make the cmake config file
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake
INSTALL_DESTINATION cmake
)

# write the cmake config version
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)

# install the cmake files
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake"
DESTINATION cmake
)

# set the export items
install(EXPORT ${CMAKE_PROJECT_NAME}-targets
DESTINATION cmake
)

# add uninstall command
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake
)

#include ctest module
include(CTest)

# creat a test
add_test(NAME ${CMAKE_PROJECT_NAME}_test COMMAND ${CMAKE_PROJECT_NAME}_exe -p)
Loading

0 comments on commit 4e970fb

Please sign in to comment.