allow to cross-compile 32 and 64 bit versions of the library for windows
This commit is contained in:
parent
8e5ec4acf3
commit
11a2da2811
4 changed files with 75 additions and 103 deletions
|
@ -97,12 +97,34 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC)
|
||||||
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
|
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
|
||||||
|
|
||||||
IF(MINGW)
|
IF(MINGW)
|
||||||
|
IF (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
# force MinGW-w64 in 32bit mode
|
# force MinGW-w64 in 32bit mode
|
||||||
SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
|
SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
|
||||||
SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
|
SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
|
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
|
||||||
|
ELSE(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
|
||||||
|
# force MinGW-w64 in 32bit mode
|
||||||
|
MESSAGE("Building 32-bit Windows DLL")
|
||||||
|
#SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
|
||||||
|
#SET(CMAKE_MODULE_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
|
#SET(CMAKE_SHARED_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
|
#SET(CMAKE_EXE_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
|
||||||
|
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
|
||||||
|
ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
||||||
|
MESSAGE("Building 64-bit Windows DLL")
|
||||||
|
SET(CMAKE_RC_FLAGS "--target=pe-x86-64 --output-format=coff ${CMAKE_RC_FLAGS}")
|
||||||
|
ELSE(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
|
||||||
|
MESSAGE(FATAL_ERROR "Unknown Processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
|
ENDIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
|
||||||
|
ENDIF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
|
||||||
|
FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
|
||||||
|
IF (NOT DLLTOOL)
|
||||||
|
MESSAGE(FATAL_ERROR "Could not find dlltool command")
|
||||||
|
ENDIF (NOT DLLTOOL)
|
||||||
ENDIF(MINGW)
|
ENDIF(MINGW)
|
||||||
|
|
||||||
IF(NOT WIN32)
|
IF(NOT WIN32)
|
||||||
|
@ -138,11 +160,18 @@ ENDIF(LIBUSB_INCLUDE_DIRS)
|
||||||
# version.rc for Windows
|
# version.rc for Windows
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
# Date for filling in rc file information
|
# Date for filling in rc file information
|
||||||
|
IF (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
MACRO (GET_CURRENT_YEAR RESULT)
|
MACRO (GET_CURRENT_YEAR RESULT)
|
||||||
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
|
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
|
||||||
STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}})
|
STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}})
|
||||||
STRING(REGEX REPLACE ".*(..)/(..)/(....).*" "\\3" ${RESULT} ${${RESULT}})
|
STRING(REGEX REPLACE ".*(..)/(..)/(....).*" "\\3" ${RESULT} ${${RESULT}})
|
||||||
ENDMACRO (GET_CURRENT_YEAR)
|
ENDMACRO (GET_CURRENT_YEAR)
|
||||||
|
ELSE(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
MACRO (GET_CURRENT_YEAR RESULT)
|
||||||
|
EXECUTE_PROCESS(COMMAND "date" "+%Y" OUTPUT_VARIABLE ${RESULT})
|
||||||
|
STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}})
|
||||||
|
ENDMACRO (GET_CURRENT_YEAR)
|
||||||
|
ENDIF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
|
||||||
GET_CURRENT_YEAR(CURRENT_YEAR)
|
GET_CURRENT_YEAR(CURRENT_YEAR)
|
||||||
MESSAGE("Year for copyright is " ${CURRENT_YEAR})
|
MESSAGE("Year for copyright is " ${CURRENT_YEAR})
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ IF(WIN32)
|
||||||
|
|
||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
OUTPUT libnfc.lib
|
OUTPUT libnfc.lib
|
||||||
COMMAND dlltool -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
|
COMMAND ${DLLTOOL} -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
|
||||||
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def
|
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def
|
||||||
)
|
)
|
||||||
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
|
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
|
||||||
|
|
34
mingw-cross-compile.sh
Normal file
34
mingw-cross-compile.sh
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/sh
|
||||||
|
PROJECT_DIR=$(readlink -e $(dirname $0))
|
||||||
|
cd "$PROJECT_DIR"
|
||||||
|
|
||||||
|
WITH_USB=1
|
||||||
|
|
||||||
|
LIBUSB_WIN32_BIN_VERSION="1.2.6.0"
|
||||||
|
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
|
||||||
|
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
|
||||||
|
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
|
||||||
|
|
||||||
|
if [ "$WITH_USB" = "1" ]; then
|
||||||
|
if [ ! -d $LIBUSB_WIN32_BIN_DIR ]; then
|
||||||
|
wget -c $LIBUSB_WIN32_BIN_URL
|
||||||
|
unzip $LIBUSB_WIN32_BIN_ARCHIVE
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
rm -rf build
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
32*)
|
||||||
|
mingw32-cmake .. -DLIBUSB_INCLUDE_DIRS="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/include -DLIBUSB_LIBRARIES="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll -DLIBNFC_ROOT_DIR=$PWD/.. -DLIBNFC_SYSCONFDIR='C:\\Program Files (x86)\\libnfc\\config'
|
||||||
|
mingw32-make;;
|
||||||
|
64*)
|
||||||
|
mingw64-cmake .. -DLIBUSB_INCLUDE_DIRS="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/include -DLIBUSB_LIBRARIES="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/bin/amd64/libusb0.dll -DLIBNFC_ROOT_DIR=.. -DLIBNFC_SYSCONFDIR='C:\\Program Files\\libnfc\\config'
|
||||||
|
mingw64-make;;
|
||||||
|
*)
|
||||||
|
echo "specify whether to build 32-bit or 64-bit version by supplying 32 or 64 as parameter";;
|
||||||
|
esac
|
|
@ -1,91 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
WITH_USB=1
|
|
||||||
|
|
||||||
LIBUSB_WIN32_BIN_VERSION="1.2.6.0"
|
|
||||||
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
|
|
||||||
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
|
|
||||||
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
|
|
||||||
|
|
||||||
if [ "$WITH_USB" = "1" ]; then
|
|
||||||
if [ ! -d $LIBUSB_WIN32_BIN_DIR ]; then
|
|
||||||
wget -c $LIBUSB_WIN32_BIN_URL
|
|
||||||
unzip $LIBUSB_WIN32_BIN_ARCHIVE
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
MINGW="${MINGW:=i686-w64-mingw32}"
|
|
||||||
MINGW_DIR="/usr/$MINGW"
|
|
||||||
|
|
||||||
# Use MinGW binaries before others
|
|
||||||
#export PATH=$MINGW_DIR/bin:$PATH
|
|
||||||
|
|
||||||
# Set CPATH to MinGW include files
|
|
||||||
export CPATH=$MINGW_DIR/include
|
|
||||||
export LD_LIBRARY_PATH=$MINGW_DIR/lib
|
|
||||||
export LD_RUN_PATH=$MINGW_DIR/lib
|
|
||||||
|
|
||||||
# Force pkg-config to search in cross environement directory
|
|
||||||
export PKG_CONFIG_LIBDIR=$MINGW_DIR/lib/pkgconfig
|
|
||||||
|
|
||||||
# Stop compilation on first error
|
|
||||||
export CFLAGS="-Wfatal-errors"
|
|
||||||
|
|
||||||
# Include default MinGW include directory, and libnfc's win32 files
|
|
||||||
export CFLAGS="$CFLAGS -I$MINGW_DIR/include -I$PWD/contrib/win32"
|
|
||||||
|
|
||||||
if [ "$MINGW" = "i686-w64-mingw32" ]; then
|
|
||||||
# mingw-64 includes winscard.a and winscard.h
|
|
||||||
#
|
|
||||||
# It is not enough to set libpcsclite_LIBS to "-lwinscard", because it is
|
|
||||||
# forgotten when libnfc is created with libtool. That's why we are setting
|
|
||||||
# LIBS.
|
|
||||||
export LIBS="-lwinscard"
|
|
||||||
|
|
||||||
echo "MinGW-w64 ships all requirements libnfc."
|
|
||||||
echo "Unfortunately the MinGW-w64 header are currently"
|
|
||||||
echo "buggy. Also, Libtool doesn't support MinGW-w64"
|
|
||||||
echo "very well."
|
|
||||||
echo ""
|
|
||||||
echo "Warning ________________________________________"
|
|
||||||
echo "You will only be able to compile libnfc.dll, but"
|
|
||||||
echo "none of the executables (see utils and examples)."
|
|
||||||
echo ""
|
|
||||||
# You can fix winbase.h by adding the following lines:
|
|
||||||
# #include <basetsd.h>
|
|
||||||
# #include <windef.h>
|
|
||||||
# But the problem with Libtool remains.
|
|
||||||
else
|
|
||||||
if [ -z "$libpcsclite_LIBS$libpcsclite_CFLAGS" ]; then
|
|
||||||
echo "Error __________________________________________"
|
|
||||||
echo "You need to get the PC/SC library from a Windows"
|
|
||||||
echo "machine and the appropriate header files. Then"
|
|
||||||
echo "specify libpcsclite_LIBS=.../WinScard.dll and"
|
|
||||||
echo "libpcsclite_CFLAGS=-I..."
|
|
||||||
fi
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Configure to cross-compile using mingw32msvc
|
|
||||||
if [ "$WITH_USB" = "1" ]; then
|
|
||||||
# with direct-USB drivers (use libusb-win32)
|
|
||||||
DRIVERS="all"
|
|
||||||
else
|
|
||||||
# with UART divers only (can be tested under wine)
|
|
||||||
DRIVERS="pn532_uart,arygon"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -x configure ]; then
|
|
||||||
autoreconf -is
|
|
||||||
fi
|
|
||||||
|
|
||||||
./configure --target=$MINGW --host=$MINGW \
|
|
||||||
--with-drivers=$DRIVERS \
|
|
||||||
--with-libusb-win32=$PWD/$LIBUSB_WIN32_BIN_DIR \
|
|
||||||
$*
|
|
||||||
|
|
||||||
if [ "$MINGW" = "i686-w64-mingw32" ]; then
|
|
||||||
# due to the buggy headers from MINGW-64 we always add "contrib/windows.h",
|
|
||||||
# otherwise some windows types won't be available.
|
|
||||||
echo "#include \"contrib/windows.h\"" >> config.h
|
|
||||||
fi
|
|
Loading…
Reference in a new issue