| 1 |
# Copyright 2012 Jared Boone |
| 2 |
# Copyright 2013/2014 Benjamin Vernoux |
| 3 |
# |
| 4 |
# This file is part of AirSpy (based on HackRF project). |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2, or (at your option) |
| 9 |
# any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; see the file COPYING. If not, write to |
| 18 |
# the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 |
# Boston, MA 02110-1301, USA. |
| 20 |
# |
| 21 |
|
| 22 |
# Based heavily upon the libftdi cmake setup. |
| 23 |
|
| 24 |
cmake_minimum_required(VERSION 2.8) |
| 25 |
project(libairspyhf C) |
| 26 |
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/airspyhf.h AIRSPYHF_H_CONTENTS) |
| 27 |
|
| 28 |
STRING(REGEX MATCH "\#define AIRSPYHF_VER_MAJOR[ \t]+([0-9]+)" AIRSPYHF_VER_MJ ${AIRSPYHF_H_CONTENTS}) |
| 29 |
STRING(REGEX MATCH "([0-9]+)" AIRSPYHF_VER_MJ ${AIRSPYHF_VER_MJ}) |
| 30 |
|
| 31 |
STRING(REGEX MATCH "\#define AIRSPYHF_VER_MINOR[ \t]+([0-9]+)" AIRSPYHF_VER_MI ${AIRSPYHF_H_CONTENTS}) |
| 32 |
STRING(REGEX MATCH "([0-9]+)" AIRSPYHF_VER_MI ${AIRSPYHF_VER_MI}) |
| 33 |
|
| 34 |
STRING(REGEX MATCH "\#define AIRSPYHF_VER_REVISION[ \t]+([0-9]+)" AIRSPYHF_VER_RE ${AIRSPYHF_H_CONTENTS}) |
| 35 |
STRING(REGEX MATCH "([0-9]+)" AIRSPYHF_VER_RE ${AIRSPYHF_VER_RE}) |
| 36 |
|
| 37 |
set(AIRSPYHF_VER_MAJOR ${AIRSPYHF_VER_MJ}) |
| 38 |
set(AIRSPYHF_VER_MINOR ${AIRSPYHF_VER_MI}) |
| 39 |
set(AIRSPYHF_VER_REVISION ${AIRSPYHF_VER_RE}) |
| 40 |
|
| 41 |
set(PACKAGE libairspyhf) |
| 42 |
set(VERSION_STRING ${AIRSPYHF_VER_MAJOR}.${AIRSPYHF_VER_MINOR}) |
| 43 |
set(VERSION ${VERSION_STRING}) |
| 44 |
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules) |
| 45 |
set(CMAKE_C_FLAGS_RELEASE "-O3") |
| 46 |
set(CMAKE_BUILD_TYPE Release) |
| 47 |
|
| 48 |
if(APPLE) |
| 49 |
set(GR_LIBRARY_DIR "lib") |
| 50 |
if(NOT CMAKE_INSTALL_NAME_DIR) |
| 51 |
set(CMAKE_INSTALL_NAME_DIR |
| 52 |
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE |
| 53 |
PATH "Library Install Name Destination Directory" FORCE) |
| 54 |
endif(NOT CMAKE_INSTALL_NAME_DIR) |
| 55 |
if(NOT CMAKE_INSTALL_RPATH) |
| 56 |
set(CMAKE_INSTALL_RPATH |
| 57 |
${CMAKE_INSTALL_PREFIX}/${GR_LIBRARY_DIR} CACHE |
| 58 |
PATH "Library Install RPath" FORCE) |
| 59 |
endif(NOT CMAKE_INSTALL_RPATH) |
| 60 |
if(NOT CMAKE_BUILD_WITH_INSTALL_RPATH) |
| 61 |
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE |
| 62 |
BOOL "Do Build Using Library Install RPath" FORCE) |
| 63 |
endif(NOT CMAKE_BUILD_WITH_INSTALL_RPATH) |
| 64 |
endif(APPLE) |
| 65 |
|
| 66 |
if(MSVC) |
| 67 |
set(THREADS_USE_PTHREADS_WIN32 true) |
| 68 |
else() |
| 69 |
add_definitions(-Wall) |
| 70 |
|
| 71 |
INCLUDE(TestBigEndian) |
| 72 |
TEST_BIG_ENDIAN(BIGENDIAN) |
| 73 |
if(${BIGENDIAN}) |
| 74 |
add_definitions(-DAIRSPYHF_BIG_ENDIAN) |
| 75 |
endif(${BIGENDIAN}) |
| 76 |
endif() |
| 77 |
find_package(USB1 REQUIRED) |
| 78 |
find_package(Threads REQUIRED) |
| 79 |
|
| 80 |
include_directories(${LIBUSB_INCLUDE_DIR} ${THREADS_PTHREADS_INCLUDE_DIR}) |
| 81 |
|
| 82 |
add_subdirectory(src) |
| 83 |
|
| 84 |
######################################################################## |
| 85 |
# Create Pkg Config File |
| 86 |
######################################################################## |
| 87 |
FOREACH(inc ${LIBUSB_INCLUDE_DIR}) |
| 88 |
LIST(APPEND AIRSPYHF_PC_CFLAGS "-I${inc}") |
| 89 |
ENDFOREACH(inc) |
| 90 |
|
| 91 |
# use space-separation format for the pc file |
| 92 |
STRING(REPLACE ";" " " AIRSPYHF_PC_CFLAGS "${AIRSPYHF_PC_CFLAGS}") |
| 93 |
STRING(REPLACE ";" " " AIRSPYHF_PC_LIBS "${AIRSPYHF_PC_LIBS}") |
| 94 |
|
| 95 |
# unset these vars to avoid hard-coded paths to cross environment |
| 96 |
IF(CMAKE_CROSSCOMPILING) |
| 97 |
UNSET(AIRSPYHF_PC_CFLAGS) |
| 98 |
UNSET(AIRSPYHF_PC_LIBS) |
| 99 |
ENDIF(CMAKE_CROSSCOMPILING) |
| 100 |
|
| 101 |
set(prefix ${CMAKE_INSTALL_PREFIX}) |
| 102 |
set(exec_prefix \${prefix}) |
| 103 |
set(libdir \${exec_prefix}/lib${LIB_SUFFIX}) |
| 104 |
set(includedir \${prefix}/include) |
| 105 |
|
| 106 |
CONFIGURE_FILE( |
| 107 |
${CMAKE_CURRENT_SOURCE_DIR}/libairspyhf.pc.in |
| 108 |
${CMAKE_CURRENT_BINARY_DIR}/libairspyhf.pc |
| 109 |
@ONLY) |
| 110 |
|
| 111 |
INSTALL( |
| 112 |
FILES ${CMAKE_CURRENT_BINARY_DIR}/libairspyhf.pc |
| 113 |
DESTINATION lib${LIB_SUFFIX}/pkgconfig |
| 114 |
) |
| 115 |
|
| 116 |
######################################################################## |
| 117 |
# Create uninstall target |
| 118 |
######################################################################## |
| 119 |
if(NOT airspyhf_all_SOURCE_DIR) |
| 120 |
configure_file( |
| 121 |
${PROJECT_SOURCE_DIR}/../cmake/cmake_uninstall.cmake.in |
| 122 |
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake |
| 123 |
@ONLY) |
| 124 |
|
| 125 |
add_custom_target(uninstall |
| 126 |
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake |
| 127 |
) |
| 128 |
endif() |