Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake scripts cleanups #680

Merged
merged 8 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CI/build_win.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ $src_dir=$pwd
mkdir build
cd build

cmake -G "$COMPILER" -A "$ARCH" -DPYTHON_BINDINGS=ON -DLIBXML2_LIBRARIES="$src_dir\deps\lib\libxml2.dll.a" ..
cmake -G "$COMPILER" -A "$ARCH" -DENABLE_IPV6=OFF -DWITH_USB_BACKEND=OFF -DWITH_SERIAL_BACKEND=OFF -DPYTHON_BINDINGS=ON -DLIBXML2_LIBRARIES="$src_dir\deps\lib\libxml2.dll.a" ..
cmake --build . --config Release
2 changes: 1 addition & 1 deletion CI/travis/before_install_darwin
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

. CI/travis/lib.sh

brew_install_if_not_exists cmake doxygen libusb libxml2 ncurses cdk
brew_install_if_not_exists cmake doxygen libusb libxml2 ncurses cdk zstd
4 changes: 2 additions & 2 deletions CI/travis/before_install_linux
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ handle_centos() {
# FIXME: see about adding `libserialport-dev` from EPEL ; maybe libusb-1.0.0-devel...
yum -y groupinstall 'Development Tools'
yum -y install cmake libxml2-devel libusb1-devel libaio-devel \
bzip2 gzip rpm rpm-build
bzip2 gzip rpm rpm-build libzstd-devel

if [ "$(get_version | head -c 1)" = "7" ] ; then
# install Cmake3, and make it the default
Expand Down Expand Up @@ -66,7 +66,7 @@ handle_generic_docker() {
handle_default() {
sudo apt-get -qq update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y cmake graphviz \
libaio-dev libavahi-client-dev libserialport-dev \
libaio-dev libavahi-client-dev libserialport-dev libzstd-dev \
libavahi-common-dev libusb-1.0-0-dev libxml2-dev rpm tar \
bzip2 gzip flex bison git libncurses5-dev libcdk5-dev \
doxygen man2html python3 python3-pip python3-setuptools
Expand Down
6 changes: 4 additions & 2 deletions CI/travis/make_darwin
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh -e

LIBIIO_BUILD_CONF="-DWITH_SERIAL_BACKEND=OFF -DWITH_ZSTD=ON"

if [ "x${COVERITY_SCAN_PROJECT_NAME}" != "x" ] ; then exit 0; fi


Expand All @@ -18,13 +20,13 @@ build_osx() {
mkdir -p build

cd build
build_osx "-DOSX_PACKAGE=ON -DPYTHON_BINDINGS=ON -DWITH_EXAMPLES=ON"
build_osx "-DOSX_PACKAGE=ON -DPYTHON_BINDINGS=ON -DWITH_EXAMPLES=ON ${LIBIIO_BUILD_CONF}"

cd ..

mkdir -p build_tar
cd build_tar
build_osx "-DOSX_PACKAGE=OFF -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON"
build_osx "-DOSX_PACKAGE=OFF -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON ${LIBIIO_BUILD_CONF}"
echo "### make package"
make package
echo "### files are"
Expand Down
15 changes: 14 additions & 1 deletion CI/travis/make_linux
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ handle_default() {

FLAGS="-DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON -DWITH_EXAMPLES=ON ${PYTHON_HELP} ${DOC_HELP} ${MAN_HELP}"

# Ubuntu Xenial's libserialport and libzstd are too old
if [ "${OS_VERSION}" = xenial ] ; then
FLAGS="${FLAGS} -DWITH_SERIAL_BACKEND=OFF"
else
FLAGS="${FLAGS} -DWITH_ZSTD=ON"
fi

echo "### cmake ${FLAGS}"
cmake ${FLAGS} ..

Expand Down Expand Up @@ -103,7 +110,13 @@ handle_centos() {
echo "handle centos"
mkdir -p build
cd build
cmake -DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON ..

FLAGS="-DENABLE_PACKAGING=ON -DPYTHON_BINDINGS=ON -DWITH_SERIAL_BACKEND=OFF -DWITH_ZSTD=ON"

# CentOS 7's kernel headers are too old for USB support in IIOD
[ "${OS_VERSION}" = centos7 ] && FLAGS="${FLAGS} -DWITH_IIOD_USBD=OFF"

cmake ${FLAGS} ..
make
make package
cd ..
Expand Down
190 changes: 96 additions & 94 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (NOT CMAKE_BUILD_TYPE)
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(BUILD_SHARED_LIBS "Build shared libraries" ON)

if (NOT BUILD_SHARED_LIBS)
add_definitions(-DLIBIIO_STATIC=1)
Expand Down Expand Up @@ -120,9 +120,6 @@ endif()
if(APPLE)
#full Single Unix Standard v3 (SUSv3) conformance (the Unix API)
add_definitions(-D_DARWIN_C_SOURCE)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE=1")
add_definitions(-D_GNU_SOURCE=1)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|DragonFly|OpenBSD|NetBSD")
set(CMAKE_REQUIRED_DEFINITIONS "-D__BSD_VISIBLE")
add_definitions(-D__BSD_VISIBLE=1)
Expand All @@ -135,29 +132,25 @@ check_symbol_exists(strndup "string.h" HAS_STRNDUP)
check_symbol_exists(strerror_r "string.h" HAS_STRERROR_R)
check_symbol_exists(newlocale "locale.h" HAS_NEWLOCALE)

if (NOT WIN32)
find_library(PTHREAD_LIBRARIES pthread)
set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES})
check_symbol_exists(pthread_setname_np "pthread.h" HAS_PTHREAD_SETNAME_NP)
set(CMAKE_REQUIRED_LIBRARIES)
endif()

option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
if (ENABLE_IPV6)
check_symbol_exists(in6addr_any "netinet/in.h" HAVE_IPV6)
if (NOT HAVE_IPV6)
message(WARNING "IPv6 is not available in your system.")
message(SEND_ERROR "IPv6 is not available in your system.")
endif()
endif()

#Handle FreeBSD libusb and Linux libusb-1.0 libraries
find_library(LIBUSB_LIBRARIES NAMES usb-1.0 usb)
find_path(LIBUSB_INCLUDE_DIR libusb.h PATH_SUFFIXES libusb-1.0)
if (LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIR)
message(STATUS "Looking for libusb-1.0 : Found")
option(WITH_USB_BACKEND "Enable the libusb backend" ON)
option(WITH_USB_BACKEND "Enable the libusb backend" ON)
if (WITH_USB_BACKEND)
#Handle FreeBSD libusb and Linux libusb-1.0 libraries
find_library(LIBUSB_LIBRARIES NAMES usb-1.0 usb)
find_path(LIBUSB_INCLUDE_DIR libusb.h PATH_SUFFIXES libusb-1.0)
if (NOT LIBUSB_LIBRARIES OR NOT LIBUSB_INCLUDE_DIR)
message(SEND_ERROR "Unable to find libusb-1.0 dependency.\n"
"If you want to disable the USB backend, set WITH_USB_BACKEND=OFF.")
else()
message(STATUS "Looking for libusb-1.0 : Found")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you can disregard my previous comment 👍

if(WITH_USB_BACKEND)
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)
set(NEED_THREADS 1)
Expand All @@ -168,13 +161,10 @@ if (LIBUSB_LIBRARIES AND LIBUSB_INCLUDE_DIR)
set(TEMP1 ${CMAKE_REQUIRED_INCLUDES})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBUSB_LIBRARIES})
list(APPEND CMAKE_REQUIRED_INCLUDES ${LIBUSB_INCLUDE_DIR})
check_symbol_exists(libusb_get_version libusb.h
HAS_LIBUSB_GETVERSION)
check_symbol_exists(libusb_get_version libusb.h HAS_LIBUSB_GETVERSION)
set(CMAKE_REQUIRED_LIBRARIES ${TEMP})
set(CMAKE_REQUIRED_INCLUDES ${TEMP1})
set(CMAKE_REQUIRED_INCLUDES ${TEMP1})
endif()
else()
message(STATUS "Looking for libusb-1.0 : Failed; building without usb")
endif()

# make sure all check_symbol_exists are before this point, otherwise they fail
Expand Down Expand Up @@ -260,31 +250,31 @@ if(WITH_LOCAL_BACKEND)
endif()
endif()

find_library(LIBSERIALPORT_LIBRARIES serialport)
find_path(LIBSERIALPORT_INCLUDE_DIR libserialport.h)
if (LIBSERIALPORT_LIBRARIES AND LIBSERIALPORT_INCLUDE_DIR)
option(WITH_SERIAL_BACKEND "Enable the serial backend" ON)
option(WITH_SERIAL_BACKEND "Enable the serial backend" ON)
if (WITH_SERIAL_BACKEND)
find_library(LIBSERIALPORT_LIBRARIES serialport)
find_path(LIBSERIALPORT_INCLUDE_DIR libserialport.h)
if (NOT LIBSERIALPORT_LIBRARIES OR NOT LIBSERIALPORT_INCLUDE_DIR)
message(SEND_ERROR "Unable to find libserialport dependency.\n"
"If you want to disable the serial backend, set WITH_SERIAL_BACKEND=OFF.")
else()
message(STATUS "Looking for libserialport : Found")

if (WITH_SERIAL_BACKEND)
file(STRINGS ${LIBSERIALPORT_INCLUDE_DIR}/libserialport.h LIBSERIALPORT_VERSION_STR REGEX "SP_PACKAGE_VERSION_STRING")
string(REGEX REPLACE "#define SP_PACKAGE_VERSION_STRING \"(.*)\"" "\\1" LIBSERIALPORT_VERSION ${LIBSERIALPORT_VERSION_STR})
if ("${LIBSERIALPORT_VERSION}" VERSION_LESS 0.1.1)
message(WARNING "The installed version of libserialport is too old. The minimum version supported is 0.1.1. Disabling Serial support.")
SET(WITH_SERIAL_BACKEND OFF)
else()
message(STATUS "Looking for libserialport : Found")
list(APPEND LIBIIO_CFILES serial.c)
list(APPEND LIBS_TO_LINK ${LIBSERIALPORT_LIBRARIES})

set(NEED_THREADS 1)
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)

