Skip to content

Commit

Permalink
cross build for win32 and win64(amd64) using mingw-gcc and github act…
Browse files Browse the repository at this point in the history
…ions

Signed-off-by: hayati ayguen <[email protected]>
  • Loading branch information
hayguen committed Sep 30, 2020
1 parent edd1bda commit 63d2218
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 2 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,70 @@ jobs:
name: macos_latest_build
path: librtlsdr_build_macos-latest.tar.gz

cross_build_win32_win64_latest:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- name: prerequisites
run: sudo apt -qq update && sudo apt -yqq install gcc-mingw-w64
- name: build_w32_static
run: bash ./cross_build_mingw32.sh static -DLINK_RTLTOOLS_AGAINST_STATIC_LIB=ON
- name: build_w32_static_udpsrv
run: bash ./cross_build_mingw32.sh static_udpsrv -DLINK_RTLTOOLS_AGAINST_STATIC_LIB=ON -DPROVIDE_UDP_SERVER=ON
- name: build_w32_dlldep
run: bash ./cross_build_mingw32.sh dlldep
- name: build_w32_dlldep_udpsrv
run: bash ./cross_build_mingw32.sh dlldep_udpsrv -DPROVIDE_UDP_SERVER=ON

- name: build_w64_static
run: bash ./cross_build_mingw64.sh static -DLINK_RTLTOOLS_AGAINST_STATIC_LIB=ON
- name: build_w64_static_udpsrv
run: bash ./cross_build_mingw64.sh static_udpsrv -DLINK_RTLTOOLS_AGAINST_STATIC_LIB=ON -DPROVIDE_UDP_SERVER=ON
- name: build_w64_dlldep
run: bash ./cross_build_mingw64.sh dlldep
- name: build_w64_dlldep_udpsrv
run: bash ./cross_build_mingw64.sh dlldep_udpsrv -DPROVIDE_UDP_SERVER=ON

- name: 'upload w32 static artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w32_static
path: rtlsdr-bin-w32_static/bin/
- name: 'upload w32 static_udpsrv artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w32_static_udpsrv
path: rtlsdr-bin-w32_static_udpsrv/bin/
- name: 'upload w32 dlldep artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w32_dlldep
path: rtlsdr-bin-w32_dlldep/bin/
- name: 'upload w32 dlldep_udpsrv artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w32_dlldep_udpsrv
path: rtlsdr-bin-w32_dlldep_udpsrv/bin/

- name: 'upload w64 static artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w64_static
path: rtlsdr-bin-w64_static/bin/
- name: 'upload w64 static_udpsrv artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w64_static_udpsrv
path: rtlsdr-bin-w64_static_udpsrv/bin/
- name: 'upload w64 dlldep artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w64_dlldep
path: rtlsdr-bin-w64_dlldep/bin/
- name: 'upload w64 dlldep_udpsrv artifact'
uses: actions/upload-artifact@v2
with:
name: rtlsdr-bin-w64_dlldep_udpsrv
path: rtlsdr-bin-w64_dlldep_udpsrv/bin/

54 changes: 54 additions & 0 deletions cross_build_mingw32.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# requires debian/ubuntu packages: zip gcc-mingw-w64

REPO_DIR=$(pwd)

if [ -z "$1" ]; then
echo "usage: $0 <zip-post> <any other cmake options>"
exit 1
fi

ZIP_POST="$1"
shift

CROSS="i686-w64-mingw32"
WN="w32"
TOOLCHAIN="mingw-w32-i686.cmake"

# libusb
if /bin/true; then
cd ${REPO_DIR} && rm -rf libusb_${WN}
cd ${REPO_DIR} && git clone --branch v1.0.23 https://github.com/libusb/libusb.git libusb_${WN}
echo -e "\n\n********************************************************"
echo "start build of libusb_${WN}"
cd ${REPO_DIR}/libusb_${WN} && ./bootstrap.sh && \
CC=${CROSS}-gcc \
AR=${CROSS}-ar \
RANLIB=${CROSS}-ranlib \
./configure --prefix=${REPO_DIR}/mingw_libusb_${WN} --host=${CROSS} --disable-shared && \
make && make install
echo -e "\n\nlisting of ${REPO_DIR}/mingw_libusb_${WN}"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}
echo -e "\nlisting of ${REPO_DIR}/mingw_libusb_${WN}/include"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}/include
echo -e "\nlisting of ${REPO_DIR}/mingw_libusb_${WN}/lib"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}/lib
echo -e "\n"
fi

