mingw32: Enable cross-building from Linux to Windows via mingw32-64.

Fix include of Windows.h on case-sensitive systems, and add -DMINGW32
targets
release-1.1.0
Mike Kershaw / Dragorn 2022-10-28 15:55:51 -04:00
parent c32f764e5e
commit 05e7cbccb5
10 changed files with 77 additions and 21 deletions

View File

@ -1,11 +1,6 @@
# Based on the hackrf cmakefiles, in turn based on the libftdi cmake
cmake_minimum_required(VERSION 2.8)
project(userspace-wifi C)
set(PACKAGE userspace-wifi)
include(${PROJECT_SOURCE_DIR}/cmake/set_release.cmake)
add_definitions(-DRELEASE="${RELEASE}")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
cmake_minimum_required(VERSION 3.0)
if (MSVC)
include_directories(getopt)
@ -13,6 +8,18 @@ if (MSVC)
if (FIND_DEBUG)
add_definitions(/D FIND_DEBUG)
endif()
elseif (MINGW32)
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
else()
add_definitions(-Wall)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
@ -21,6 +28,12 @@ else()
endif()
endif()
project(userspace-wifi C)
set(PACKAGE userspace-wifi)
include(${PROJECT_SOURCE_DIR}/cmake/set_release.cmake)
add_definitions(-DRELEASE="${RELEASE}")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
set(prefix ${CMAKE_INSTALL_PREFIX})
if(MSVC)
@ -33,6 +46,23 @@ if(MSVC)
link_directories(${LIBUSB_1_LIBRARY_DIR})
set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES})
set (firmwaredir .)
elseif(MINGW32)
# find_package(PThread REQUIRED)
# include_directories(${PTHREAD_INCLUDE_DIR})
# set(INT_THREAD_LIBS ${PTHREADS_LIBRARY})
#find_package(LibUSB-1.0 REQUIRED)
#include_directories(${LIBUSB_1_INCLUDE_DIR})
#link_directories(${LIBUSB_1_LIBRARY_DIR})
#set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES})
find_package(Threads REQUIRED)
set(INT_THREAD_LIBS ${THREADS_LIBRARY})
include_directories("${VCPKG_HOME}/installed/x64-mingw-static/include/libusb-1.0")
set(INT_LIBUSB_LIBS "${VCPKG_HOME}/installed/x64-mingw-static/lib/libusb-1.0.a")
set (firmwaredir .)
else()
find_package(Threads REQUIRED)
@ -52,7 +82,6 @@ add_subdirectory(libwifiuserspace)
include_directories(${PROJECT_SOURCE_DIR}/libwifiuserspace)
SET(TOOLS
wifi_coconut_capture
wifi_coconut
)
@ -62,8 +91,13 @@ if (MSVC)
)
endif()
if (MINGW32)
add_library(libpthread STATIC IMPORTED)
else()
LIST(APPEND TOOLS_LINK_LIBS ${INT_THREAD_LIBS})
endif()
LIST(APPEND TOOLS_LINK_LIBS wifiuserspace-static)
LIST(APPEND TOOLS_LINK_LIBS ${INT_THREAD_LIBS})
LIST(APPEND TOOLS_LINK_LIBS ${INT_LIBUSB_LIBS})
LIST(APPEND TOOLS_LINK_LIBS ${CMAKE_THREAD_LIBS_INIT})
@ -75,10 +109,6 @@ if (MSVC)
add_custom_target(copydlls)
endif()
add_executable(wifi_coconut_capture
wifi_capture.c
)
add_executable(wifi_coconut
wifi_coconut.c
wifi_coconut/wifi_coconut.c

View File

@ -1,6 +1,5 @@
# Based on the hackrf cmakefiles, in turn based on the libftdi cmake
cmake_minimum_required(VERSION 2.8)
project(libwifiuserspace C)
set(PACKAGE libwifiuserspace)
include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake)
@ -17,6 +16,28 @@ if(MSVC)
link_directories(${LIBUSB_1_LIBRARY_DIR})
set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES})
set(sharedir "./")
set(INSTALL_LIB_DIR "./")
set(INSTALL_DEFAULT_BINDIR "./")
elseif (MINGW32)
#find_package(PThread REQUIRED)
#include_directories(${PTHREAD_INCLUDE_DIR})
#set(INT_THREAD_LIBS ${PTHREADS_LIBRARY})
#find_package(LibUSB-1.0 REQUIRED)
#include_directories(${LIBUSB_1_INCLUDE_DIR})
#link_directories(${LIBUSB_1_LIBRARY_DIR})
#set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES})
find_package(Threads REQUIRED)
set(INT_THREAD_LIBS ${THREADS_LIBRARY})
#find_package(USB1 REQUIRED)
#include_directories(${LIBUSB_INCLUDE_DIR})
#set(INT_LIBUSB_LIBS ${LIBUSB_LIBRARIES})
include_directories("${VCPKG_HOME}/installed/x64-mingw-static/include/libusb-1.0")
set(INT_LIBUSB_LIBS "${VCPKG_HOME}/installed/x64-mingw-static/lib/libusb-1.0.a")
set(sharedir "./")
set(INSTALL_LIB_DIR "./")
set(INSTALL_DEFAULT_BINDIR "./")

View File

@ -113,7 +113,9 @@
* @x: first value
* @y: second value
*/
#ifndef max
#define max(x, y) __cmp(x, y, >)
#endif
/*
* This looks more complex than it should be. But we need to

View File

@ -14,7 +14,7 @@
#ifndef _WIN32
#include <unistd.h>
#else
#include "Windows.h"
#include "windows.h"
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#define sleep(x) Sleep(x*1000)
#endif

View File

@ -19,7 +19,7 @@
#ifndef _WIN32
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#endif

View File

@ -15,7 +15,7 @@
#ifndef _WIN32
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#endif

View File

@ -17,7 +17,7 @@
#include <sys/time.h>
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#define sleep(x) Sleep(x * 1000)
#endif
@ -29,7 +29,7 @@
#include "userspace.h"
#include "rt2800usb/rt2800usb.h"
#ifdef _WIN32
#if defined(_WIN32) && !defined(__MINGW32__)
/*
* Kluge a windows time into a user time
*/
@ -55,6 +55,9 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp) {
((a)->tv_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec))
#endif
#ifdef _WIN32
#define timeradd(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \

View File

@ -16,7 +16,7 @@
#include <sys/time.h>
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#endif

View File

@ -17,7 +17,7 @@
#include <sys/time.h>
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#endif

View File

@ -19,7 +19,7 @@
#include <sys/time.h>
#include <unistd.h>
#else
#include <Windows.h>
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#endif