include_directories(${LIBSERIALPORT_INCLUDE_DIR})
message(SEND_ERROR "The installed version of libserialport is too old. The minimum version supported is 0.1.1.")
endif()

list(APPEND LIBIIO_CFILES serial.c)
list(APPEND LIBS_TO_LINK ${LIBSERIALPORT_LIBRARIES})

set(NEED_THREADS 1)
set(IIOD_CLIENT 1)
set(NEED_LIBXML2 1)

include_directories(${LIBSERIALPORT_INCLUDE_DIR})
endif()
else()
message(STATUS "Looking for libserialport : Failed; building without serial")
endif()

option(WITH_ZSTD "Support for ZSTD compressed metadata" OFF)
Expand All @@ -293,7 +283,8 @@ if (WITH_ZSTD)
find_path(LIBZSTD_INCLUDE_DIR zstd.h)

if (NOT LIBZSTD_LIBRARIES OR NOT LIBZSTD_INCLUDE_DIR)
message(SEND_ERROR "Unable to find libzstd")
message(SEND_ERROR "Unable to find libzstd dependency.\n"
"If you want to disable ZSTD compression support, set WITH_ZSTD=OFF.")
endif()

list(APPEND LIBS_TO_LINK ${LIBZSTD_LIBRARIES})
Expand All @@ -309,12 +300,15 @@ if(WITH_NETWORK_BACKEND)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
include(CheckCSourceCompiles)
check_c_source_compiles("#include <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)

if (HAS_O_TMPFILE)
option(WITH_NETWORK_GET_BUFFER "Enable experimental zero-copy transfers" OFF)
endif(HAS_O_TMPFILE)
option(WITH_NETWORK_GET_BUFFER "Enable experimental zero-copy transfers" OFF)
if (WITH_NETWORK_GET_BUFFER)
include(CheckCSourceCompiles)
check_c_source_compiles("#include <fcntl.h>\nint main(void) { return O_TMPFILE; }" HAS_O_TMPFILE)

if (NOT HAS_O_TMPFILE)
message(SEND_ERROR "Zero-copy requires the O_TMPFILE flag, which is not available on the system.")
endif()
endif()

check_c_source_compiles("#include <sys/eventfd.h>\nint main(void) { return eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); }" WITH_NETWORK_EVENTFD)
endif()
Expand All @@ -331,34 +325,37 @@ if(WITH_NETWORK_BACKEND)
list(APPEND LIBIIO_CFILES network-unix.c)
endif()

find_library(AVAHI_CLIENT_LIBRARIES avahi-client)
find_library(AVAHI_COMMON_LIBRARIES avahi-common)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
option(HAVE_DNS_SD "Enable DNS-SD (ZeroConf) support" ON)
if (NOT HAVE_DNS_SD)
message(STATUS "Building without DNS-SD (ZeroConf) support")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(CORE_SERVICES CoreServices)

message(STATUS "Building with CFNetServices, an Apple DNS SD implementation")
set(HAVE_DNS_SD ON)

list(APPEND LIBIIO_CFILES dns_sd_bonjour.c dns_sd.c)
list(APPEND LIBS_TO_LINK ${CORE_SERVICES} )

elseif(AVAHI_CLIENT_LIBRARIES AND AVAHI_COMMON_LIBRARIES)
message(STATUS "Building with Avahi, a DNS SD implementation")
set(HAVE_DNS_SD ON)
set(HAVE_AVAHI ON)

list(APPEND LIBIIO_CFILES dns_sd_avahi.c dns_sd.c)
set(AVAHI_LIBRARIES ${AVAHI_CLIENT_LIBRARIES} ${AVAHI_COMMON_LIBRARIES})
list(APPEND LIBS_TO_LINK ${AVAHI_LIBRARIES})
elseif(WIN32)
set(HAVE_DNS_SD ON)
list(APPEND LIBIIO_CFILES dns_sd_windows.c dns_sd.c)
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_source_files_properties(dns_sd_windows.c PROPERTIES COMPILE_FLAGS "-Wno-unused-function")
endif()
message(STATUS "Building with mdns, A Public domain mDNS/DNS-SD library in C ")
else()
message(STATUS "Building without DNS-SD (Zeroconf) support")
find_library(AVAHI_CLIENT_LIBRARIES avahi-client)
find_library(AVAHI_COMMON_LIBRARIES avahi-common)
if (NOT AVAHI_CLIENT_LIBRARIES OR NOT AVAHI_COMMON_LIBRARIES)
message(SEND_ERROR "Unable to find libavahi-common / libavahi-client dependencies.\n"
"If you want to disable DNS-SD (ZeroConf) support, set HAVE_DNS_SD=OFF.")
endif()

message(STATUS "Building with Avahi, a DNS-SD (ZeroConf) implementation")
set(HAVE_AVAHI ON)

list(APPEND LIBIIO_CFILES dns_sd_avahi.c dns_sd.c)
set(AVAHI_LIBRARIES ${AVAHI_CLIENT_LIBRARIES} ${AVAHI_COMMON_LIBRARIES})
list(APPEND LIBS_TO_LINK ${AVAHI_LIBRARIES})
endif()

set(NEED_THREADS 1)
Expand All @@ -368,42 +365,47 @@ else()
message(STATUS "Building without network support")
endif()

# Since libxml2-2.9.2, libxml2 provides its own LibXml2-config.cmake, with all
# variables correctly set.
# So, try first to find the CMake module provided by libxml2 package, then fallback
# on the CMake's FindLibXml2.cmake module (which can lack some definition, especially
# in static build case).
find_package(LibXml2 QUIET NO_MODULE)
if(DEFINED LIBXML2_VERSION_STRING)
set(LIBXML2_FOUND ON)
set(LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIRS})
else()
include(FindLibXml2)
endif()

