1cmake_minimum_required(VERSION 2.8.7)
2project(iiod C)
3
4include(FindBISON)
5include(FindFLEX)
6
7flex_target(lexer
8	${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
9bison_target(parser
10	${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c)
11add_flex_bison_dependency(lexer parser)
12include_directories(${CMAKE_CURRENT_BINARY_DIR})
13include_directories(${CMAKE_CURRENT_SOURCE_DIR})
14
15set(IIOD_CFILES iiod.c ops.c thread-pool.c ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})
16
17find_library(LIBAIO_LIBRARIES aio)
18find_path(LIBAIO_INCLUDE_DIR libaio.h)
19
20if (LIBAIO_LIBRARIES AND LIBAIO_INCLUDE_DIR)
21	option(ENABLE_AIO "Build IIOD with async. I/O support" ON)
22endif ()
23
24include(CheckTypeSize)
25set(CMAKE_EXTRA_INCLUDE_FILES linux/usb/functionfs.h)
26check_type_size("struct usb_functionfs_descs_head_v2" FUNCTIONFS_V2)
27set(CMAKE_EXTRA_INCLUDE_FILES)
28
29if (HAVE_FUNCTIONFS_V2)
30	OPTION(WITH_IIOD_USBD "Add support for USB through FunctionFS within IIOD" ${ENABLE_AIO})
31
32	if (WITH_IIOD_USBD)
33		if (NOT ENABLE_AIO)
34			message(SEND_ERROR "USB support in IIOD requires async. I/O support")
35		endif (NOT ENABLE_AIO)
36
37		set(IIOD_CFILES ${IIOD_CFILES} usbd.c)
38	endif (WITH_IIOD_USBD)
39endif (HAVE_FUNCTIONFS_V2)
40
41include(CheckSymbolExists)
42set(CMAKE_REQUIRED_LIBRARIES ${PTHREAD_LIBRARIES})
43check_symbol_exists(pthread_setname_np "pthread.h" HAS_PTHREAD_SETNAME_NP)
44set(CMAKE_REQUIRED_LIBRARIES)
45
46add_executable(iiod ${IIOD_CFILES})
47set_target_properties(iiod PROPERTIES
48	C_STANDARD 99
49	C_STANDARD_REQUIRED ON
50	C_EXTENSIONS OFF
51)
52target_link_libraries(iiod iio ${PTHREAD_LIBRARIES} ${AVAHI_LIBRARIES})
53
54if (ENABLE_AIO)
55	add_definitions(-DWITH_AIO=1)
56	include_directories(${LIBAIO_INCLUDE_DIR})
57	target_link_libraries(iiod ${LIBAIO_LIBRARIES})
58endif ()
59
60add_definitions(-D_GNU_SOURCE=1)
61
62if(NOT SKIP_INSTALL_ALL)
63	install(TARGETS iiod RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
64endif()
65
66if (WITH_SYSTEMD)
67	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.service.cmakein ${PROJECT_BINARY_DIR}/init/iiod.service)
68	install(FILES ${PROJECT_BINARY_DIR}/init/iiod.service DESTINATION ${SYSTEMD_UNIT_INSTALL_DIR})
69endif()
70
71if (WITH_SYSVINIT)
72	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.init.cmakein ${PROJECT_BINARY_DIR}/init/iiod)
73	install(FILES ${PROJECT_BINARY_DIR}/init/iiod
74	        PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
75	        DESTINATION ${SYSVINIT_INSTALL_DIR})
76endif()
77
78if (WITH_UPSTART)
79	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/init/iiod.conf.cmakein ${PROJECT_BINARY_DIR}/init/iiod.conf)
80	install(FILES ${PROJECT_BINARY_DIR}/init/iiod.conf DESTINATION ${UPSTART_CONF_INSTALL_DIR})
81endif()
82