From 5db8be908bf25363622cc2b73d6bf12a72c297b9 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Mar 2011 13:38:49 +0000 Subject: [PATCH] Windows support contribution: - Move CMake modules from cmake_modules/ to cmake/modules/ - CMake now use cmake/config_windows.h.cmake to create config.h on Windows platform - contrib/windows.h header is automagically included by config.h - Put missing NFC_EXPORT macro on front of emulation API - nfc-mfclassic and nfc-mfcultralight examples are now compiled under Windows Many thanks to Glenn Ergeerts which provide the initial patch. --- CMakeLists.txt | 20 +++++++++---------- config.h.cmake => cmake/config_posix.h.cmake | 0 cmake/config_windows.h.cmake | 5 +++++ .../modules}/COPYING-CMAKE-SCRIPTS | 0 .../modules}/FindLIBUSB.cmake | 0 .../modules}/FindPCSC.cmake | 0 .../modules}/LibnfcDrivers.cmake | 0 {cmake_modules => cmake/modules}/Makefile.am | 0 .../modules}/UseDoxygen.cmake | 0 contrib/win32/err.h | 2 +- contrib/windows.h | 4 ++++ examples/CMakeLists.txt | 14 ++++++------- examples/nfc-relay-picc.c | 2 +- examples/pn53x-sam.c | 1 - include/nfc/nfc-emulation.h | 3 ++- libnfc/CMakeLists.txt | 3 +++ libnfc/buses/uart_win32.c | 2 +- libnfc/chips/pn53x.c | 4 ---- libnfc/nfc-device.c | 4 ++++ libnfc/nfc.c | 4 ---- 20 files changed, 37 insertions(+), 31 deletions(-) rename config.h.cmake => cmake/config_posix.h.cmake (100%) create mode 100644 cmake/config_windows.h.cmake rename {cmake_modules => cmake/modules}/COPYING-CMAKE-SCRIPTS (100%) rename {cmake_modules => cmake/modules}/FindLIBUSB.cmake (100%) rename {cmake_modules => cmake/modules}/FindPCSC.cmake (100%) rename {cmake_modules => cmake/modules}/LibnfcDrivers.cmake (100%) rename {cmake_modules => cmake/modules}/Makefile.am (100%) rename {cmake_modules => cmake/modules}/UseDoxygen.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad501f5..a7eb5e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,22 +11,20 @@ SET(PACKAGE_VERSION ${VERSION}) SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") # config.h -IF(NOT WIN32) +IF(WIN32) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32) +ELSE(WIN32) SET(_XOPEN_SOURCE 600) -ENDIF(NOT WIN32) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) +ENDIF(WIN32) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) ADD_DEFINITIONS("-DHAVE_CONFIG_H") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) -# Win32 -IF(WIN32) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32) -ENDIF(WIN32) - # make it easy to locate CMake modules for finding libraries -SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/") +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") # Options SET(LIBNFC_DEBUG_OUTPUT OFF CACHE BOOL "Debug output of communication with the NFC chip") @@ -78,9 +76,9 @@ IF(NOT WIN32) SET(prefix ${CMAKE_INSTALL_PREFIX}) SET(exec_prefix ${CMAKE_INSTALL_PREFIX}) SET(PACKAGE "libnfc") - IF(LIBNFC_DRIVER_PN531_USB OR LIBNFC_DRIVER_PN533_USB) + IF(LIBNFC_DRIVER_PN53X_USB) SET(PKG_REQ ${PKG_REQ} "libusb") - ENDIF(LIBNFC_DRIVER_PN531_USB OR LIBNFC_DRIVER_PN533_USB) + ENDIF(LIBNFC_DRIVER_PN53X_USB) IF(LIBNFC_DRIVER_ACR122) SET(PKG_REQ ${PKG_REQ} "libpcsclite") ENDIF(LIBNFC_DRIVER_ACR122) diff --git a/config.h.cmake b/cmake/config_posix.h.cmake similarity index 100% rename from config.h.cmake rename to cmake/config_posix.h.cmake diff --git a/cmake/config_windows.h.cmake b/cmake/config_windows.h.cmake new file mode 100644 index 0000000..5267ced --- /dev/null +++ b/cmake/config_windows.h.cmake @@ -0,0 +1,5 @@ +#include "contrib/windows.h" + +#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" +#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" +#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" diff --git a/cmake_modules/COPYING-CMAKE-SCRIPTS b/cmake/modules/COPYING-CMAKE-SCRIPTS similarity index 100% rename from cmake_modules/COPYING-CMAKE-SCRIPTS rename to cmake/modules/COPYING-CMAKE-SCRIPTS diff --git a/cmake_modules/FindLIBUSB.cmake b/cmake/modules/FindLIBUSB.cmake similarity index 100% rename from cmake_modules/FindLIBUSB.cmake rename to cmake/modules/FindLIBUSB.cmake diff --git a/cmake_modules/FindPCSC.cmake b/cmake/modules/FindPCSC.cmake similarity index 100% rename from cmake_modules/FindPCSC.cmake rename to cmake/modules/FindPCSC.cmake diff --git a/cmake_modules/LibnfcDrivers.cmake b/cmake/modules/LibnfcDrivers.cmake similarity index 100% rename from cmake_modules/LibnfcDrivers.cmake rename to cmake/modules/LibnfcDrivers.cmake diff --git a/cmake_modules/Makefile.am b/cmake/modules/Makefile.am similarity index 100% rename from cmake_modules/Makefile.am rename to cmake/modules/Makefile.am diff --git a/cmake_modules/UseDoxygen.cmake b/cmake/modules/UseDoxygen.cmake similarity index 100% rename from cmake_modules/UseDoxygen.cmake rename to cmake/modules/UseDoxygen.cmake diff --git a/contrib/win32/err.h b/contrib/win32/err.h index b38bcb9..20c9a57 100644 --- a/contrib/win32/err.h +++ b/contrib/win32/err.h @@ -14,6 +14,6 @@ exit (code); \ } while (0) -#define err(code, ...) errx(code, ...) +#define err errx #endif /* !_ERR_H_ */ diff --git a/contrib/windows.h b/contrib/windows.h index c97e07a..01b29f0 100644 --- a/contrib/windows.h +++ b/contrib/windows.h @@ -27,11 +27,15 @@ #define __WINDOWS_H__ # include +# include +# include "win32/err.h" # if defined (__MINGW32__) # define snprintf(S, n, F, ...) sprintf(S, F, __VA_ARGS__) # define MAX(a,b) max(a,b) # define MIN(a,b) min(a,b) # define pipe(fds) _pipe(fds, 5000, _O_BINARY) +# define ETIMEDOUT WSAETIMEDOUT +# define ENOTSUP 134 # else # define snprintf sprintf_s # define strdup _strdup diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index af2c79f..d8ce22a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ -SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-forum-tag4 nfc-emulate-tag nfc-emulate-uid nfc-list nfc-poll nfc-relay nfc-relay-picc) -#TODO nfc-mfclassic nfc-mfultralight pn53x-diagnose pn53x-sam pn53x-tamashell +SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-forum-tag4 nfc-emulate-tag nfc-emulate-uid nfc-list nfc-poll nfc-relay nfc-relay-picc nfc-mfclassic nfc-mfultralight) +#TODO pn53x-diagnose pn53x-sam pn53x-tamashell # XXX: Examples should not use private API! INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc) @@ -8,19 +8,19 @@ INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS} ${PCSC_INCLUDE_DIRS}) LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS} ${PCSC_LIBRARY_DIRS}) ADD_LIBRARY(nfc-utils nfc-utils) -#ADD_LIBRARY(mifare mifare) # Examples FOREACH(source ${EXAMPLES-SOURCES}) - ADD_EXECUTABLE(${source} ${source}.c) + IF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic")) + ADD_EXECUTABLE(${source} ${source}.c mifare) + ELSE() + ADD_EXECUTABLE(${source} ${source}.c) + ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic")) TARGET_LINK_LIBRARIES(${source} nfc) TARGET_LINK_LIBRARIES(${source} nfc-utils) INSTALL(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples) ENDFOREACH(source) -#TARGET_LINK_LIBRARIES(nfc-mfclassic mifare) -#TARGET_LINK_LIBRARIES(nfc-mfultralight mifare) - IF(NOT WIN32) # Manuals for the examples FILE(GLOB manuals "${CMAKE_CURRENT_SOURCE_DIR}/*.1") diff --git a/examples/nfc-relay-picc.c b/examples/nfc-relay-picc.c index b51ab81..45e3eef 100644 --- a/examples/nfc-relay-picc.c +++ b/examples/nfc-relay-picc.c @@ -52,6 +52,7 @@ #include "nfc-utils.h" +// TODO Move this Windows conditional code in contrib/win32/ or contrib/windows.h #ifndef _WIN32 // Needed by sleep() under Unix # include @@ -59,7 +60,6 @@ # define SUSP_TIME 1 // secs. #else // Needed by Sleep() under Windows -# include "../contrib/windows.h" # include # define sleep Sleep # define SUSP_TIME 1000 // msecs. diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index 6b472c2..2d0ac6d 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -47,7 +47,6 @@ # define SUSP_TIME 1 // secs. #else // Needed by Sleep() under Windows -# include "../contrib/windows.h" # include # define sleep Sleep # define SUSP_TIME 1000 // msecs. diff --git a/include/nfc/nfc-emulation.h b/include/nfc/nfc-emulation.h index 5d110af..e0586e2 100644 --- a/include/nfc/nfc-emulation.h +++ b/include/nfc/nfc-emulation.h @@ -21,6 +21,7 @@ #define __NFC_EMULATION_H__ #include +#include struct nfc_emulator; struct nfc_emulation_state_machine; @@ -37,6 +38,6 @@ struct nfc_emulation_state_machine { void *data; }; -int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator); +NFC_EXPORT int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator); #endif /* __NFC_EMULATION_H__ */ diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index e32a8a8..090130d 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -22,6 +22,9 @@ SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation iso14443-subr mirror-subr ${DRI INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES}) TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES}) +IF(WIN32) + TARGET_LINK_LIBRARIES(nfc wsock32) +ENDIF(WIN32) SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0) IF(WIN32) diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 543e50a..f8ae352 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -149,7 +149,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd) if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) { return DEIO; } - return (dwRwLen == (DWORD) szRx) ? 0 : DEIO; + return (dwRxLen == (DWORD) szRx) ? 0 : DEIO; } int diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 3b98093..bfd9a8e 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -43,10 +43,6 @@ #include "mirror-subr.h" #include "nfc-internal.h" -#ifdef _WIN32 -# include "contrib/windows.h" -#endif - #include #define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data)) diff --git a/libnfc/nfc-device.c b/libnfc/nfc-device.c index b62e877..019a07b 100644 --- a/libnfc/nfc-device.c +++ b/libnfc/nfc-device.c @@ -26,6 +26,10 @@ #include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif // HAVE_CONFIG_H + #include "nfc-internal.h" nfc_device_t * diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 1696a9f..9297f37 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -39,10 +39,6 @@ #include -#ifdef _WIN32 -# include "contrib/windows.h" -#endif - #include "drivers.h" #include "nfc-internal.h"