# librtlsdr
if /bin/true; then
cd ${REPO_DIR} && rm -rf build_${WN}
echo -e "\n\n********************************************************"
echo "start build of librtlsdr_${WN}"
mkdir ${REPO_DIR}/build_${WN} && cd ${REPO_DIR}/build_${WN} && \
cmake -DCMAKE_TOOLCHAIN_FILE=${REPO_DIR}/${TOOLCHAIN} \
-DCMAKE_INSTALL_PREFIX=${REPO_DIR}/rtlsdr-bin-${WN}_${ZIP_POST} \
-DRTL_STATIC_BUILD=ON "$@" \
-DLIBUSB_INCLUDE_DIR=${REPO_DIR}/mingw_libusb_${WN}/include/libusb-1.0 \
-DLIBUSB_LIBRARIES=${REPO_DIR}/mingw_libusb_${WN}/lib/libusb-1.0.a \
../ && \
make && make install
fi

54 changes: 54 additions & 0 deletions cross_build_mingw64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# requires debian/ubuntu packages: zip gcc-mingw-w64

REPO_DIR=$(pwd)

if [ -z "$1" ]; then
echo "usage: $0 <zip-post> <any other cmake options>"
exit 1
fi

ZIP_POST="$1"
shift

CROSS="x86_64-w64-mingw32"
WN="w64"
TOOLCHAIN="mingw-w64-x64_64.cmake"

# libusb
if /bin/true; then
cd ${REPO_DIR} && rm -rf libusb_${WN}
cd ${REPO_DIR} && git clone --branch v1.0.23 https://github.com/libusb/libusb.git libusb_${WN}
echo -e "\n\n********************************************************"
echo "start build of libusb_${WN}"
cd ${REPO_DIR}/libusb_${WN} && ./bootstrap.sh && \
CC=${CROSS}-gcc \
AR=${CROSS}-ar \
RANLIB=${CROSS}-ranlib \
./configure --prefix=${REPO_DIR}/mingw_libusb_${WN} --host=${CROSS} --disable-shared && \
make && make install
echo -e "\n\nlisting of ${REPO_DIR}/mingw_libusb_${WN}"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}
echo -e "\nlisting of ${REPO_DIR}/mingw_libusb_${WN}/include"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}/include
echo -e "\nlisting of ${REPO_DIR}/mingw_libusb_${WN}/lib"
ls -alh ${REPO_DIR}/mingw_libusb_${WN}/lib
echo -e "\n"
fi

# librtlsdr
if /bin/true; then
cd ${REPO_DIR} && rm -rf build_${WN}
echo -e "\n\n********************************************************"
echo "start build of librtlsdr_${WN}"
mkdir ${REPO_DIR}/build_${WN} && cd ${REPO_DIR}/build_${WN} && \
cmake -DCMAKE_TOOLCHAIN_FILE=${REPO_DIR}/${TOOLCHAIN} \
-DCMAKE_INSTALL_PREFIX=${REPO_DIR}/rtlsdr-bin-${WN}_${ZIP_POST} \
-DRTL_STATIC_BUILD=ON "$@" \
-DLIBUSB_INCLUDE_DIR=${REPO_DIR}/mingw_libusb_${WN}/include/libusb-1.0 \
-DLIBUSB_LIBRARIES=${REPO_DIR}/mingw_libusb_${WN}/lib/libusb-1.0.a \
../ && \
make && make install
fi

24 changes: 24 additions & 0 deletions mingw-w32-i686.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w32-i686.cmake ..
#
# build for Windows' 32 bit architecture

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
24 changes: 24 additions & 0 deletions mingw-w64-x64_64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake ..
#
# build for Windows' 64 bit architecture

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ add_library(rtlsdr_shared SHARED ${rtlsdr_srcs})
if(NOT WIN32)
target_link_libraries(rtlsdr_shared ${LIBUSB_LIBRARIES})
else()
target_link_libraries(rtlsdr_shared ws2_32 ${LIBUSB_LIBRARIES})
target_link_libraries(rtlsdr_shared ws2_32 ${LIBUSB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()
if (WITH_RPC)
target_compile_definitions(rtlsdr_shared PUBLIC _ENABLE_RPC)
Expand All @@ -75,7 +75,7 @@ add_library(rtlsdr_static STATIC ${rtlsdr_srcs})
if(NOT WIN32)
target_link_libraries(rtlsdr_static ${LIBUSB_LIBRARIES})
else()
target_link_libraries(rtlsdr_static ws2_32 ${LIBUSB_LIBRARIES})
target_link_libraries(rtlsdr_static ws2_32 ${LIBUSB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif()

if (WITH_RPC)
Expand Down

0 comments on commit 63d2218

Please sign in to comment.