File: FindBluetooth.cmake

package info (click to toggle)
obexpushd 0.10.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 488 kB
  • ctags: 562
  • sloc: ansic: 5,858; xml: 412; sh: 58; makefile: 8
file content (125 lines) | stat: -rw-r--r-- 3,504 bytes parent folder | download | duplicates (5)
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
# - Find system default bluetooth implementation
#
# On Linux it will use PkgConfig if present and supported,
# else and on all other architectures, it looks for it on its own.
# The following standard variables get defined:
#  Bluetooth_FOUND:        true if Bluetooth was found
#  Bluetooth_INCLUDE_DIRS: the directory that contains the include file
#  Bluetooth_LIBRARIES:    full path to the libraries

include ( CheckCSourceCompiles )
include ( CheckLibraryExists )
include ( CheckIncludeFile )

if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
  find_package ( PkgConfig )
  if ( PKG_CONFIG_FOUND )
    pkg_check_modules ( PKGCONFIG_BLUEZ bluez )
  endif ( PKG_CONFIG_FOUND )
  find_path ( Bluetooth_INCLUDE_DIRS
    NAMES
      bluetooth/bluetooth.h
    PATH_SUFFIXES
      include
  )
  mark_as_advanced ( Bluetooth_INCLUDE_DIRS )

  if ( PKGCONFIG_BLUEZ_FOUND )
    foreach ( i ${PKGCONFIG_BLUEZ_LIBRARIES} )
      find_library ( ${i}_LIBRARY
        NAMES
	  ${i}
        PATHS
	  ${PKGCONFIG_BLUEZ_LIBRARY_DIRS}
      )
      mark_as_advanced ( ${i}_LIBRARY )
      if ( ${i}_LIBRARY )
	list ( APPEND Bluetooth_LIBRARIES ${${i}_LIBRARY} )
      endif ( ${i}_LIBRARY )
    endforeach ( i )
    add_definitions ( -DHAVE_SDPLIB )

  else ( PKGCONFIG_BLUEZ_FOUND )
    find_library ( bluetooth_LIBRARY
      NAMES
        bluetooth
      PATH_SUFFIXES
        lib
    )
    mark_as_advanced ( bluetooth_LIBRARY )
    if ( bluetooth_LIBRARY )
      set ( Bluetooth_LIBRARIES ${bluetooth_LIBRARY} )
    endif ( bluetooth_LIBRARY )
  endif ( PKGCONFIG_BLUEZ_FOUND )
  if ( Bluetooth_INCLUDE_DIRS AND Bluetooth_LIBRARIES )
    set ( Bluetooth_FOUND true )
  endif ( Bluetooth_INCLUDE_DIRS AND Bluetooth_LIBRARIES )

elseif ( CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
  find_path ( Bluetooth_INCLUDE_DIRS
    NAMES
      bluetooth.h
    PATH_SUFFIXES
      include
  )
  mark_as_advanced ( Bluetooth_INCLUDE_DIRS )

  if ( Bluetooth_INCLUDE_DIRS )
    set ( CMAKE_REQUIRED_INCLUDES ${Bluetooth_INLUDE_DIRS} )
    CHECK_C_SOURCE_COMPILES (
      "#include <bluetooth.h>
       int main () {
         struct sockaddr_rfcomm f;
         return 0;
       }"
      Bluetooth_FOUND
    )
  endif ( Bluetooth_INCLUDE_DIRS )

elseif ( CMAKE_SYSTEM_NAME STREQUAL "NetBSD" )
  find_path ( Bluetooth_INCLUDE_DIRS
    NAMES
      bluetooth.h
    PATH_SUFFIXES
      include
  )
  mark_as_advanced ( Bluetooth_INCLUDE_DIRS )

  if ( Bluetooth_INCLUDE_DIRS )
    set ( CMAKE_REQUIRED_INCLUDES ${Bluetooth_INLUDE_DIRS} )
    CHECK_C_SOURCE_COMPILES (
      "#include <bluetooth.h>
       int main () {
         struct sockaddr_bt f;
         return 0;
       }"
      Bluetooth_FOUND
    )    
  endif ( Bluetooth_INCLUDE_DIRS )

elseif ( WIN32 )
  CHECK_C_SOURCE_COMPILES (
    "#include <winsock2.h>
     #include <ws2bth.h>
     int main () {
       SOCKADDR_BTH f;
       return 0;
     }"
    Bluetooth_FOUND
  )    
endif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" )

if ( Bluetooth_FOUND )
  set ( Bluetooth_FOUND true )
else ( Bluetooth_FOUND )
  set ( Bluetooth_FOUND false )
endif ( Bluetooth_FOUND )

if ( NOT Bluetooth_FOUND )
  if ( NOT Bluetooth_FIND_QUIETLY )
    message ( STATUS "Bluetooth not found." )
  endif ( NOT Bluetooth_FIND_QUIETLY )
  if ( Bluetooth_FIND_REQUIRED )
    message ( FATAL_ERROR "Bluetooth not found but required." )
  endif ( Bluetooth_FIND_REQUIRED )
endif ( NOT Bluetooth_FOUND )