Commit 54e0bdb6 authored by Alex Lian's avatar Alex Lian

Windows: Build updates

- Generate rc files from version.rc.in + CMake variable information in CMakeLists files
- Add step to generate .lib file for windows developers
- Re-structure tool flag usage, apparently ADD_DEFINTIONS adds them to _ALL_ tools. This is bad for rc files with the windres tool.

Needs other platform testing, as the flags have changed to fix Windows rc file generation.
parent eddc46fd
......@@ -29,7 +29,12 @@ 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")
IF(LIBNFC_DEBUG_OUTPUT)
ADD_DEFINITIONS(-DDEBUG -DLOG -g3)
ADD_DEFINITIONS(-DDEBUG -DLOG)
SET(CMAKE_C_FLAGS "-g3 ${CMAKE_C_FLAGS}")
SET(WIN32_MODE "debug")
SET(CMAKE_RC_FLAGS "-D_DEBUG ${CMAKE_RC_FLAGS}")
ELSE(LIBNFC_DEBUG_OUTPUT)
SET(WIN32_MODE "release")
ENDIF(LIBNFC_DEBUG_OUTPUT)
# Doxygen
......@@ -58,7 +63,7 @@ ENDIF(NOT DEFINED SHARE_INSTALL_PREFIX)
# Additonnal GCC flags
IF(CMAKE_COMPILER_IS_GNUCC)
# Make sure we will not miss some warnings ;)
ADD_DEFINITIONS(-Wall -pedantic -std=c99)
SET(CMAKE_C_FLAGS "-Wall -pedantic -std=c99 ${CMAKE_C_FLAGS}")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
# Workarounds for libusb in C99
......@@ -66,9 +71,11 @@ ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
IF(MINGW)
# force MinGW-w64 in 32bit mode
ADD_DEFINITIONS(-m32)
SET(CMAKE_SHARED_LINKER_FLAGS -m32)
SET(CMAKE_EXE_LINKER_FLAGS -m32)
SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET(CMAKE_MODULE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_SHARED_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-m32 --enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
ENDIF(MINGW)
IF(NOT WIN32)
......@@ -107,6 +114,23 @@ IF(LIBUSB_INCLUDE_DIRS)
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
ENDIF(LIBUSB_INCLUDE_DIRS)
# version.rc for Windows
IF(WIN32)
# Date for filling in rc file information
MACRO (GET_CURRENT_YEAR RESULT)
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
STRING(REGEX REPLACE ".*(..)/(..)/(....).*" "\\3" ${RESULT} ${${RESULT}})
ENDMACRO (GET_CURRENT_YEAR)
GET_CURRENT_YEAR(CURRENT_YEAR)
MESSAGE("Year for copyright is " ${CURRENT_YEAR})
SET(RC_COMMENT "${PACKAGE_NAME} library")
SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}")
SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll)
SET(RC_FILE_TYPE VFT_DLL)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/windows/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows/libnfc.rc @ONLY)
ENDIF(WIN32)
ADD_SUBDIRECTORY(libnfc)
ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(utils)
......
......@@ -14,7 +14,18 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc)
# Examples
FOREACH(source ${EXAMPLES-SOURCES})
ADD_EXECUTABLE(${source} ${source}.c)
SET (TARGETS ${source}.c)
IF(WIN32)
SET(RC_COMMENT "${PACKAGE_NAME} example")
SET(RC_INTERNAL_NAME ${source})
SET(RC_ORIGINAL_NAME ${source}.exe)
SET(RC_FILE_TYPE VFT_APP)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../windows/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY)
LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc)
ENDIF(WIN32)
ADD_EXECUTABLE(${source} ${TARGETS})
TARGET_LINK_LIBRARIES(${source} nfc)
TARGET_LINK_LIBRARIES(${source} nfcutils)
INSTALL(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples)
......
# Windows MinGW workarounds
IF(WIN32)
message("Adding in contrib win32 sources")
SET(WINDOWS_SOURCES ../contrib/win32/stdlib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32)
message("Win32: " ${WINDOWS_SOURCES})
# Add in the rc for version information in the dll
LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../windows/libnfc.rc)
ENDIF(WIN32)
# Library's chips
......@@ -52,16 +53,22 @@ IF(LIBUSB_FOUND)
TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES})
ENDIF(LIBUSB_FOUND)
IF(WIN32)
TARGET_LINK_LIBRARIES(nfc wsock32)
ENDIF(WIN32)
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0)
IF(WIN32)
# Libraries that are windows specific
TARGET_LINK_LIBRARIES(nfc wsock32)
IF(PCRE_FOUND)
TARGET_LINK_LIBRARIES(nfc ${PCRE_LIBRARIES})
ENDIF(PCRE_FOUND)
ADD_CUSTOM_COMMAND(
OUTPUT libnfc.lib
COMMAND dlltool -d ${CMAKE_CURRENT_SOURCE_DIR}/../windows/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../windows/win32/nfc.def
)
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
# 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 nfc RUNTIME DESTINATION bin COMPONENT libraries)
......
......@@ -17,6 +17,15 @@ TARGET_LINK_LIBRARIES(nfcutils nfc)
FOREACH(source ${UTILS-SOURCES})
SET (TARGETS ${source}.c)
IF(WIN32)
SET(RC_COMMENT "${PACKAGE_NAME} utility")
SET(RC_INTERNAL_NAME ${source})
SET(RC_ORIGINAL_NAME ${source}.exe)
SET(RC_FILE_TYPE VFT_APP)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../windows/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY)
LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc)
ENDIF(WIN32)
IF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic"))
LIST(APPEND TARGETS mifare)
ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic"))
......@@ -33,7 +42,6 @@ FOREACH(source ${UTILS-SOURCES})
TARGET_LINK_LIBRARIES(${source} nfc)
TARGET_LINK_LIBRARIES(${source} nfcutils)
INSTALL(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT utils)
ENDFOREACH(source)
......
#include "windows.h"
1 VERSIONINFO
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG|VS_FF_PRERELEASE
#else
FILEFLAGS 0L
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE @RC_FILE_TYPE@
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904e4"
BEGIN
VALUE "Comments", "@RC_COMMENT@\0"
VALUE "CompanyName", "libnfc.org\0"
VALUE "FileDescription", "\0"
VALUE "FileVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@.0\0"
VALUE "InternalName", "@RC_INTERNAL_NAME@ @WIN32_MODE@\0"
VALUE "LegalCopyright", "Copyright (C) @CURRENT_YEAR@\0"
VALUE "OriginalFilename", "@RC_ORIGINAL_NAME@\0"
VALUE "ProductName", "@PACKAGE_NAME@ @WIN32_MODE@\0"
VALUE "ProductVersion", "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@.0\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1252
END
END
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment