From a58ac6926dae427f44b7c542700ebe1c167a2b05 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 9 Sep 2009 12:32:41 +0000 Subject: [PATCH] Update CMake files in order to be able to compile under Windows 64bits. (Thanks to Fkooman) --- CMakeLists.txt | 4 +- README-Windows.txt | 145 +++++++++++++++++++++++---------- cmake_modules/FindLIBUSB.cmake | 47 +++++++++++ cmake_modules/FindPCSC.cmake | 41 ++++++++++ src/CMakeLists.txt | 4 +- 5 files changed, 196 insertions(+), 45 deletions(-) create mode 100644 cmake_modules/FindLIBUSB.cmake create mode 100644 cmake_modules/FindPCSC.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 26f7484..2549992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,9 +45,9 @@ ADD_SUBDIRECTORY(src) IF(MSVC) SET(CPACK_GENERATOR "NSIS") ELSE(MSVC) - SET(CPACK_GENERATOR "TGZ") + SET(CPACK_GENERATOR "TBZ2") ENDIF(MSVC) -SET(CPACK_PACKAGE_FILE_NAME "libnfc-${VERSION}-bin") +SET(CPACK_PACKAGE_FILE_NAME "libnfc-${VERSION}-bin-${CMAKE_SYSTEM_PROCESSOR}") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library") SET(CPACK_PACKAGE_VENDOR "Roel Verdult") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") diff --git a/README-Windows.txt b/README-Windows.txt index fcd5868..723b635 100644 --- a/README-Windows.txt +++ b/README-Windows.txt @@ -1,41 +1,104 @@ -Requirements -============ -This project uses CMake [1] to create a Visual Studio project from the -source files. - -It have been tested with: - -- Microsoft Visual C++ 2008 Express Edition, with SP1 [2] -- LibUsb-Win32 0.1.12.2 [3] -- NSIS 2.45 (to create Windows installer) [4] - -On Windows XP SP3. - -Compilation -=========== - -CMake can be used to create MSVC project files, then each MSVC can -be used to compile the project, create an installer, etc. - -MSVC project will create a shared library for Windows (nfc.dll), and -a library file (nfc.lib) to link your applications against. It will compile -examples against this shared library. Installer will install the DLL file -in the same directory as the examples if your goal was to be able to -run and install libnfc as a standard user. In a system wide installation -the DLL should be placed in "windows\system32" or any other directory in -Windows PATH. - -If you want your own tools to use libnfc you have to link them with "nfc.lib" -which can be found in "lib" subdirectory under the installation root. Headers -can be found in "include" subdirectory. - -In a "normal" Windows install this would be: -- "C:\Program Files\libnfc-x.x.x\lib" -- "C:\Program Files\libnfc-x.x.x\include" - - - -[1] http://www.cmake.org -[2] http://www.microsoft.com/express/vc/ -[3] http://libusb-win32.sourceforge.net/ -[4] http://nsis.sourceforge.net/Main_Page +Requirements - Running +====================== +In order to run the included tools, at least these dependencies should be +installed: + +- LibUsb-Win32 0.1.12.2 [1] +- Microsoft Visual C++ 2008 SP1 Redistributable Package [2] + +These C++ 2008 SP1 libraries are also part of "Microsoft .NET Framework 3.5 +Service Pack 1 and .NET Framework 3.5 Family" which can be obtained through +Windows Update. + +There are two versions of the redistributable package (one for x86 and one for +x64). Be sure which one is needed. + +Requirements - Development +========================== +This project uses CMake for creating a Visual Studio project from the +source files. + +The following software was used to create the libnfc distribution: + +- CMake 2.6.4 [3] +- Microsoft Windows SDK for Windows 7 (7.0) [4] +- Microsoft .NET framework 3.5 SP1 (Windows Update) +- LibUsb-Win32 0.1.12.2 [1] +- NSIS 2.45 (to create the installer) [5] +- 7-Zip 4.65 (for generating source archive) [6] + +This was tested on Windows XP SP3, but should work on Windows Vista and +Windows 7 as well. Even on 64 bit systems. + +Building +======== +To build the distribution the NMake Makefiles generator of CMake was used. Here +is an example of how to generate a distribution with the above mentioned +requirements fulfilled (it is assumed the CMake binaries are in the system +path, this is optional during installation of CMake): + +- Start -> Programs -> Microsoft Windows SDK v7.0 -> CMD shell +- Now it is possible to run CMake and NMake: + + C:\Program Files\Microsoft SDKs\Windows\v7.0> cd c:\dev\libnfc-read-only + C:\dev\libnfc-read-only> mkdir bin + C:\dev\libnfc-read-only> cd bin + C:\dev\libnfc-read-only\bin> cmake-gui .. + +Now you can configure the build. Press "Configure", specify "NMake Makefiles" +and then you have the opportunity to set some configuration variables. If you +don't want a Debug build change the variable CMAKE_BUILD_TYPE to "Release". + +Now run NMake: + + C:\dev\libnfc-read-only\bin> nmake package + +To create the binary package, or: + + C:\dev\libnfc-read-only\bin> nmake package_source + +To create the source archive. + +NMake will create a shared library for Windows (nfc.dll), and +a library file (nfc.lib) to link your applications against. It will compile +the tools against this shared library. The installer will install the +DLL file in the same directory as the tools as our goal was to be able to +run and install libnfc as a standard user. In a system wide installation +the DLL should be placed in "windows\system32" or any other directory in +the (system) path. + +If you want your own tools to use libnfc you have to link them with "nfc.lib" +which can be found in the "lib" directory under the installation root. The +header files can be found under "include" in the installation root. + +In a "normal" Windows install this would be: +- "C:\Program Files\libnfc-x.x.x\lib" +- "C:\Program Files\libnfc-x.x.x\include" + +You also need to copy the "nfc.dll" file to the same directory as your +application, or install it somewhere in the system path (see above). + +CMake can also be used to create the MSVC [7] project files instead of NMake +Makefiles, after which MSVC can be used to compile the project, create an +installer, etc. + +Building 64 Bit +=============== +Building on native 64 bit should work "out of the box". + +It is also possible to "cross compile" for 64 bit systems on a 32 bit system. +This can be accomplished by using the "setenv" command from the shell opened +in the previous section. Try "setenv /?" to see what is available. When cross +compiling the name of the binary installer package generated is not correct, +because CMake does not notice it is cross compiling. It should work fine +however. + +References +========== +[1] http://libusb-win32.sourceforge.net/ +[2] http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2 +[3] http://www.cmake.org +[4] http://msdn.microsoft.com/en-us/windows/bb980924.aspx +[5] http://nsis.sourceforge.net/Main_Page +[6] http://http://www.7-zip.org/ +[7] http://www.microsoft.com/express/vc/ diff --git a/cmake_modules/FindLIBUSB.cmake b/cmake_modules/FindLIBUSB.cmake new file mode 100644 index 0000000..d2822eb --- /dev/null +++ b/cmake_modules/FindLIBUSB.cmake @@ -0,0 +1,47 @@ +# This CMake script wants to use libusb functionality, therefore it looks +# for libusb include files and libraries. +# +# Operating Systems Supported: +# - Unix (requires pkg-config) +# Tested with Ubuntu 9.04 and Fedora 11 +# - Windows (requires MSVC) +# Tested with Windows XP +# +# This should work for both 32 bit and 64 bit systems. +# +# Author: F. Kooman +# + +IF(MSVC) + # Windows with Microsoft Visual C++ + FIND_PATH(LIBUSB_INCLUDE_DIRS usb.h "$ENV{ProgramFiles}/LibUSB-Win32/include") + IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") + # on x64 (win64) + FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc_x64") + ELSE(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") + # on x86 (win32) + FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc") + ENDIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") +ELSE(MSVC) + # If not MS Visual Studio we use PkgConfig + FIND_PACKAGE (PkgConfig) + IF(PKG_CONFIG_FOUND) + PKG_CHECK_MODULES(LIBUSB REQUIRED libusb) + ELSE(PKG_CONFIG_FOUND) + MESSAGE(FATAL_ERROR "Could not find PkgConfig") + ENDIF(PKG_CONFIG_FOUND) +ENDIF(MSVC) + +IF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES) + SET(LIBUSB_FOUND TRUE) +ENDIF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES) + +IF(LIBUSB_FOUND) + IF(NOT LIBUSB_FIND_QUIETLY) + MESSAGE(STATUS "Found LIBUSB: ${LIBUSB_LIBRARIES}") + ENDIF (NOT LIBUSB_FIND_QUIETLY) +ELSE(LIBUSB_FOUND) + IF(LIBUSB_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find LIBUSB") + ENDIF(LIBUSB_FIND_REQUIRED) +ENDIF(LIBUSB_FOUND) diff --git a/cmake_modules/FindPCSC.cmake b/cmake_modules/FindPCSC.cmake new file mode 100644 index 0000000..73150af --- /dev/null +++ b/cmake_modules/FindPCSC.cmake @@ -0,0 +1,41 @@ +# This CMake script wants to use PC/SC functionality, therefore it looks +# for PC/SC include files and libraries. +# +# Operating Systems Supported: +# - Unix (requires pkg-config) +# Tested with Ubuntu 9.04 and Fedora 11 +# - Windows (requires MSVC) +# Tested with Windows XP +# +# This should work for both 32 bit and 64 bit systems. +# +# Author: F. Kooman +# + +IF(MSVC) + # Windows with Microsoft Visual C++ + FIND_PATH(PCSC_INCLUDE_DIRS WinSCard.h "$ENV{INCLUDE}") + FIND_LIBRARY(PCSC_LIBRARIES NAMES WinSCard PATHS "$ENV{LIB}") +ELSE(MSVC) + # If not MS Visual Studio we use PkgConfig + FIND_PACKAGE (PkgConfig) + IF(PKG_CONFIG_FOUND) + PKG_CHECK_MODULES(PCSC REQUIRED libpcsclite) + ELSE(PKG_CONFIG_FOUND) + MESSAGE(FATAL_ERROR "Could not find PkgConfig") + ENDIF(PKG_CONFIG_FOUND) +ENDIF(MSVC) + +IF(PCSC_INCLUDE_DIRS AND PCSC_LIBRARIES) + SET(PCSC_FOUND TRUE) +ENDIF(PCSC_INCLUDE_DIRS AND PCSC_LIBRARIES) + +IF(PCSC_FOUND) + IF(NOT PCSC_FIND_QUIETLY) + MESSAGE(STATUS "Found PCSC: ${PCSC_LIBRARIES}") + ENDIF(NOT PCSC_FIND_QUIETLY) +ELSE(PCSC_FOUND) + IF(PCSC_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find PCSC") + ENDIF(PCSC_FIND_REQUIRED) +ENDIF(PCSC_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89dd1d9..3ee4dc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,8 +24,8 @@ IF(LIBNFC_LANG_C99 AND NOT MSVC) ENDIF(LIBNFC_LANG_C99 AND NOT MSVC) IF(MSVC) - # Hide some warnings, this should be fixed in the code instead! - ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS") + # We should fix the code, not hide warning! + #ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS") # Include the stdint headers, because MSVC does not have them INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../win32/stdint) ENDIF(MSVC)