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 # Based on the hackrf cmakefiles, in turn based on the libftdi cmake
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 3.0)
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)
if (MSVC) if (MSVC)
include_directories(getopt) include_directories(getopt)
@ -13,6 +8,18 @@ if (MSVC)
if (FIND_DEBUG) if (FIND_DEBUG)
add_definitions(/D FIND_DEBUG) add_definitions(/D FIND_DEBUG)
endif() 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() else()
add_definitions(-Wall) add_definitions(-Wall)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
@ -21,6 +28,12 @@ else()
endif() endif()
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}) set(prefix ${CMAKE_INSTALL_PREFIX})
if(MSVC) if(MSVC)
@ -33,6 +46,23 @@ if(MSVC)
link_directories(${LIBUSB_1_LIBRARY_DIR}) link_directories(${LIBUSB_1_LIBRARY_DIR})
set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES}) 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 .) set (firmwaredir .)
else() else()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
@ -52,7 +82,6 @@ add_subdirectory(libwifiuserspace)
include_directories(${PROJECT_SOURCE_DIR}/libwifiuserspace) include_directories(${PROJECT_SOURCE_DIR}/libwifiuserspace)
SET(TOOLS SET(TOOLS
wifi_coconut_capture
wifi_coconut wifi_coconut
) )
@ -62,8 +91,13 @@ if (MSVC)
) )
endif() endif()
LIST(APPEND TOOLS_LINK_LIBS wifiuserspace-static) if (MINGW32)
add_library(libpthread STATIC IMPORTED)
else()
LIST(APPEND TOOLS_LINK_LIBS ${INT_THREAD_LIBS}) LIST(APPEND TOOLS_LINK_LIBS ${INT_THREAD_LIBS})
endif()
LIST(APPEND TOOLS_LINK_LIBS wifiuserspace-static)
LIST(APPEND TOOLS_LINK_LIBS ${INT_LIBUSB_LIBS}) LIST(APPEND TOOLS_LINK_LIBS ${INT_LIBUSB_LIBS})
LIST(APPEND TOOLS_LINK_LIBS ${CMAKE_THREAD_LIBS_INIT}) LIST(APPEND TOOLS_LINK_LIBS ${CMAKE_THREAD_LIBS_INIT})
@ -75,10 +109,6 @@ if (MSVC)
add_custom_target(copydlls) add_custom_target(copydlls)
endif() endif()
add_executable(wifi_coconut_capture
wifi_capture.c
)
add_executable(wifi_coconut add_executable(wifi_coconut
wifi_coconut.c wifi_coconut.c
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 # Based on the hackrf cmakefiles, in turn based on the libftdi cmake
cmake_minimum_required(VERSION 2.8)
project(libwifiuserspace C) project(libwifiuserspace C)
set(PACKAGE libwifiuserspace) set(PACKAGE libwifiuserspace)
include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake) include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake)
@ -17,6 +16,28 @@ if(MSVC)
link_directories(${LIBUSB_1_LIBRARY_DIR}) link_directories(${LIBUSB_1_LIBRARY_DIR})
set(INT_LIBUSB_LIBS ${LIBUSB_1_LIBRARIES}) 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(sharedir "./")
set(INSTALL_LIB_DIR "./") set(INSTALL_LIB_DIR "./")
set(INSTALL_DEFAULT_BINDIR "./") set(INSTALL_DEFAULT_BINDIR "./")

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#else #else
#include <Windows.h> #include <windows.h>
#define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000) #define usleep(x) Sleep((x) < 1000 ? 1 : (x) / 1000)
#define sleep(x) Sleep(x * 1000) #define sleep(x) Sleep(x * 1000)
#endif #endif
@ -29,7 +29,7 @@
#include "userspace.h" #include "userspace.h"
#include "rt2800usb/rt2800usb.h" #include "rt2800usb/rt2800usb.h"
#ifdef _WIN32 #if defined(_WIN32) && !defined(__MINGW32__)
/* /*
* Kluge a windows time into a user time * 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_usec CMP (b)->tv_usec) : \
((a)->tv_sec CMP (b)->tv_sec)) ((a)->tv_sec CMP (b)->tv_sec))
#endif
#ifdef _WIN32
#define timeradd(a, b, result) \ #define timeradd(a, b, result) \
do { \ do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \

View File

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

View File

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

View File

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