forked from jgarff/rpi_ws281x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
72 lines (58 loc) · 1.78 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 3.0.0)
# read and parse version file
file(READ version PROJECT_VERSION)
string(STRIP ${PROJECT_VERSION} PROJECT_VERSION)
string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" VERSION_MAJOR ${PROJECT_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" VERSION_MINOR ${PROJECT_VERSION})
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" VERSION_MICRO ${PROJECT_VERSION})
set(HEADERDEF "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_MICRO}")
project(rpi_ws281x VERSION ${PROJECT_VERSION})
option(BUILD_SHARED "Build as shared library" OFF)
option(BUILD_TEST "Build test application" ON)
set(CMAKE_C_STANDARD 11)
set(LIB_TARGET ws2811)
set(TEST_TARGET test)
set(LIB_PUBLIC_HEADERS
ws2811.h
rpihw.h
pwm.h
clk.h
dma.h
gpio.h
mailbox.h
pcm.h
)
set(LIB_SOURCES
mailbox.c
ws2811.c
pwm.c
pcm.c
dma.c
rpihw.c
)
set(TEST_SOURCES
main.c
)
configure_file(version.h.in version.h)
set(DEST_HEADERS_DIR include/ws2811)
set(DEST_LIB_DIR lib)
if(BUILD_SHARED)
add_library(${LIB_TARGET} SHARED ${LIB_SOURCES})
set_target_properties(${LIB_TARGET} PROPERTIES PUBLIC_HEADER "${LIB_PUBLIC_HEADERS}")
install(TARGETS ${LIB_TARGET}
LIBRARY DESTINATION ${DEST_LIB_DIR}
PUBLIC_HEADER DESTINATION ${DEST_HEADERS_DIR}
)
else()
add_library(${LIB_TARGET} ${LIB_SOURCES})
set_target_properties(${LIB_TARGET} PROPERTIES PUBLIC_HEADER "${LIB_PUBLIC_HEADERS}")
install(TARGETS ${LIB_TARGET}
ARCHIVE DESTINATION ${DEST_LIB_DIR}
PUBLIC_HEADER DESTINATION ${DEST_HEADERS_DIR}
)
endif()
if(BUILD_TEST)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(${TEST_TARGET} ${TEST_SOURCES})
target_link_libraries(${TEST_TARGET} ${LIB_TARGET})
endif()