-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
98 lines (77 loc) · 2.86 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
cmake_minimum_required(VERSION 3.10)
# workaround for https://gitlab.kitware.com/cmake/cmake/issues/16967
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
project(rx888)
else()
project(rx888 C)
endif()
#select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_C_FLAGS "-std=c11 -pedantic-errors -Wall -Wextra -Werror")
include(GNUInstallDirs)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
# Set the version information here
set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes
set(VERSION_INFO_MINOR_VERSION 6) # increment minor on feature-level changes
set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBUSB libusb-1.0 IMPORTED_TARGET)
endif()
if(PKG_CONFIG_FOUND AND NOT LIBUSB_FOUND)
message(FATAL_ERROR "LibUSB 1.0 required to compile rx888")
endif()
########################################################################
# Install public header files
########################################################################
install(FILES
include/librx888.h
DESTINATION include
)
########################################################################
# Add subdirectories
########################################################################
add_subdirectory(include)
add_subdirectory(src)
########################################################################
# Create Pkg Config File
########################################################################
FOREACH(inc ${LIBUSB_INCLUDEDIR})
LIST(APPEND RX888_PC_CFLAGS "-I${inc}")
ENDFOREACH(inc)
FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
LIST(APPEND RX888_PC_LIBS "-L${lib}")
ENDFOREACH(lib)
# use space-separation format for the pc file
STRING(REPLACE ";" " " RX888_PC_CFLAGS "${RX888_PC_CFLAGS}")
STRING(REPLACE ";" " " RX888_PC_LIBS "${RX888_PC_LIBS}")
# unset these vars to avoid hard-coded paths to cross environment
IF(CMAKE_CROSSCOMPILING)
UNSET(RX888_PC_CFLAGS)
UNSET(RX888_PC_LIBS)
ENDIF(CMAKE_CROSSCOMPILING)
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix \${prefix})
set(includedir \${prefix}/include)
set(libdir \${exec_prefix}/lib)
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/librx888.pc.in
${CMAKE_CURRENT_BINARY_DIR}/librx888.pc
@ONLY)
INSTALL(
FILES ${CMAKE_CURRENT_BINARY_DIR}/librx888.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()