Skip to content

Commit 024f90b

Browse files
authored
Merge pull request #5 from hepingood/dev
feat: add cmake
2 parents ce4b8bf + f573ecb commit 024f90b

File tree

13 files changed

+555
-38
lines changed

13 files changed

+555
-38
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ LibDriver AT24CXX is the full function driver of AT24CXX launched by LibDriver.
2727

2828
/src includes LibDriver AT24CXX source files.
2929

30-
/interface includes LibDriver AT24CXX IIC platform independent template
30+
/interface includes LibDriver AT24CXX IIC platform independent template.
3131

32-
/test includes LibDriver AT24CXX driver test code and this code can test the chip necessary function simply
32+
/test includes LibDriver AT24CXX driver test code and this code can test the chip necessary function simply.
3333

3434
/example includes LibDriver AT24CXX sample code.
3535

3636
/doc includes LibDriver AT24CXX offline document.
3737

38-
/datasheet includes AT24CXX datasheet
38+
/datasheet includes AT24CXX datasheet.
3939

4040
/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.
4141

@@ -50,6 +50,8 @@ Add /src, /interface and /example to your project.
5050
#### example basic
5151

5252
```C
53+
#include "driver_at24cxx_basic.h"
54+
5355
uint8_t res;
5456
uint8_t data;
5557

README_de.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Fügen Sie /src, /interface und /example zu Ihrem Projekt hinzu.
4949
#### example basic
5050

5151
```C
52+
#include "driver_at24cxx_basic.h"
53+
5254
uint8_t res;
5355
uint8_t data;
5456

README_ja.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ LibDriver AT24CXXは、LibDriverによって起動されたAT24CXXの全機能
5050
#### example basic
5151

5252
```C
53+
#include "driver_at24cxx_basic.h"
54+
5355
uint8_t res;
5456
uint8_t data;
5557

README_ko.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ LibDriver AT24CXX는 LibDriver에서 출시한 AT24CXX의 전체 기능 드라
5050
#### example basic
5151

5252
```C
53+
#include "driver_at24cxx_basic.h"
54+
5355
uint8_t res;
5456
uint8_t data;
5557

README_zh-Hans.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ LibDriver AT24CXX是LibDriver推出的AT24CXX的全功能驱动,该驱动提
5050
#### example basic
5151

5252
```C
53+
#include "driver_at24cxx_basic.h"
54+
5355
uint8_t res;
5456
uint8_t data;
5557

README_zh-Hant.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ LibDriver AT24CXX是LibDriver推出的AT24CXX的全功能驅動,該驅動提
5050
#### example basic
5151

5252
```C
53+
#include "driver_at24cxx_basic.h"
54+
5355
uint8_t res;
5456
uint8_t data;
5557