if (LIBXML2_FOUND)
option(WITH_XML_BACKEND "Enable the XML backend" ON)

if (WITH_XML_BACKEND)
list(APPEND LIBIIO_CFILES xml.c)
option(WITH_XML_BACKEND "Enable the XML backend" ON)
if (WITH_XML_BACKEND)
# Since libxml2-2.9.2, libxml2 provides its own LibXml2-config.cmake, with all
# variables correctly set.
# So, try first to find the CMake module provided by libxml2 package, then fallback
# on the CMake's FindLibXml2.cmake module (which can lack some definition, especially
# in static build case).
find_package(LibXml2 QUIET NO_MODULE)
if(DEFINED LIBXML2_VERSION_STRING)
set(LIBXML2_FOUND ON)
set(LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIRS})
else()
include(FindLibXml2)
endif()

include_directories(${LIBXML2_INCLUDE_DIR})
list(APPEND LIBS_TO_LINK ${LIBXML2_LIBRARIES})
if (NOT LIBXML2_FOUND)
message(SEND_ERROR "Unable to find libxml2 dependency.\n"
"If you want to disable the XML backend, set WITH_XML_BACKEND=OFF.")
endif()
endif()

if (NEED_LIBXML2 AND NOT (LIBXML2_FOUND AND WITH_XML_BACKEND))
message(SEND_ERROR "The selected backends require libxml2 and the XML backend to be enabled")
list(APPEND LIBIIO_CFILES xml.c)

