CMakeLists.txt 5.9 KB

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