CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ########################################################################
  32. # Compiler specific setup
  33. ########################################################################
  34. if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
  35. ADD_DEFINITIONS(-Wall)
  36. ADD_DEFINITIONS(-Wextra)
  37. ADD_DEFINITIONS(-Wno-unused)
  38. ADD_DEFINITIONS(-Wsign-compare)
  39. #http://gcc.gnu.org/wiki/Visibility
  40. add_definitions(-fvisibility=hidden)
  41. endif()
  42. ########################################################################
  43. # Find build dependencies
  44. ########################################################################
  45. find_package(PkgConfig)
  46. find_package(LibUSB)
  47. set(THREADS_USE_PTHREADS_WIN32 true)
  48. find_package(Threads)
  49. if(NOT LIBUSB_FOUND)
  50. message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr")
  51. endif()
  52. if(NOT THREADS_FOUND)
  53. message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr")
  54. endif()
  55. ########################################################################
  56. # Setup the include and linker paths
  57. ########################################################################
  58. include_directories(
  59. ${CMAKE_SOURCE_DIR}/include
  60. ${LIBUSB_INCLUDE_DIR}
  61. ${THREADS_PTHREADS_INCLUDE_DIR}
  62. )
  63. #link_directories(
  64. # ...
  65. #)
  66. # Set component parameters
  67. #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE)
  68. ########################################################################
  69. # Create uninstall target
  70. ########################################################################
  71. configure_file(
  72. ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
  73. ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  74. @ONLY)
  75. add_custom_target(uninstall
  76. ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
  77. )
  78. ########################################################################
  79. # Install udev rules
  80. ########################################################################
  81. option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF)
  82. if (INSTALL_UDEV_RULES)
  83. install (
  84. FILES rtl-sdr.rules
  85. DESTINATION "/etc/udev/rules.d"
  86. COMPONENT "udev"
  87. )
  88. else (INSTALL_UDEV_RULES)
  89. message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON")
  90. endif (INSTALL_UDEV_RULES)
  91. ########################################################################
  92. # Add subdirectories
  93. ########################################################################
  94. add_subdirectory(include)
  95. add_subdirectory(src)
  96. ########################################################################
  97. # Create Pkg Config File
  98. ########################################################################
  99. FOREACH(inc ${LIBUSB_INCLUDE_DIR})
  100. LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}")
  101. ENDFOREACH(inc)
  102. FOREACH(lib ${LIBUSB_LIBRARY_DIRS})
  103. LIST(APPEND RTLSDR_PC_LIBS "-L${lib}")
  104. ENDFOREACH(lib)
  105. # use space-separation format for the pc file
  106. STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}")
  107. STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}")
  108. # unset these vars to avoid hard-coded paths to cross environment
  109. IF(CMAKE_CROSSCOMPILING)
  110. UNSET(RTLSDR_PC_CFLAGS)
  111. UNSET(RTLSDR_PC_LIBS)
  112. ENDIF(CMAKE_CROSSCOMPILING)
  113. set(prefix ${CMAKE_INSTALL_PREFIX})
  114. set(exec_prefix \${prefix})
  115. set(libdir \${exec_prefix}/lib)
  116. set(includedir \${prefix}/include)
  117. CONFIGURE_FILE(
  118. ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in
  119. ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  120. @ONLY)
  121. INSTALL(
  122. FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc
  123. DESTINATION lib/pkgconfig
  124. )