-
Notifications
You must be signed in to change notification settings - Fork 231
/
CMakeLists.txt
72 lines (60 loc) · 2.72 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 2.6)
project(periphery C)
option(BUILD_TESTS "Build test programs" ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Check Linux kernel header files for character device GPIO support
include(CheckSourceCompiles)
check_source_compiles(C "#include <linux/gpio.h>\nint main(void) { GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; return 0; }" HAVE_GPIO_CDEV_V2)
include(CheckSymbolExists)
check_symbol_exists(GPIO_GET_LINEEVENT_IOCTL linux/gpio.h HAVE_GPIO_CDEV_V1)
if(HAVE_GPIO_CDEV_V2)
set(GPIO_CDEV_SUPPORT 2)
elseif(HAVE_GPIO_CDEV_V1)
set(GPIO_CDEV_SUPPORT 1)
else()
set(GPIO_CDEV_SUPPORT 0)
message(WARNING "Missing character device GPIO support in Linux kernel header files. c-periphery will be built with legacy sysfs GPIO support only.")
endif()
add_definitions(-DPERIPHERY_GPIO_CDEV_SUPPORT=${GPIO_CDEV_SUPPORT})
# Library version
set(VERSION "2.4.2")
set(SOVERSION ${VERSION})
# Glob sources, headers, tests
file(GLOB_RECURSE periphery_SOURCES src/*.c)
file(GLOB_RECURSE periphery_HEADERS src/*.h)
file(GLOB_RECURSE periphery_TESTS tests/*.c)
# Expose git commit id into COMMIT_ID variable
execute_process(
COMMAND git --git-dir="${CMAKE_CURRENT_SOURCE_DIR}/.git" describe --abbrev --always --tags --dirty
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE COMMIT_ID
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Define C flags and include directories
add_definitions(-DPERIPHERY_VERSION_COMMIT="${COMMIT_ID}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wno-stringop-truncation -fPIC")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_RELEASE "-O3")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
# Declare library target
add_library(periphery ${periphery_SOURCES} ${periphery_HEADERS})
set_target_properties(periphery PROPERTIES SOVERSION ${VERSION})
include(GNUInstallDirs)
# Generate pkg-config pc file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/libperiphery.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libperiphery.pc @ONLY)
# Declare install targets
install(TARGETS periphery DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${periphery_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libperiphery.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Declare test targets if enabled
if(BUILD_TESTS)
foreach(TEST_SOURCE ${periphery_TESTS})
get_filename_component(TEST_PROGRAM ${TEST_SOURCE} NAME_WE)
add_executable(${TEST_PROGRAM} ${TEST_SOURCE})
target_link_libraries(${TEST_PROGRAM} periphery pthread)
set(TEST_PROGRAMS ${TEST_PROGRAMS} ${TEST_PROGRAM})
endforeach()
add_custom_target(tests DEPENDS periphery ${TEST_PROGRAMS})
endif()