CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 5) # increment minor on feature-level changes
  37. set(VERSION_INFO_PATCH_VERSION 2) # 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-parameter)
  46. ADD_DEFINITIONS(-Wno-unused)
  47. ADD_DEFINITIONS(-Wsign-compare)
  48. #http://gcc.gnu.org/wiki/Visibility
  49. add_definitions(-fvisibility=hidden)
  50. endif()
  51. ########################################################################
  52. # Find build dependencies
  53. ########################################################################
  54. find_package(PkgConfig)
  55. find_package(LibUSB)
  56. set(THREADS_USE_PTHREADS_WIN32 true)
  57. find_package(Threads)
  58. if(NOT LIBUSB_FOUND)
  59. message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr")
  60. endif()
  61. if(NOT THREADS_FOUND)
  62. message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr")
  63. endif()
  64. ########################################################################
  65. # Setup the include and linker paths
  66. ########################################################################
  67. include_directories(
  68. ${CMAKE_SOURCE_DIR}/include
  69. ${LIBUSB_INCLUDE_DIR}
  70. ${THREADS_PTHREADS_INCLUDE_DIR}
  71. )
  72. #link_directories(
  73. # ...
  74. #)
  75. # Set component parameters
  76. #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
  77. ########################################################################
  78. # Create uninstall target
  79. ########################################################################
  80. configure_file(
  81. ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
  82. ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  83. @ONLY)
  84. add_custom_target(uninstall
  85. ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  86. )
  87. ########################################################################
  88. # Install udev rules
  89. ########################################################################
  90. option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF)
  91. if (INSTALL_UDEV_RULES)
  92. install (
  93. FILES rtl-sdr.rules
  94. DESTINATION "/etc/udev/rules.d"
  95. COMPONENT "udev"
  96. )
  97. else (INSTALL_UDEV_RULES)
  98. message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON")
  99. endif (INSTALL_UDEV_RULES)
  100. option(DETACH_KERNEL_DRIVER "Detach kernel driver if loaded" OFF)
  101. if (DETACH_KERNEL_DRIVER)
  102. message (STATUS "Building with kernel driver detaching enabled")
  103. add_definitions(-DDETACH_KERNEL_DRIVER=1)
  104. else (DETACH_KERNEL_DRIVER)
  105. message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable")
  106. endif (DETACH_KERNEL_DRIVER)
  107. ########################################################################
  108. # Add subdirectories
  109. ########################################################################
  110. add_subdirectory(include)
  111. add_subdirectory(src)
  112. ########################################################################
  113. # Create Pkg Config File
  114. ########################################################################
  115. FOREACH(inc ${LIBUSB_INCLUDE_DIR})
  116. LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}")
  117. ENDFOREACH(inc)
  118. FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
  119. LIST(APPEND RTLSDR_PC_LIBS "-L${lib}")
  120. ENDFOREACH(lib)
  121. # use space-separation format for the pc file
  122. STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}")
  123. STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}")
  124. # unset these vars to avoid hard-coded paths to cross environment
  125. IF(CMAKE_CROSSCOMPILING)
  126. UNSET(RTLSDR_PC_CFLAGS)
  127. UNSET(RTLSDR_PC_LIBS)
  128. ENDIF(CMAKE_CROSSCOMPILING)
  129. set(prefix ${CMAKE_INSTALL_PREFIX})
  130. set(exec_prefix \${prefix})
  131. set(libdir \${exec_prefix}/${LIB_INSTALL_DIR})
  132. set(includedir \${prefix}/include)
  133. CONFIGURE_FILE(
  134. ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in
  135. ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  136. @ONLY)
  137. INSTALL(
  138. FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  139. DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
  140. )
  141. ########################################################################
  142. # Print Summary
  143. ########################################################################
  144. MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}")
  145. MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")