From 428d1624fa08ac815a23f6f0a38dc20eb036033e Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 8 Feb 2017 00:29:34 +0100 Subject: [PATCH] cmake: Move BlueZ detection to Core --- CMakeLists.txt | 13 ---------- CMakeTests/FindBlueZ.cmake | 42 +++++++++++++++++++++++++++++++++ Source/Core/Core/CMakeLists.txt | 21 +++++++++++++---- 3 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 CMakeTests/FindBlueZ.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c31cd66990..1eee549f22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -436,19 +436,6 @@ if (OPENGL_GL) include_directories(${OPENGL_INCLUDE_DIR}) endif() -if(ENABLE_BLUEZ) - check_lib(BLUEZ bluez bluez QUIET) - if(BLUEZ_FOUND) - add_definitions(-DHAVE_BLUEZ=1) - message(STATUS "bluez found, enabling bluetooth support") - else() - add_definitions(-DHAVE_BLUEZ=0) - message(STATUS "bluez NOT found, disabling bluetooth support") - endif() -else() - message(STATUS "bluez explicitly disabled, disabling bluetooth support") -endif() - if(ENABLE_LLVM) find_package(LLVM) if (LLVM_FOUND) diff --git a/CMakeTests/FindBlueZ.cmake b/CMakeTests/FindBlueZ.cmake new file mode 100644 index 0000000000..b82e7bdb0f --- /dev/null +++ b/CMakeTests/FindBlueZ.cmake @@ -0,0 +1,42 @@ +# - Find BlueZ library +# This module defines +# BlueZ_INCLUDE_DIR +# BlueZ_LIBRARIES +# BlueZ_FOUND +# +# vim: expandtab sw=4 ts=4 sts=4: + +include(FindPkgConfig) +pkg_check_modules (BlueZ_PKG QUIET bluez) + +find_path(BlueZ_INCLUDE_DIR NAMES bluetooth/bluetooth.h + PATHS + ${BlueZ_PKG_INCLUDE_DIRS} + /usr/include/bluetooth + /usr/include + /usr/local/include/bluetooth + /usr/local/include +) + +find_library(BlueZ_LIBRARIES NAMES bluetooth + PATHS + ${BlueZ_PKG_LIBRARY_DIRS} + /usr/lib + /usr/local/lib +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BlueZ + REQUIRED_VARS BlueZ_LIBRARIES BlueZ_INCLUDE_DIR) + +if(BlueZ_FOUND) + if(NOT TARGET BlueZ::BlueZ) + add_library(BlueZ::BlueZ UNKNOWN IMPORTED) + set_target_properties(BlueZ::BlueZ PROPERTIES + IMPORTED_LOCATION ${BlueZ_LIBRARIES} + INTERFACE_INCLUDE_DIRECTORIES ${BlueZ_INCLUDE_DIR} + ) + endif() +endif() + +mark_as_advanced(BlueZ_INCLUDE_DIR BlueZ_LIBRARIES) diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 166eb158bf..68eacfc3ed 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -294,13 +294,26 @@ elseif(APPLE) ${IOB_LIBRARY}) elseif(UNIX) set(SRCS ${SRCS} HW/EXI/BBA-TAP/TAP_Unix.cpp) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND BLUEZ_FOUND) - set(SRCS ${SRCS} HW/WiimoteReal/IOLinux.cpp) - set(LIBS ${LIBS} bluetooth) - elseif(ANDROID) + if(ANDROID) set(SRCS ${SRCS} HW/WiimoteReal/IOAndroid.cpp) endif() endif() + +# Bluez doesn't support all the communication modes on FreeBSD, so only using it on Linux +if(ENABLE_BLUEZ AND CMAKE_SYSTEM_NAME MATCHES "Linux") + find_package(BlueZ) + if(BLUEZ_FOUND) + message(STATUS "BlueZ found, enabling bluetooth support") + set(SRCS ${SRCS} HW/WiimoteReal/IOLinux.cpp) + set(LIBS ${LIBS} BlueZ::BlueZ) + add_definitions(-DHAVE_BLUEZ=1) + else() + message(STATUS "BlueZ NOT found, disabling bluetooth support") + endif() +else() + message(STATUS "BlueZ explicitly disabled, disabling bluetooth support") +endif() + if(HIDAPI_FOUND) set(SRCS ${SRCS} HW/WiimoteReal/IOhidapi.cpp) endif()