forked from analogdevicesinc/libiio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
285 lines (230 loc) · 8.7 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
cmake_minimum_required(VERSION 2.8.7)
project(libiio C)
set(LIBIIO_VERSION_MAJOR 0)
set(LIBIIO_VERSION_MINOR 6)
set(VERSION "${LIBIIO_VERSION_MAJOR}.${LIBIIO_VERSION_MINOR}")
# Set the default install path to /usr
if (NOT WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "default install path" FORCE)
endif()
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin"
CACHE PATH "Installation directory for binaries")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib"
CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include"
CACHE PATH "Installation directory for headers")
set(INSTALL_PKGCONFIG_DIR "${INSTALL_LIB_DIR}/pkgconfig"
CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share"
CACHE PATH "Installation directory for data")
mark_as_advanced(INSTALL_BIN_DIR)
mark_as_advanced(INSTALL_LIB_DIR)
mark_as_advanced(INSTALL_INC_DIR)
mark_as_advanced(INSTALL_PKGCONFIG_DIR)
mark_as_advanced(INSTALL_DATA_DIR)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS None Debug Release RelWithDebInfo MinSizeRel)
endif()
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
option(WITH_NETWORK_BACKEND "Enable the network backend" ON)
if (NOT MSVC)
option(WITH_TESTS "Build the test programs" ON)
else()
# Avoid annoying warnings from Visual Studio
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
endif()
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
option(WITH_IIOD "Build the IIO Daemon" ON)
option(WITH_LOCAL_BACKEND "Enable the local backend" ON)
if (WITH_IIOD AND NOT WITH_LOCAL_BACKEND)
message(SEND_ERROR "IIOD can only be enabled if the local backend is enabled")
endif()
endif()
option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
include(CheckSymbolExists)
check_symbol_exists(in6addr_any "netinet/in.h" HAVE_IPV6)
if (ENABLE_IPV6)
if (NOT HAVE_IPV6)
message(WARNING "IPv6 is not available in your system.")
else()
add_definitions(-DHAVE_IPV6=1)
endif()
endif()
set(LIBIIO_CFILES channel.c device.c context.c buffer.c utilities.c)
set(LIBIIO_HEADERS iio.h)
add_definitions(-D_POSIX_C_SOURCE=200809L -DLIBIIO_EXPORTS=1)
# Get the GIT hash of the latest commit
include(FindGit OPTIONAL)
if (GIT_FOUND)
execute_process(
COMMAND git rev-parse --show-toplevel
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIBIIO_GIT_REPO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (${LIBIIO_GIT_REPO} MATCHES ${CMAKE_CURRENT_SOURCE_DIR})
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE LIBIIO_VERSION_GIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
if (NOT LIBIIO_VERSION_GIT)
set(LIBIIO_VERSION_GIT v${VERSION})
endif()
add_definitions(-DLIBIIO_VERSION_MAJOR=${LIBIIO_VERSION_MAJOR})
add_definitions(-DLIBIIO_VERSION_MINOR=${LIBIIO_VERSION_MINOR})
add_definitions(-DLIBIIO_VERSION_GIT="${LIBIIO_VERSION_GIT}")
if(WITH_LOCAL_BACKEND)
add_definitions(-DLOCAL_BACKEND=1)
set(LIBIIO_CFILES ${LIBIIO_CFILES} local.c)
endif()
find_library(LIBUSB_LIBRARIES usb-1.0)
find_path(LIBUSB_INCLUDE_DIR libusb-1.0/libusb.h)
if (LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIR)
option(WITH_USB_BACKEND "Enable the libusb backend" ON)
if(WITH_USB_BACKEND)
add_definitions(-DUSB_BACKEND=1)
set(LIBIIO_CFILES ${LIBIIO_CFILES} usb.c)
set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBUSB_LIBRARIES})
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)
include_directories(${LIBUSB_INCLUDE_DIR})
endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(WITH_NETWORK_BACKEND)
if (WIN32)
set(LIBS_TO_LINK ${LIBS_TO_LINK} wsock32 ws2_32)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE=1")
check_c_source_compiles("#include <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)
if (HAS_O_TMPFILE)
add_definitions(-D_GNU_SOURCE=1 -DWITH_NETWORK_GET_BUFFER=1)
endif()
endif()
add_definitions(-DNETWORK_BACKEND=1)
set(LIBIIO_CFILES ${LIBIIO_CFILES} network.c)
find_library(AVAHI_CLIENT_LIBRARIES avahi-client)
find_library(AVAHI_COMMON_LIBRARIES avahi-common)
if(AVAHI_CLIENT_LIBRARIES AND AVAHI_COMMON_LIBRARIES)
add_definitions(-DHAVE_AVAHI=1)
set(AVAHI_LIBRARIES ${AVAHI_CLIENT_LIBRARIES} ${AVAHI_COMMON_LIBRARIES})
set(LIBS_TO_LINK ${LIBS_TO_LINK} ${AVAHI_LIBRARIES})
endif()
set(NEED_THREADS 1)
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)
endif()
if (NEED_LIBXML2)
include(FindLibXml2)
if (NOT LIBXML2_FOUND)
message(SEND_ERROR "The selected backends require libxml2 to be installed")
else()
set(LIBIIO_CFILES ${LIBIIO_CFILES} xml.c)
add_definitions(${LIBXML2_DEFINITIONS} -DXML_BACKEND=1)
include_directories(${LIBXML2_INCLUDE_DIR})
set(LIBS_TO_LINK ${LIBS_TO_LINK} ${LIBXML2_LIBRARIES})
endif()
endif()
if (NEED_THREADS)
if (NOT WIN32)
find_library(PTHREAD_LIBRARIES pthread)
if (PTHREAD_LIBRARIES)
set(LIBS_TO_LINK ${LIBS_TO_LINK} ${PTHREAD_LIBRARIES})
set(LIBIIO_CFILES ${LIBIIO_CFILES} lock.c)
else()
message(SEND_ERROR "The pthread library is a requirement for the selected backends")
endif()
else()
set(LIBIIO_CFILES ${LIBIIO_CFILES} lock.c)
endif()
endif()
if (IIOD_CLIENT)
set(LIBIIO_CFILES ${LIBIIO_CFILES} iiod-client.c)
endif()
configure_file(libiio.iss.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libiio.iss @ONLY)
set(LIBIIO_PC ${CMAKE_CURRENT_BINARY_DIR}/libiio.pc)
configure_file(libiio.pc.cmakein ${LIBIIO_PC} @ONLY)
install(FILES ${LIBIIO_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
#set(SETUP_PY ${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/setup.py)
#configure_file(python/setup.py.in ${SETUP_PY} @ONLY)
add_library(iio ${LIBIIO_CFILES} ${LIBIIO_HEADERS})
set_target_properties(iio PROPERTIES VERSION ${VERSION} SOVERSION ${LIBIIO_VERSION_MAJOR} FRAMEWORK TRUE PUBLIC_HEADER ${LIBIIO_HEADERS})
target_link_libraries(iio LINK_PRIVATE ${LIBS_TO_LINK})
if (MSVC)
set_target_properties(iio PROPERTIES OUTPUT_NAME libiio)
endif()
if(NOT SKIP_INSTALL_ALL)
install(TARGETS iio
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
FRAMEWORK DESTINATION "${INSTALL_LIB_DIR}"
PUBLIC_HEADER DESTINATION "${INSTALL_INC_DIR}")
endif()
find_package(Doxygen)
if(DOXYGEN_FOUND)
option(WITH_DOC "Generate documentation with Doxygen" ON)
if (WITH_DOC)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
set(HTML_DEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/html)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/doc DESTINATION ${HTML_DEST_DIR})
add_custom_command(TARGET iio POST_BUILD
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
install(DIRECTORY ${HTML_DEST_DIR}
DESTINATION ${INSTALL_DATA_DIR}/doc/libiio${LIBIIO_VERSION_MAJOR}-doc)
endif()
else()
message(STATUS "Doxygen not found, API documentation won't be generated")
endif()
# Create an installer if compiling for OSX
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(LIBIIO_PKG ${CMAKE_CURRENT_BINARY_DIR}/libiio-${VERSION}.pkg)
set(LIBIIO_TEMP_PKG ${CMAKE_CURRENT_BINARY_DIR}/libiio-${VERSION}-temp.pkg)
set(LIBIIO_DISTRIBUTION_XML ${CMAKE_CURRENT_BINARY_DIR}/Distribution.xml)
configure_file(Distribution.xml.cmakein ${LIBIIO_DISTRIBUTION_XML} @ONLY)
find_program(PKGBUILD_EXECUTABLE
NAMES pkgbuild
DOC "OSX Package builder (pkgbuild)")
mark_as_advanced(PKGBUILD_EXECUTABLE)
find_program(PRODUCTBUILD_EXECUTABLE
NAMES productbuild
DOC "OSX Package builder (productbuild)")
mark_as_advanced(PRODUCTBUILD_EXECUTABLE)
add_custom_command(OUTPUT ${LIBIIO_TEMP_PKG} COMMAND ${PKGBUILD_EXECUTABLE}
--root ${CMAKE_CURRENT_BINARY_DIR}/Debug
--identifier libiio --version ${VERSION}
--install-location /System/Library/Frameworks ${LIBIIO_TEMP_PKG}
DEPENDS iio
)
add_custom_command(OUTPUT ${LIBIIO_PKG} COMMAND ${PRODUCTBUILD_EXECUTABLE}
--distribution ${LIBIIO_DISTRIBUTION_XML} ${LIBIIO_PKG}
DEPENDS ${LIBIIO_DISTRIBUTION_XML} ${LIBIIO_TEMP_PKG}
)
if (PKGBUILD_EXECUTABLE AND PRODUCTBUILD_EXECUTABLE)
add_custom_target(libiio-pkg ALL DEPENDS ${LIBIIO_PKG})
else()
message(WARNING "Missing pkgbuild or productbuild: OSX installer won't be created.")
endif()
endif()
if(WITH_IIOD)
add_subdirectory(iiod)
endif()
if(WITH_TESTS)
add_subdirectory(tests)
endif()
add_subdirectory(bindings)