Commit 9c05e853 authored by Jakob Bornecrantz's avatar Jakob Bornecrantz

build: Refactor flags and definitions (and fix fallout)

Defines:
* XRT_HAVE_[name] is a external dep indicator.
* XRT_DRIVER_[name] if a internal driver is built.

CMake variables:
* BUILD_WITH_[name] is a external dep indicator.
* BUILD_DRIVER_[name] tells if we should build a specific driver.
parent 831b52f7
Pipeline #33850 passed with stages
in 43 seconds
......@@ -26,26 +26,15 @@ find_package(HIDAPI)
find_package(OpenHMD)
find_package(OpenCV)
# Export OpenCV definition if found
if(OpenCV_FOUND)
add_definitions(-DXRT_HAVE_OPENCV)
endif()
# @TODO Turn into a find_package LIBUSB-1.0 file.
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
add_definitions(-DXRT_HAVE_LIBUSB)
# @TODO Turn into a find_package LIBUVC file.
pkg_check_modules(LIBUVC libuvc)
if(LIBUVC_FOUND)
add_definitions(-DXRT_HAVE_LIBUVC)
endif()
# @TODO Turn into a find_package FFMPEG file.
pkg_check_modules(FFMPEG libavcodec)
if(FFMPEG_FOUND)
add_definitions(-DXRT_HAVE_FFMPEG)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(X11)
......@@ -53,11 +42,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
pkg_check_modules(XCB xcb xcb-randr)
endif()
cmake_dependent_option(BUILD_WITH_OPENHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_HIDAPI "Enable HIDAPI-based OSVR HDK driver" ON "HIDAPI_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_XLIB "Enable xlib support" ON "X11_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_OPENGL "Enable OpenGL Graphics API support?" ON "OPENGL_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_OPENGL "Enable OpenGL Graphics API support" ON "OPENGL_FOUND" OFF)
set(BUILD_WITH_LIBUSB TRUE)
cmake_dependent_option(BUILD_WITH_OPENCV "Enable OpenCV backend" ON "OpenCV_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_LIBUVC "Enable libuvc video driver" ON "LIBUVC_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_FFMPEG "Enable ffmpeg testing video driver" ON "FFMPEG_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_HIDAPI "Enable HIDAPI-based driver(s) (OSVR HDK)" ON "HIDAPI_FOUND" OFF)
cmake_dependent_option(BUILD_WITH_OPENHMD "Enable OpenHMD driver" ON "OPENHMD_FOUND" OFF)
###
# Error checking
###
if(NOT BUILD_WITH_OPENHMD AND NOT BUILD_WITH_HIDAPI)
message(FATAL_ERROR "You must enable at least one driver: either provide OpenHMD and enable BUILD_WITH_OPENHMD (for a variety of devices via OpenHMD), or provide HIDAPI and enable BUILD_WITH_HIDAPI (for the HDK driver)")
......@@ -68,6 +67,38 @@ endif()
# Flags
###
if(BUILD_WITH_LIBUSB)
add_definitions(-DXRT_HAVE_LIBUSB)
endif()
if(BUILD_WITH_OPENCV)
add_definitions(-DXRT_HAVE_OPENCV)
endif()
if(BUILD_WITH_LIBUVC)
add_definitions(-DXRT_HAVE_LIBUVC)
endif()
if(BUILD_WITH_FFMPEG)
add_definitions(-DXRT_HAVE_FFMPEG)
endif()
if(BUILD_WITH_OPENHMD)
add_definitions(-DXRT_HAVE_OPENHMD)
# Drivers enabled with OpenHMD.
add_definitions(-DXRT_BUILD_OHMD)
set(BUILD_DRIVER_OHMD TRUE)
endif()
if(BUILD_WITH_HIDAPI)
add_definitions(-DXRT_HAVE_HIDAPI)
# Drivers enabled with hidapi.
add_definitions(-DXRT_BUILD_HDK)
set(BUILD_DRIVER_HDK TRUE)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wall -Wextra -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
......
......@@ -12,11 +12,11 @@
#include <stdlib.h>
#include "xrt/xrt_prober.h"
#ifdef XRT_HAVE_OHMD
#ifdef XRT_BUILD_OHMD
#include "ohmd/oh_interface.h"
#endif
#ifdef XRT_HAVE_HDK
#ifdef XRT_BUILD_HDK
#include "hdk/hdk_interface.h"
#endif
......@@ -29,12 +29,12 @@ extern "C" {
typedef struct xrt_prober *(*prober_creator)();
static const prober_creator DRIVERS[] = {
#ifdef XRT_HAVE_HDK
#ifdef XRT_BUILD_HDK
// Returns NULL if none found, so OK to go first.
hdk_create_prober,
#endif
#ifdef XRT_HAVE_OHMD
#ifdef XRT_BUILD_OHMD
oh_create_prober,
#endif
......
# Copyright 2019, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../auxiliary
)
set(OHMD_SOURCE_FILES
ohmd/oh_device.c
ohmd/oh_device.h
ohmd/oh_interface.h
ohmd/oh_prober.c
)
# Use OBJECT to not create a archive, since it just gets in the way.
add_library(drv_ohmd OBJECT ${OHMD_SOURCE_FILES})
set_property(TARGET drv_ohmd PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(drv_ohmd SYSTEM
PRIVATE ${OPENHMD_INCLUDE_DIRS}
)
if(BUILD_WITH_HIDAPI)
if(BUILD_DRIVER_HDK)
set(HDK_SOURCE_FILES
hdk/hdk_device.cpp
hdk/hdk_device.h
......@@ -35,3 +23,20 @@ if(BUILD_WITH_HIDAPI)
PRIVATE ${HIDAPI_INCLUDE_DIRS}
)
endif()
if(BUILD_DRIVER_OHMD)
set(OHMD_SOURCE_FILES
ohmd/oh_device.c
ohmd/oh_device.h
ohmd/oh_interface.h
ohmd/oh_prober.c
)
# Use OBJECT to not create a archive, since it just gets in the way.
add_library(drv_ohmd OBJECT ${OHMD_SOURCE_FILES})
set_property(TARGET drv_ohmd PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(drv_ohmd SYSTEM
PRIVATE ${OPENHMD_INCLUDE_DIRS}
)
endif()
......@@ -76,16 +76,14 @@ target_link_libraries(${RUNTIME_TARGET}
)
if(BUILD_WITH_OPENHMD)
if(BUILD_DRIVER_OHMD)
target_sources(${RUNTIME_TARGET} PRIVATE $<TARGET_OBJECTS:drv_ohmd>)
target_compile_definitions(${RUNTIME_TARGET} PRIVATE XRT_HAVE_OHMD)
target_link_libraries(${RUNTIME_TARGET} PRIVATE OpenHMD::OpenHMD)
endif()
if(BUILD_WITH_HIDAPI)
if(BUILD_DRIVER_HDK)
target_sources(${RUNTIME_TARGET} PRIVATE $<TARGET_OBJECTS:drv_hdk>)
target_link_libraries(${RUNTIME_TARGET} PUBLIC ${HIDAPI_LIBRARIES})
target_compile_definitions(${RUNTIME_TARGET} PRIVATE XRT_HAVE_HDK)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment