Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host software CMake cleanup: attempt #2 #1016

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f92aa7
Revert "Revert "Cleanup of host software CMake build system (#664)""
multiplemonomials Dec 10, 2021
559a4b6
Move common initialization into a script and call it from whatever th…
multiplemonomials Dec 10, 2021
a4041a8
Get FindLIBHACKRF.cmake working properly and integrated into the buil…
multiplemonomials Dec 10, 2021
6cc3a05
Fix static library getting installed to the bin dir instead of lib
multiplemonomials Dec 10, 2021
1c88a7d
Clarify message to say how to turn off udev rules
multiplemonomials Dec 10, 2021
6cef11a
Fix git release define when building out of source
multiplemonomials Dec 10, 2021
4dad270
Fix formatting, fix windows build error (rebase issue)
multiplemonomials Jan 15, 2023
ec4bd4a
Fix more formatting, update github actions Windows build to also set …
multiplemonomials Jan 15, 2023
565e623
Formatting again
multiplemonomials Jan 15, 2023
6f79891
Simplify life using CMAKE_PREFIX_PATH in CI
multiplemonomials Jan 15, 2023
557f76c
FindUSB1: add support for vcpkg library naming
multiplemonomials Jan 15, 2023
c0f5e22
FindThreads.cmake: Fix finding pthreads4w version 3.0+
multiplemonomials Jan 15, 2023
001c9e2
Apply prefix path everywhere
multiplemonomials Jan 15, 2023
d3e1967
Update variable name
multiplemonomials Jan 15, 2023
ef8b732
Fix path to hackrf.lib
multiplemonomials Jan 15, 2023
dce9bc5
Temporarily disable requirement for CMake check to pass
multiplemonomials Jan 15, 2023
fb76e55
Switch workspace variable evaluation
multiplemonomials Jan 15, 2023
7ba2b39
Try to fix install dir again
multiplemonomials Jan 15, 2023
2e7d9f4
FIx install prefix in another place
multiplemonomials Jan 15, 2023
8390895
Re-add HACKRF_WORKS check
multiplemonomials Jan 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ on:
schedule:
- cron: 1 12 * * 1

env:
WIN_LIBUSB_INC: -DLIBUSB_INCLUDE_DIR=C:/vcpkg/installed/x64-windows/include/libusb-1.0
WIN_LIBUSB_LIB: -DLIBUSB_LIBRARIES=C:/vcpkg/installed/x64-windows/lib/libusb-1.0.lib
WIN_FFTW_INC: -DFFTW_INCLUDES=C:/vcpkg/installed/x64-windows/include
WIN_FFTW_LIB: -DFFTW_LIBRARIES=C:/vcpkg/installed/x64-windows/lib/fftw3f.lib
WIN_PTHREAD_INC: -DTHREADS_PTHREADS_INCLUDE_DIR=C:/vcpkg/installed/x64-windows/include
WIN_PTHREAD_LIB: -DTHREADS_PTHREADS_WIN32_LIBRARY=C:/vcpkg/installed/x64-windows/lib/pthreadvc3.lib

jobs:
host:
strategy:
Expand Down Expand Up @@ -53,7 +45,7 @@ jobs:

- name: Configure CMake (Windows)
working-directory: ${{runner.workspace}}/host/build
run: cmake $env:GITHUB_WORKSPACE/host/ $env:WIN_LIBUSB_INC $env:WIN_LIBUSB_LIB $env:WIN_FFTW_INC $env:WIN_FFTW_LIB $env:WIN_PTHREAD_INC $env:WIN_PTHREAD_LIB
run: cmake $env:GITHUB_WORKSPACE/host/ -DCMAKE_PREFIX_PATH=C:/vcpkg/installed/x64-windows/
if: matrix.os == 'windows-latest'

- name: Build
Expand All @@ -70,7 +62,7 @@ jobs:

- name: Configure CMake (libhackrf, Windows)
working-directory: ${{runner.workspace}}/host/libhackrf/build
run: cmake $env:GITHUB_WORKSPACE/host/libhackrf/ $env:WIN_LIBUSB_INC $env:WIN_LIBUSB_LIB $env:WIN_PTHREAD_INC $env:WIN_PTHREAD_LIB
run: cmake $env:GITHUB_WORKSPACE/host/libhackrf/ -DCMAKE_PREFIX_PATH=C:/vcpkg/installed/x64-windows/ -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install
if: matrix.os == 'windows-latest'

- name: Build (libhackrf)
Expand All @@ -86,7 +78,7 @@ jobs:
- name: Install (libhackrf, Windows)
working-directory: ${{runner.workspace}}/host/libhackrf/build
run: |
cmake --install . --config Release --prefix=$env:GITHUB_WORKSPACE/install
cmake --install . --config Release
if: matrix.os == 'windows-latest'

- name: Create Build Environment (hackrf-tools)
Expand All @@ -100,7 +92,7 @@ jobs:
- name: Configure CMake (hackrf-tools, Windows)
working-directory: ${{runner.workspace}}/host/hackrf-tools/build
run: |
cmake $env:GITHUB_WORKSPACE/host/hackrf-tools/ $env:WIN_FFTW_INC $env:WIN_FFTW_LIB -DLIBHACKRF_INCLUDE_DIR=$env:GITHUB_WORKSPACE/install/include/libhackrf -DLIBHACKRF_LIBRARIES=$env:GITHUB_WORKSPACE/install/bin/hackrf.lib
cmake $env:GITHUB_WORKSPACE/host/hackrf-tools/ -DCMAKE_PREFIX_PATH=C:/vcpkg/installed/x64-windows/ -DLIBHACKRF_INCLUDE_DIR=${{runner.workspace}}/install/include/libhackrf -DLIBHACKRF_LIBRARY=${{runner.workspace}}/install/lib/hackrf.lib
if: matrix.os == 'windows-latest'

- name: Build (hackrf-tools)
Expand Down
6 changes: 4 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ install:
- curl -fsS -o "C:\fftw-3.3.5.zip" "ftp://ftp.fftw.org/pub/fftw/fftw-3.3.5-dll64.zip"
- 7z x -y "C:\fftw-3.3.5.zip" -o"C:\fftw"
- cd c:\fftw
- ps: lib /machine:x64 /def:libfftw3-3.def
- ps: lib /machine:x64 /def:libfftw3f-3.def
# ARM GCC for firmware builds
# - appveyor DownloadFile "https://developer.arm.com/-/media/Files/downloads/gnu-rm/6-2017q2/gcc-arm-none-eabi-6-2017-q2-update-win32.zip" -FileName "C:\gcc-arm-none-eabi-win32.zip"
Expand All @@ -34,8 +35,9 @@ build_script:
-DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads\Pre-built.2\include \
-DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads\Pre-built.2\lib\x64\pthreadVC2.lib \
-DPKG_CONFIG_EXECUTABLE="C:\pkg-config\bin\pkg-config.exe" \
-DFFTW_INCLUDES=C:\fftw \
-DFFTW_LIBRARIES=C:\fftw\libfftw3f-3.lib \
-DFFTW_INCLUDES_SERIAL=C:\fftw \
-DFFTW_LIBRARY_SERIAL=C:\fftw\libfftw3-3.lib \
-DFFTWF_LIBRARY_SERIAL=C:\fftw\libfftw3f-3.lib \
..
- msbuild HackRF.sln /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
# Firmware
Expand Down
26 changes: 10 additions & 16 deletions host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
#top dir cmake project for libhackrf + tools

cmake_minimum_required(VERSION 2.8)
project (HackRF C)
cmake_minimum_required(VERSION 3.8)
project(HackRF LANGUAGES C)

set(CMAKE_C_FLAGS "$ENV{CFLAGS}" CACHE STRING "C Flags")
# standard policies for CMake 3.8
cmake_policy(VERSION 3.8)

# Run common init code
# -----------------------------------------------------
include(cmake/hackrf-host.cmake)

# Subdirectories
# -----------------------------------------------------
add_subdirectory(libhackrf)
add_subdirectory(hackrf-tools)

########################################################################
# Create uninstall target
########################################################################

configure_file(
${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)


add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
49 changes: 34 additions & 15 deletions host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ rm -rf *
## How to build host software on Windows:
### Prerequisites for Cygwin, MinGW, or Visual Studio:

* cmake-2.8.12.1 or later from http://www.cmake.org/cmake/resources/software.html
* libusbx-1.0.18 or later from http://sourceforge.net/projects/libusbx/files/latest/download?source=files
* fftw-3.3.5 or later from http://www.fftw.org/install/windows.html
You will need to install these tools:
* cmake-3.8 or later from http://www.cmake.org/cmake/resources/software.html
* Install Windows driver for HackRF hardware or use Zadig see http://sourceforge.net/projects/libwdi/files/zadig
- If you want to use Zadig select HackRF USB device and just install/replace it with WinUSB driver.

You will also need these dependency libraries:
* libusb-1.0.18 or later from https://libusb.info/
* Make sure to grab the binaries corresponding to your VS version from the zip file
* fftw-3.3.5 or later from http://www.fftw.org/install/windows.html

If your environment has a package manager, such as Cygwin or MSYS2, you should be able to install these from there. Otherwise, you can download binaries directly from these sites and copy them to a build dependencies prefix. DLLs go in the bin folder, headers in include, .dll.a and .lib files in the lib folder, like normal.

>**Note for Windows build:**
You shall always execute hackrf-tools from Windows command shell and not from Cygwin or MinGW shell because on Cygwin/MinGW
Expand All @@ -53,26 +59,39 @@ make install
```

### For MinGW:

If you downloaded the fftw3 binaries above, you have to turn that fftw3 DLL into something MinGW can link to by running these commands in your prefix bin folder:
```
C:\your\build\prefix\bin> dlltool -d libfftw3f-3.def -l libfftw3f-3.dll.a -D libfftw3f-3.dll
C:\your\build\prefix\bin> dlltool -d libfftw3-3.def -l libfftw3-3.dll.a -D libfftw3-3.dll
```

Then move the generated .dll.a files to your prefix lib folder.

Now you can build from a Windows command prompt:
```
mkdir host/build
cd host/build
cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
make
make install
cmake ../ -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:/your/build/prefix -DCMAKE_INSTALL_PREFIX=C:/your/install/prefix
mingw32-make
mingw32-make install
```

### For Visual Studio 2015 x64
Create library definition for MSVC to link to
`C:\fftw-3.3.5-dll64> lib /machine:x64 /def:libfftw3f-3.def`

Similarly to the MinGW instructions, create fftw3 import libraries for MSVC to link to. You may have to run these from a Visual Studio command prompt in the folder where you extracted the fftw3 .dll and .def files:
```
C:\your\build\prefix\bin> lib /machine:x64 /def:libfftw3f-3.def
C:\your\build\prefix\bin> lib /machine:x64 /def:libfftw3-3.def
```
Then move the generated .lib files to your prefix lib folder. Also rename them to get rid of the "lib" prefix, e.g. `fftw3-3.lib`.

For libusb, libusb-1.0.dll needs to be extracted to your bin folder, libusb-1.0.lib needs to be extracted to your lib folder and renamed usb-1.0.lib, and the libusb-1.0/ folder needs to be extracted to your include folder.

For MSVC you will also need one additional dependency, [pthreads-win32](http://mirrors.kernel.org/sourceware/pthreads-win32/pthreads-w32-2-9-1-release.zip). Download that and extract the headers and `pthreadVC2.lib` from the prebuilts folder inside the zip.

```
c:\hackrf\host\build> cmake ../ -G "Visual Studio 14 2015 Win64" \
-DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.21\libusb \
-DLIBUSB_LIBRARIES=c:\libusb-1.0.21\MS64\dll\lib\libusb-1.0.lib \
-DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include \
-DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib \
-DFFTW_INCLUDES=C:\fftw-3.3.5-dll64 \
-DFFTW_LIBRARIES=C:\fftw-3.3.5-dll64\libfftw3f-3.lib
c:\hackrf\host\build> cmake ../ -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/your/build/prefix -DCMAKE_INSTALL_PREFIX=C:/your/install/prefix
```

CMake will produce a solution file named `HackRF.sln` and a series of
Expand Down
104 changes: 104 additions & 0 deletions host/cmake/hackrf-host.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This script contains the top-level logic for initializing the hackrf host
# software build system. Whichever directory CMake is from calls this
# CMake script to do all needed setup.

list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/modules
${CMAKE_CURRENT_LIST_DIR}/modules/amber-cmake)

include(TryLinkLibrary)
include(LibraryUtils)

set(HACKRF_HOST_INCLUDED TRUE)

# Compilation flags
# -----------------------------------------------------

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")

set(CMAKE_C_FLAGS_RELEASE "/O2")
set(CMAKE_C_FLAGS_DEBUG "/MDd /Zi /Ob0 /Od")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /W3")

# disable verbose security warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)

# enable M_PI
add_definitions(-D_USE_MATH_DEFINES=1)

# disable deprecated API headers
add_definitions(-DWIN32_LEAN_AND_MEAN)

elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")

set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
else()

message(WARNING "Unknown compiler ${CMAKE_C_COMPILER_ID}, don't know how to set CFLAGS")
endif()

# language standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS TRUE) # for M_PI

# endianness
include(TestBigEndian)
test_big_endian(BIGENDIAN)
if(BIGENDIAN)
add_definitions(-DHACKRF_BIG_ENDIAN)
endif()

# RPATH
# (set to point to lib dir in install prefix)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Find dependencies
# -----------------------------------------------------
message(STATUS "Checking dependencies...")

# libusb1.0
find_package(USB1 REQUIRED)
import_library(libusb ${LIBUSB_LIBRARIES} ${LIBUSB_INCLUDE_DIR})

# pthread
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
# tell FindThreads to use MSVC pthread library
set(THREADS_USE_PTHREADS_WIN32 TRUE)
endif()
find_package(Threads REQUIRED)

if(EXISTS "${THREADS_PTHREADS_INCLUDE_DIR}")
import_libraries(pthread LIBRARIES ${CMAKE_THREAD_LIBS_INIT} INCLUDES ${THREADS_PTHREADS_INCLUDE_DIR})
else()
# no include dir
import_libraries(pthread LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
endif()

# Options
# -----------------------------------------------------
set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX")


########################################################################
# Create uninstall target
########################################################################

configure_file(
${CMAKE_CURRENT_LIST_DIR}/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY)


add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
Loading