66fbda814e570df9804252a0aa89440e46b2d6bc
[rtl-433.git] / src / CMakeLists.txt
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 ########################################################################
21 # Setup library
22 ########################################################################
23 add_library(rtlsdr_shared SHARED
24     librtlsdr.c
25     tuner_e4k.c
26     tuner_fc0012.c
27     tuner_fc0013.c
28     tuner_fc2580.c
29     tuner_r820t.c
30 )
31
32 target_link_libraries(rtlsdr_shared
33     ${LIBUSB_LIBRARIES}
34 )
35
36 set_target_properties(rtlsdr_shared PROPERTIES DEFINE_SYMBOL "rtlsdr_EXPORTS")
37 set_target_properties(rtlsdr_shared PROPERTIES OUTPUT_NAME rtlsdr)
38 set_target_properties(rtlsdr_shared PROPERTIES SOVERSION 0 VERSION 0.0.0)
39
40 add_library(rtlsdr_static STATIC
41     librtlsdr.c
42     tuner_e4k.c
43     tuner_fc0012.c
44     tuner_fc0013.c
45     tuner_fc2580.c
46     tuner_r820t.c
47 )
48
49 if(WIN32)
50 add_library(libgetopt_static STATIC
51     getopt/getopt.c
52 )
53 endif()
54
55 target_link_libraries(rtlsdr_static
56     ${LIBUSB_LIBRARIES}
57 )
58
59 set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
60
61 if(NOT WIN32)
62 # Force same library filename for static and shared variants of the library
63 set_target_properties(rtlsdr_static PROPERTIES OUTPUT_NAME rtlsdr)
64 endif()
65
66 ########################################################################
67 # Build utility
68 ########################################################################
69 add_executable(rtl_sdr rtl_sdr.c)
70 add_executable(rtl_tcp rtl_tcp.c)
71 add_executable(rtl_test rtl_test.c)
72 add_executable(rtl_fm rtl_fm.c)
73 add_executable(rtl_eeprom rtl_eeprom.c)
74 add_executable(rtl_adsb rtl_adsb.c)
75 add_executable(rtl_433 rtl_433.c)
76 set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_433)
77
78 target_link_libraries(rtl_sdr rtlsdr_shared
79     ${LIBUSB_LIBRARIES}
80     ${CMAKE_THREAD_LIBS_INIT}
81 )
82 target_link_libraries(rtl_tcp rtlsdr_shared
83     ${LIBUSB_LIBRARIES}
84     ${CMAKE_THREAD_LIBS_INIT}
85 )
86 target_link_libraries(rtl_test rtlsdr_shared
87     ${LIBUSB_LIBRARIES}
88     ${CMAKE_THREAD_LIBS_INIT}
89 )
90 target_link_libraries(rtl_fm rtlsdr_shared
91     ${LIBUSB_LIBRARIES}
92     ${CMAKE_THREAD_LIBS_INIT}
93 )
94 target_link_libraries(rtl_433 rtlsdr_shared
95     ${LIBUSB_LIBRARIES}
96     ${CMAKE_THREAD_LIBS_INIT}
97 )
98 target_link_libraries(rtl_eeprom rtlsdr_shared
99     ${LIBUSB_LIBRARIES}
100     ${CMAKE_THREAD_LIBS_INIT}
101 )
102 target_link_libraries(rtl_adsb rtlsdr_shared
103     ${LIBUSB_LIBRARIES}
104     ${CMAKE_THREAD_LIBS_INIT}
105 )
106 if(UNIX)
107 target_link_libraries(rtl_fm m)
108 target_link_libraries(rtl_433 m)
109 target_link_libraries(rtl_adsb m)
110 if(APPLE)
111     target_link_libraries(rtl_test m)
112 else()
113     target_link_libraries(rtl_test m rt)
114 endif()
115 endif()
116
117 if(WIN32)
118 target_link_libraries(rtl_sdr libgetopt_static)
119 target_link_libraries(rtl_tcp libgetopt_static)
120 target_link_libraries(rtl_test libgetopt_static)
121 target_link_libraries(rtl_fm libgetopt_static)
122 target_link_libraries(rtl_433 libgetopt_static)
123 target_link_libraries(rtl_eeprom libgetopt_static)
124 target_link_libraries(rtl_adsb libgetopt_static)
125 set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
126 set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
127 set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
128 set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
129 set_property(TARGET rtl_433 APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
130 set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
131 set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" )
132 endif()
133 ########################################################################
134 # Install built library files & utilities
135 ########################################################################
136 install(TARGETS ${INSTALL_TARGETS}
137     LIBRARY DESTINATION lib${LIB_SUFFIX} # .so/.dylib file
138     ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file
139     RUNTIME DESTINATION bin              # .dll file
140 )