project/raspberrypi4b/CMakeLists.txt

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#
2+
# Copyright (c) 2015 - present LibDriver All rights reserved
3+
#
4+
# The MIT License (MIT)
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
#
24+
25+
# set the cmake minimum version
26+
cmake_minimum_required(VERSION 3.0)
27+
28+
# set the project name and language
29+
project(at24cxx C)
30+
31+
# read the version from files
32+
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VERSION ${CMAKE_PROJECT_NAME}_VERSION)
33+
34+
# set the project version
35+
set(PROJECT_VERSION ${${CMAKE_PROJECT_NAME}_VERSION})
36+
37+
# set c standard c99
38+
set(CMAKE_C_STANDARD 99)
39+
40+
# enable c standard required
41+
set(CMAKE_C_STANDARD_REQUIRED True)
42+
43+
# set release level
44+
set(CMAKE_BUILD_TYPE Release)
45+
46+
# set the release flags of c
47+
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
48+
49+
# include cmake package config helpers
50+
include(CMakePackageConfigHelpers)
51+
52+
# find the pkgconfig and use this tool to find the third party packages
53+
find_package(PkgConfig REQUIRED)
54+
55+
# find the third party packages with pkgconfig
56+
pkg_search_module(GPIOD REQUIRED libgpiod)
57+
58+
# include all library header directories
59+
set(LIB_INC_DIRS
60+
${GPIOD_INCLUDE_DIRS}
61+
)
62+
63+
# include all linked libraries
64+
set(LIBS
65+
${GPIOD_LIBRARIES}
66+
)
67+
68+
# include all header directories
69+
set(INC_DIRS
70+
${LIB_INC_DIRS}
71+
${CMAKE_CURRENT_SOURCE_DIR}/../../src
72+
${CMAKE_CURRENT_SOURCE_DIR}/../../interface
73+
${CMAKE_CURRENT_SOURCE_DIR}/../../example
74+
${CMAKE_CURRENT_SOURCE_DIR}/../../test
75+
${CMAKE_CURRENT_SOURCE_DIR}/interface/inc
76+
)
77+
78+
# include all installed headers
79+
file(GLOB INSTL_INCS
80+
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.h
81+
)
82+
83+
# include all sources files
84+
file(GLOB SRCS
85+
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.c
86+
)
87+
88+
# include executable source
89+
file(GLOB MAIN
90+
${SRCS}
91+
${CMAKE_CURRENT_SOURCE_DIR}/../../example/*.c
92+
${CMAKE_CURRENT_SOURCE_DIR}/../../test/*.c
93+
${CMAKE_CURRENT_SOURCE_DIR}/interface/src/*.c
94+
${CMAKE_CURRENT_SOURCE_DIR}/driver/src/*.c
95+
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
96+
)
97+
98+
# enable output as a static library
99+
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRCS})
100+
101+
# set the static library include directories
102+
target_include_directories(${CMAKE_PROJECT_NAME}_static PRIVATE ${INC_DIRS})
103+
104+
# set the static library link libraries
105+
target_link_libraries(${CMAKE_PROJECT_NAME}_static
106+
m
107+
)
108+
109+
# rename as ${CMAKE_PROJECT_NAME}
110+
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})
111+
112+
# don't delete ${CMAKE_PROJECT_NAME} libs
113+
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
114+
115+
# set the static library version
116+
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})
117+
118+
# enable output as a dynamic library
119+
add_library(${CMAKE_PROJECT_NAME} SHARED ${SRCS})
120+
121+
# set the executable program include directories
122+
target_include_directories(${CMAKE_PROJECT_NAME}
123+
PUBLIC $<INSTALL_INTERFACE:include/${CMAKE_PROJECT_NAME}>
124+
PRIVATE ${INC_DIRS}
125+
)
126+
127+
# set the dynamic library link libraries
128+
target_link_libraries(${CMAKE_PROJECT_NAME}
129+
m
130+
)
131+
132+
# rename as ${CMAKE_PROJECT_NAME}
133+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})
134+
135+
# don't delete ${CMAKE_PROJECT_NAME} libs
136+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
137+
138+
# include the public header
139+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${INSTL_INCS}")
140+
141+
# set the dynamic library version
142+
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})
143+
144+
# enable the executable program
145+
add_executable(${CMAKE_PROJECT_NAME}_exe ${MAIN})
146+
147+
# set the executable program include directories
148+
target_include_directories(${CMAKE_PROJECT_NAME}_exe PRIVATE ${INC_DIRS})
149+
150+
# set the executable program link libraries
151+
target_link_libraries(${CMAKE_PROJECT_NAME}_exe
152+
${LIBS}
153+
m
154+
pthread
155+
)
156+
157+
# rename as ${CMAKE_PROJECT_NAME}
158+
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})
159+
160+
# don't delete ${CMAKE_PROJECT_NAME} exe
161+
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES CLEAN_DIRECT_OUTPUT 1)
162+
163+
# install the binary
164+
install(TARGETS ${CMAKE_PROJECT_NAME}_exe
165+
RUNTIME DESTINATION bin
166+
)
167+
168+
# install the static library
169+
install(TARGETS ${CMAKE_PROJECT_NAME}_static
170+
ARCHIVE DESTINATION lib
171+
)
172+
173+
# install the dynamic library
174+
install(TARGETS ${CMAKE_PROJECT_NAME}
175+
EXPORT ${CMAKE_PROJECT_NAME}-targets
176+
LIBRARY DESTINATION lib
177+
PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME}
178+
)
179+
180+
# make the cmake config file
181+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
182+
${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake
183+
INSTALL_DESTINATION cmake
184+
)
185+
186+
# write the cmake config version
187+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake
188+
VERSION ${PACKAGE_VERSION}
189+
COMPATIBILITY AnyNewerVersion
190+
)
191+
192+
# install the cmake files
193+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake"
194+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake"
195+
DESTINATION cmake
196+
)
197+
198+
# set the export items
199+
install(EXPORT ${CMAKE_PROJECT_NAME}-targets
200+
DESTINATION cmake
201+
)
202+
203+
# add uninstall command
204+
add_custom_target(uninstall
205+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake
206+
)
207+
208+
#include ctest module
209+
include(CTest)
210+
211+
# creat a test
212+
add_test(NAME ${CMAKE_PROJECT_NAME}_test COMMAND ${CMAKE_PROJECT_NAME}_exe -p)

0 commit comments

Comments
 (0)