CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Copyright 2012 OSMOCOM Project
  2. #
  3. # This file is part of rtl-sdr
  4. #
  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)
  8. # any later version.
  9. #
  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.
  14. #
  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.
  19. ########################################################################
  20. # Project setup
  21. ########################################################################
  22. cmake_minimum_required(VERSION 2.6)
  23. project(rtlsdr C)
  24. #select the release build type by default to get optimization flags
  25. if(NOT CMAKE_BUILD_TYPE)
  26. set(CMAKE_BUILD_TYPE "Release")
  27. message(STATUS "Build type not specified: defaulting to release.")
  28. endif(NOT CMAKE_BUILD_TYPE)
  29. set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
  30. list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  31. if(NOT LIB_INSTALL_DIR)
  32. set(LIB_INSTALL_DIR lib)
  33. endif()
  34. # Set the version information here
  35. set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes
  36. set(VERSION_INFO_MINOR_VERSION 0) # increment minor on feature-level changes
  37. set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs
  38. include(Version) # setup version info
  39. ########################################################################
  40. # Compiler specific setup
  41. ########################################################################
  42. if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
  43. ADD_DEFINITIONS(-Wall)
  44. ADD_DEFINITIONS(-Wextra)
  45. ADD_DEFINITIONS(-Wno-unused)
  46. ADD_DEFINITIONS(-Wsign-compare)
  47. #http://gcc.gnu.org/wiki/Visibility
  48. add_definitions(-fvisibility=hidden)
  49. endif()
  50. ########################################################################
  51. # Find build dependencies
  52. ########################################################################
  53. find_package(PkgConfig)
  54. find_package(LibUSB)
  55. set(THREADS_USE_PTHREADS_WIN32 true)
  56. find_package(Threads)
  57. if(NOT LIBUSB_FOUND)
  58. message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr")
  59. endif()
  60. if(NOT THREADS_FOUND)
  61. message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr")
  62. endif()
  63. ########################################################################
  64. # Setup the include and linker paths
  65. ########################################################################
  66. include_directories(
  67. ${CMAKE_SOURCE_DIR}/include
  68. ${LIBUSB_INCLUDE_DIR}
  69. ${THREADS_PTHREADS_INCLUDE_DIR}
  70. )
  71. #link_directories(
  72. # ...
  73. #)
  74. # Set component parameters
  75. #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
  76. ########################################################################
  77. # Create uninstall target
  78. ########################################################################
  79. configure_file(
  80. ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
  81. ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  82. @ONLY)
  83. add_custom_target(uninstall
  84. ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  85. )
  86. ########################################################################
  87. # Install udev rules
  88. ########################################################################
  89. option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF)
  90. if (INSTALL_UDEV_RULES)
  91. install (
  92. FILES rtl-sdr.rules
  93. DESTINATION "/etc/udev/rules.d"
  94. COMPONENT "udev"
  95. )
  96. else (INSTALL_UDEV_RULES)
  97. message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON")
  98. endif (INSTALL_UDEV_RULES)
  99. option(DETACH_KERNEL_DRIVER "Detach kernel driver if loaded" OFF)
  100. if (DETACH_KERNEL_DRIVER)
  101. message (STATUS "Building with kernel driver detaching enabled")
  102. add_definitions(-DDETACH_KERNEL_DRIVER=1)
  103. else (DETACH_KERNEL_DRIVER)
  104. message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable")
  105. endif (DETACH_KERNEL_DRIVER)
  106. ########################################################################
  107. # Add subdirectories
  108. ########################################################################
  109. add_subdirectory(include)
  110. add_subdirectory(src)
  111. ########################################################################
  112. # Create Pkg Config File
  113. ########################################################################
  114. FOREACH(inc ${LIBUSB_INCLUDE_DIR})
  115. LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}")
  116. ENDFOREACH(inc)
  117. FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
  118. LIST(APPEND RTLSDR_PC_LIBS "-L${lib}")
  119. ENDFOREACH(lib)
  120. # use space-separation format for the pc file
  121. STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}")
  122. STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}")
  123. # unset these vars to avoid hard-coded paths to cross environment
  124. IF(CMAKE_CROSSCOMPILING)
  125. UNSET(RTLSDR_PC_CFLAGS)
  126. UNSET(RTLSDR_PC_LIBS)
  127. ENDIF(CMAKE_CROSSCOMPILING)
  128. set(prefix ${CMAKE_INSTALL_PREFIX})
  129. set(exec_prefix \${prefix})
  130. set(libdir \${exec_prefix}/${LIB_INSTALL_DIR})
  131. set(includedir \${prefix}/include)
  132. CONFIGURE_FILE(
  133. ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in
  134. ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  135. @ONLY)
  136. INSTALL(
  137. FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  138. DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
  139. )
  140. ########################################################################
  141. # Print Summary
  142. ########################################################################
  143. MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}")
  144. MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")