diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..5274627
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,56 @@
+# $Id$
+project(libfreefare C)
+cmake_minimum_required(VERSION 2.6)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
+
+add_definitions("-std=c99")
+
+find_package(LIBNFC REQUIRED)
+find_package(OpenSSL REQUIRED)
+
+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)
+ find_library(WINSOCK_LIB libws2_32.a)
+ set(LIBS ${LIBS} ${WINSOCK_LIB})
+ENDIF(WIN32)
+
+if(MINGW)
+ # force MinGW-w64 in 32bit mode
+ add_definitions("-m32")
+ set(CMAKE_SHARED_LINKER_FLAGS -m32)
+ set(CMAKE_EXE_LINKER_FLAGS -m32)
+endif(MINGW)
+
+message("CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
+message("CMAKE_SHARED_LINKER_FLAGS: " ${CMAKE_SHARED_LINKER_FLAGS})
+
+include_directories(${LIBNFC_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
+set(LIBS ${LIBS} ${LIBNFC_LIBRARIES} ${OPENSSL_LIBRARIES})
+
+if(NOT DEFINED CMAKE_INSTALL_PREFIX)
+ message("CMAKE_INSTALL_PREFIX not defined")
+ set(CMAKE_INSTALL_PREFIX "c:/projects/EVENT/install") # TODO
+endif(NOT DEFINED CMAKE_INSTALL_PREFIX)
+
+if(DEFINED CMAKE_INSTALL_LIBDIR)
+ set(libdir ${CMAKE_INSTALL_LIBDIR})
+else(DEFINED CMAKE_INSTALL_LIBDIR)
+ set(CMAKE_INSTALL_LIBDIR lib)
+ set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
+endif(DEFINED CMAKE_INSTALL_LIBDIR)
+
+if(DEFINED INCLUDE_INSTALL_DIR)
+ set(includedir ${INCLUDE_INSTALL_DIR})
+else(DEFINED INCLUDE_INSTALL_DIR)
+ set(INCLUDE_INSTALL_DIR include)
+ set(includedir ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR})
+endif(DEFINED INCLUDE_INSTALL_DIR)
+
+if(NOT DEFINED SHARE_INSTALL_PREFIX)
+ set(SHARE_INSTALL_PREFIX share)
+endif(NOT DEFINED SHARE_INSTALL_PREFIX)
+
+add_subdirectory(libfreefare)
+add_subdirectory(examples)
diff --git a/FindLIBNFC.cmake b/FindLIBNFC.cmake
new file mode 100644
index 0000000..55ca560
--- /dev/null
+++ b/FindLIBNFC.cmake
@@ -0,0 +1,21 @@
+# $Id$
+# TODO locate using pkg-config for linux/bsd
+
+#set(LIBNFC_INCLUDE_DIRS "")
+#set(LIBNFC_LIBRARIES "")
+set(LIBNFC_INSTALL_DIR $ENV{PROGRAMFILES}/libnfc CACHE PATH "libnfc installation directory")
+
+message("libnfc install dir: " ${LIBNFC_INSTALL_DIR})
+
+find_path(LIBNFC_INCLUDE_DIRS NAMES nfc/nfc.h PATHS ${LIBNFC_INSTALL_DIR}/include)
+message("libnfc include dir found: " ${LIBNFC_INCLUDE_DIRS})
+
+find_library(LIBNFC_LIBRARIES libnfc PATHS ${LIBNFC_INSTALL_DIR}/lib)
+message("libnfc library found: " ${LIBNFC_LIBRARIES})
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBNFC DEFAULT_MSG
+ LIBNFC_INCLUDE_DIRS
+ LIBNFC_LIBRARIES
+)
+MARK_AS_ADVANCED(LIBNFC_INCLUDE_DIRS LIBNFC_LIBRARIES)
diff --git a/Makefile.am b/Makefile.am
index e9cb58e..1a9b307 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,7 +32,7 @@ clean-local-coverage:
-rm -rf coverage
SVN_KEYWORDS_FILES_LIST_CMD = find $(top_srcdir) -name '*.[hc]' -a ! -name config.h \
- -o -name Makefile.am
+ -o -name Makefile.am -o -name '*.cmake' -o -name 'CMakeLists.txt'
svn-keywords:
@echo Update files svn:keywords...
@$(SVN_KEYWORDS_FILES_LIST_CMD) | xargs svn propset -q svn:keywords Id
diff --git a/NEWS b/NEWS
index 481d7fa..7f6cafc 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Changes between 0.3.1 and 0.3.2 [XX xxx XXXX]
mifare_desfire_create_backup_data_file_iso(),
mifare_desfire_create_linear_record_file_iso(),
mifare_desfire_create_cyclic_record_file_iso().
+ *) Microsoft Windows support.
Changes between 0.3.0 and 0.3.1 [23 feb 2011]
diff --git a/config_windows.h.cmake b/config_windows.h.cmake
new file mode 100644
index 0000000..a05d0ea
--- /dev/null
+++ b/config_windows.h.cmake
@@ -0,0 +1,33 @@
+/*-
+ * Copyright (C) 2011 Glenn Ergeerts.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see
+ *
+ * $Id$
+ */
+
+#ifndef __CONFIG_WINDOWS_H__
+#define __CONFIG_WINDOWS_H__
+
+#include
+
+#define htole32(x) (x)
+#define le32toh(x) (x)
+#define le16toh(x) (x)
+#define htobe16(x) htons(x)
+#define be16toh(x) ntohs(x)
+
+#define ENOTSUP WSAEOPNOTSUPP
+
+#endif /* !__CONFIG_WINDOWS_H__ */
diff --git a/err.h b/err.h
new file mode 100644
index 0000000..aa5aee4
--- /dev/null
+++ b/err.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (C) 2011 Glenn Ergeerts.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see
+ *
+ * $Id$
+ */
+
+#ifndef __ERR_H__
+#define __ERR_H__
+
+#include
+
+#define warnx(...) do { \
+ fprintf (stderr, __VA_ARGS__); \
+ fprintf (stderr, "\n"); \
+} while (0)
+
+#define errx(code, ...) do { \
+ fprintf (stderr, __VA_ARGS__); \
+ fprintf (stderr, "\n"); \
+ exit (code); \
+} while (0)
+
+/* FIXME: warn / err are supposed to display errno's message */
+#define warn warnx
+#define err errx
+
+#endif /* !__ERR_H__ */
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..56b2f36
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,21 @@
+# $Id$
+set(EXAMPLES-SOURCES
+ mifare-classic-format
+ mifare-classic-write-ndef
+ mifare-desfire-access
+ mifare-desfire-format
+ mifare-desfire-info
+ mifare-desfire-write-ndef
+ mifare-desfire-ev1-configure-ats
+ mifare-desfire-ev1-configure-default-key
+ mifare-desfire-ev1-configure-random-uid
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libfreefare)
+
+# Examples
+foreach(source ${EXAMPLES-SOURCES})
+ add_executable(${source} ${source}.c)
+ target_link_libraries(${source} freefare)
+ install(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples)
+endforeach(source)
diff --git a/libfreefare/CMakeLists.txt b/libfreefare/CMakeLists.txt
new file mode 100644
index 0000000..282dd08
--- /dev/null
+++ b/libfreefare/CMakeLists.txt
@@ -0,0 +1,34 @@
+# $Id$
+set(LIBRARY_SOURCES
+ freefare
+ freefare_internal
+ mad
+ mifare_application
+ mifare_classic
+ mifare_desfire
+ mifare_desfire_aid
+ mifare_desfire_crypto
+ mifare_desfire_error
+ mifare_desfire_key
+ mifare_ultralight
+ tlv
+ )
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+add_library(freefare SHARED ${LIBRARY_SOURCES})
+target_link_libraries(freefare ${LIBS})
+
+set(installheaders freefare.h)
+install(FILES ${installheaders} DESTINATION ${INCLUDE_INSTALL_DIR}/freefare COMPONENT headers)
+
+if(WIN32)
+ # On Windows the shared (runtime) library should be either in the same
+ # directory as the excutables or in the path, we add it to same directory
+ install(TARGETS freefare RUNTIME DESTINATION bin COMPONENT libraries)
+
+ # At compile time we need the .LIB file, we place it in the lib directory
+ install(TARGETS freefare ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers)
+else(WIN32)
+ install(TARGETS freefare LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
+endif(WIN32)