include_directories(${LIBXML2_INCLUDE_DIR})
list(APPEND LIBS_TO_LINK ${LIBXML2_LIBRARIES})
elseif(NEED_LIBXML2)
message(SEND_ERROR "Enabled backends require the XML backend to be enabled as well.\n"
"If you want to enable the XML backend, set WITH_XML_BACKEND=ON.")
endif()

if (NEED_THREADS)
option(NO_THREADS "Disable multi-threading support" OFF)
if (NEED_THREADS AND NOT NO_THREADS)
if (NOT WIN32)
if (PTHREAD_LIBRARIES)
list(APPEND LIBS_TO_LINK ${PTHREAD_LIBRARIES})
else()
message(WARNING "pthread library not found; support for threads will be disabled")
set(NO_THREADS ON)
find_library(PTHREAD_LIBRARIES pthread)

if (NOT PTHREAD_LIBRARIES)
message(SEND_ERROR "Unable to find pthread dependency.\n"
"If you want to disable multi-threading support, set NO_THREADS=ON.")
endif()

list(APPEND LIBS_TO_LINK ${PTHREAD_LIBRARIES})
endif()

list(APPEND LIBIIO_CFILES lock.c)
Expand Down Expand Up @@ -577,8 +579,8 @@ if(WITH_IIOD)
set(UPSTART_CONF_INSTALL_DIR /etc/init CACHE PATH "default install path for upstart conf files")

