xref: /libbtbb/lib/src/CMakeLists.txt (revision a3bcbc61038727a7f4463175808dbe5ee20e3209)
1#
2# This file is part of Libbtbb.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; see the file COPYING.  If not, write to
16# the Free Software Foundation, Inc., 51 Franklin Street,
17# Boston, MA 02110-1301, USA.
18#
19# Based slightly upon the hackrf cmake setup.
20
21# FIXME Set static release version here to avoid pulling from git
22set(RELEASE "")
23set(DIRTY_FLAG "")
24
25if ( "${RELEASE}" STREQUAL "" )
26	# automatic git version when working out of git
27	include(GetGitRevisionDescription)
28	get_git_head_revision(GIT_REFSPEC RELEASE)
29
30	execute_process(COMMAND git status -s --untracked-files=no OUTPUT_VARIABLE DIRTY)
31	if ( NOT "${DIRTY}" STREQUAL "" )
32		set(DIRTY_FLAG "*")
33	endif()
34endif()
35
36add_definitions( -DRELEASE="${RELEASE}${DIRTY_FLAG}" )
37message(STATUS "Setting version string ${RELEASE}${DIRTY_FLAG}")
38
39# Source
40set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth_packet.c
41              ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth_piconet.c
42              ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth_le_packet.c
43              ${CMAKE_CURRENT_SOURCE_DIR}/companies.c
44              ${CMAKE_CURRENT_SOURCE_DIR}/pcap.c
45              ${CMAKE_CURRENT_SOURCE_DIR}/pcapng.c
46              ${CMAKE_CURRENT_SOURCE_DIR}/pcapng-bt.c
47			  CACHE INTERNAL "List of C sources")
48set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/btbb.h
49			  CACHE INTERNAL "List of C headers")
50
51if( NOT ${BUILD_SHARED_LIB} AND NOT ${BUILD_STATIC} )
52	message( FATAL_ERROR "Not building static or shared library - at least one must be built")
53endif( NOT ${BUILD_SHARED_LIB} AND NOT ${BUILD_STATIC} )
54
55set(CMAKE_MACOSX_RPATH 1)
56
57if( ${BUILD_SHARED_LIB} )
58    # Shared library
59    message(STATUS "Building shared library")
60    add_library(btbb SHARED ${c_sources})
61    set_target_properties(btbb PROPERTIES VERSION ${MAJOR_VERSION}.${MINOR_VERSION} SOVERSION 1)
62    set_target_properties(btbb PROPERTIES CLEAN_DIRECT_OUTPUT 1)
63    install(TARGETS btbb
64            LIBRARY DESTINATION lib${LIB_SUFFIX}
65            COMPONENT sharedlibs)
66endif( ${BUILD_SHARED_LIB} )
67
68if( ${BUILD_STATIC_LIB} )
69    # Static library
70    message(STATUS "Building static library")
71    add_library(btbb-static STATIC ${c_sources})
72    set_target_properties(btbb-static PROPERTIES OUTPUT_NAME "btbb")
73    set_target_properties(btbb-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
74    install(TARGETS btbb-static
75            DESTINATION lib${LIB_SUFFIX}
76            COMPONENT staticlibs)
77endif( ${BUILD_STATIC_LIB} )
78
79install(FILES ${c_headers}
80        DESTINATION include
81        COMPONENT headers
82        )
83