mirror of
https://github.com/greatscottgadgets/hackrf.git
synced 2026-03-08 00:08:12 +01:00
modern cmake
Refactor HackRF build system with a more modern CMake style. Install files to allow library users using CMake to find_project(HackRF CONFIG) and obtain HackRF::hackrf and/or HackRF::hackrf_static library targets. Add options ENABLE_STATIC_LIB and ENABLE_SHARED_LIB to allow shared or static library to be disabled. (Default builds both shared and static libraries.) Add option ENABLE_HACKRF_SWEEP, when disabled allows building without FFT library. (Default enabled.) Add option DISABLE_USB_DEVICE_DISCOVERY for a compile definition which could be used to alter libusb usage as needed on Android.
This commit is contained in:
committed by
Martin Ling
parent
adc537331c
commit
506c8cb292
@@ -1,74 +1,76 @@
|
||||
# Copyright 2012 Jared Boone
|
||||
# Copyright 2013 Benjamin Vernoux
|
||||
# Copyright 2025 A. Maitland Bottoms <bottoms@debian.org>
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; see the file COPYING. If not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
# Based heavily upon the libftdi cmake setup.
|
||||
option(ENABLE_HACKRF_SWEEP
|
||||
"Build and Install hackrf_sweep tool (Requires FFTW3f)" ON)
|
||||
find_package(FFTW3f)
|
||||
|
||||
set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX")
|
||||
set(TOOLS
|
||||
hackrf_transfer
|
||||
hackrf_spiflash
|
||||
hackrf_cpldjtag
|
||||
hackrf_info
|
||||
hackrf_debug
|
||||
hackrf_clock
|
||||
hackrf_operacake
|
||||
hackrf_biast)
|
||||
|
||||
find_package(FFTW REQUIRED)
|
||||
include_directories(${FFTW_INCLUDES})
|
||||
get_filename_component(FFTW_LIBRARY_DIRS ${FFTW_LIBRARIES} DIRECTORY)
|
||||
link_directories(${FFTW_LIBRARY_DIRS})
|
||||
|
||||
SET(TOOLS
|
||||
hackrf_transfer
|
||||
hackrf_spiflash
|
||||
hackrf_cpldjtag
|
||||
hackrf_info
|
||||
hackrf_debug
|
||||
hackrf_clock
|
||||
hackrf_sweep
|
||||
hackrf_operacake
|
||||
hackrf_biast
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
add_library(libgetopt_static STATIC
|
||||
../getopt/getopt.c
|
||||
)
|
||||
LIST(APPEND TOOLS_LINK_LIBS ${FFTW_LIBRARIES})
|
||||
if(TARGET HackRF::hackrf)
|
||||
list(APPEND TOOLS_LINK_LIBS HackRF::hackrf)
|
||||
else()
|
||||
LIST(APPEND TOOLS_LINK_LIBS m fftw3f)
|
||||
endif()
|
||||
|
||||
if(NOT libhackrf_SOURCE_DIR)
|
||||
include_directories(${LIBHACKRF_INCLUDE_DIR})
|
||||
LIST(APPEND TOOLS_LINK_LIBS ${LIBHACKRF_LIBRARIES})
|
||||
else()
|
||||
LIST(APPEND TOOLS_LINK_LIBS hackrf)
|
||||
list(APPEND TOOLS_LINK_LIBS HackRF::hackrf_static)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
LIST(APPEND TOOLS_LINK_LIBS libgetopt_static)
|
||||
add_library(libgetopt_static STATIC ../getopt/getopt.c)
|
||||
list(APPEND TOOLS_LINK_LIBS libgetopt_static)
|
||||
endif()
|
||||
|
||||
include(CheckLibraryExists)
|
||||
check_library_exists(m log10 "" LIBM)
|
||||
if(LIBM)
|
||||
list(APPEND TOOLS_LINK_LIBS m)
|
||||
endif()
|
||||
|
||||
foreach(tool ${TOOLS})
|
||||
add_executable(${tool} ${tool}.c)
|
||||
target_link_libraries(${tool} ${TOOLS_LINK_LIBS})
|
||||
install(TARGETS ${tool} RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
add_executable(${tool} ${tool}.c)
|
||||
target_compile_features(${tool} PRIVATE c_std_90)
|
||||
target_link_libraries(${tool} ${TOOLS_LINK_LIBS})
|
||||
install(TARGETS ${tool} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endforeach(tool)
|
||||
if(PC_FFTW3f_FOUND AND ENABLE_HACKRF_SWEEP)
|
||||
add_executable(hackrf_sweep hackrf_sweep.c)
|
||||
target_compile_features(hackrf_sweep PRIVATE c_std_90)
|
||||
target_link_libraries(hackrf_sweep fftw3f::fftw3f ${TOOLS_LINK_LIBS})
|
||||
install(TARGETS hackrf_sweep RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
else()
|
||||
message(
|
||||
STATUS
|
||||
"Not building hackrf_sweep tool. (Install FFTW, set ENABLE_HACKRF_SWEEP)"
|
||||
)
|
||||
endif()
|
||||
|
||||
if( ${WIN32} )
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/"
|
||||
DESTINATION ${INSTALL_DEFAULT_BINDIR}
|
||||
FILES_MATCHING
|
||||
PATTERN "fftw*.dll")
|
||||
endif( ${WIN32} )
|
||||
if(WIN32)
|
||||
install(
|
||||
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>/"
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
FILES_MATCHING
|
||||
PATTERN "fftw*.dll")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user