1 # Copyright 2012 OSMOCOM Project
3 # This file is part of rtl-sdr
5 # GNU Radio is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
10 # GNU Radio is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Radio; see the file COPYING. If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street,
18 # Boston, MA 02110-1301, USA.
21 ########################################################################
23 ########################################################################
24 cmake_minimum_required(VERSION 2.6)
27 #select the release build type by default to get optimization flags
28 if(NOT CMAKE_BUILD_TYPE)
29 set(CMAKE_BUILD_TYPE "Release")
30 message(STATUS "Build type not specified: defaulting to release.")
31 endif(NOT CMAKE_BUILD_TYPE)
32 set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
34 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
36 ########################################################################
37 # Compiler specific setup
38 ########################################################################
39 if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
40 ADD_DEFINITIONS(-Wall)
41 ADD_DEFINITIONS(-Wextra)
42 ADD_DEFINITIONS(-Wno-unused)
43 ADD_DEFINITIONS(-Wsign-compare)
44 ADD_DEFINITIONS(-g3 -O0)
45 #http://gcc.gnu.org/wiki/Visibility
46 add_definitions(-fvisibility=hidden)
49 ########################################################################
50 # Find build dependencies
51 ########################################################################
52 find_package(PkgConfig)
54 set(THREADS_USE_PTHREADS_WIN32 true)
58 message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr")
61 message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr")
63 ########################################################################
64 # Setup the include and linker paths
65 ########################################################################
67 ${CMAKE_SOURCE_DIR}/include
69 ${THREADS_PTHREADS_INCLUDE_DIR}
76 # Set component parameters
77 #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
79 ########################################################################
80 # Create uninstall target
81 ########################################################################
83 ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
84 ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
87 add_custom_target(uninstall
88 ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
91 ########################################################################
93 ########################################################################
94 option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF)
95 if (INSTALL_UDEV_RULES)
98 DESTINATION "/etc/udev/rules.d"
101 else (INSTALL_UDEV_RULES)
102 message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON")
103 endif (INSTALL_UDEV_RULES)
105 ########################################################################
107 ########################################################################
108 add_subdirectory(include)
109 add_subdirectory(src)
111 ########################################################################
112 # Create Pkg Config File
113 ########################################################################
114 FOREACH(inc ${LIBUSB_INCLUDE_DIR})
115 LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}")
118 FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
119 LIST(APPEND RTLSDR_PC_LIBS "-L${lib}")
122 # use space-separation format for the pc file
123 STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}")
124 STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}")
126 # unset these vars to avoid hard-coded paths to cross environment
127 IF(CMAKE_CROSSCOMPILING)
128 UNSET(RTLSDR_PC_CFLAGS)
129 UNSET(RTLSDR_PC_LIBS)
130 ENDIF(CMAKE_CROSSCOMPILING)
132 set(prefix ${CMAKE_INSTALL_PREFIX})
133 set(exec_prefix \${prefix})
134 set(libdir \${exec_prefix}/lib)
135 set(includedir \${prefix}/include)
138 ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in
139 ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
143 FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
144 DESTINATION lib/pkgconfig