if (NOT PTHREAD_LIBRARIES)
message(WARNING "IIOD requires threads support; disabling")
set(WITH_IIOD OFF CACHE BOOL "" FORCE)
message(SEND_ERROR "IIOD requires pthread support\n."
"If you want to disable IIOD, set WITH_IIOD=OFF.")
else()
add_subdirectory(iiod)
endif()
Expand Down
2 changes: 1 addition & 1 deletion iio-config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#cmakedefine01 WITH_NETWORK_EVENTFD
#cmakedefine01 WITH_IIOD_USBD
#cmakedefine01 WITH_LOCAL_CONFIG
#cmakedefine01 WITH_AIO
Copy link
Contributor

@nunojsa nunojsa May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment which has noting to do with this... We should definitely consider about replacing aio for io_uring and liburing for libiio2 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will definitely have a look at io_uring. I want to see if it can help us with zero-copy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has both ring buffers shared between kernel and userspace so that's something already in the right way... Another neat thing is that we can potential reduce a lot the number of syscalls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I assume the IIO subsystem needs to support it (does it?).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so. At least for normal reads/writes on sysfs stuff. Now for ioctl (not sure if that stuff was merged; and yes, it seems io_uring is also allowing to re-implement ioctl), the last time I checked I think IIO would have to support it...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://lwn.net/Articles/844875/ - not idea the outcome of the RFC

#cmakedefine01 HAVE_DNS_SD
#cmakedefine01 HAVE_AVAHI
#cmakedefine01 ENABLE_AIO
#cmakedefine01 WITH_ZSTD

#cmakedefine HAS_PIPE2
Expand Down
Loading