Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce GIT_REVISION and LIBNFC_CONFDIR #738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ build
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
Expand Down
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,29 @@ SET(PACKAGE_NAME "libnfc")
SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")

# config.h
FIND_PACKAGE(Git)
IF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
EXECUTE_PROCESS(
COMMAND ${GIT_EXECUTABLE} describe
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REVISION
)
STRING(REGEX REPLACE "\n$" "" GIT_REVISION "${GIT_REVISION}")
ENDIF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")

IF(WIN32)
SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32)
IF(NOT MINGW)
SET(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ${CMAKE_C_FLAGS}")
ENDIF(NOT MINGW)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
ELSE(WIN32)
SET(_XOPEN_SOURCE 600)
SET(SYSCONFDIR "/etc" CACHE PATH "System configuration directory")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
ADD_DEFINITIONS(-D_XOPEN_SOURCE=600)
ENDIF(WIN32)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

SET(LIBNFC_CONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/nfc" CACHE STRING "libnfc configuration directory")

# config.h
ADD_DEFINITIONS("-DHAVE_CONFIG_H")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)

Expand Down
4 changes: 2 additions & 2 deletions README-Windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ don't want a Debug build change the variable CMAKE_BUILD_TYPE to "Release".

If a non-GUI solution is preferred one can use:

C:\dev\libnfc-build> cmake -G "MinGW Makefiles"
-DCMAKE_BUILD_TYPE=Release ..\libnfc-read-only
C:\dev\libnfc-build> cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
-DLIBNFC_CONFDIR="./config" ..\libnfc-read-only

Now run mingw32-make to build:

Expand Down
3 changes: 1 addition & 2 deletions cmake/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ SUBDIRS = modules

EXTRA_DIST = \
FixBundle.cmake.in \
config_posix.h.cmake \
config_windows.h.cmake \
config.h.in \
LibNFCConfig.cmake.in \
LibNFCConfigVersion.cmake.in \
UseLibNFC.cmake
8 changes: 8 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifdef _WIN32
#include "contrib/windows.h"
#endif

#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
#cmakedefine GIT_REVISION "@GIT_REVISION@"
#cmakedefine LIBNFC_CONFDIR "@LIBNFC_CONFDIR@"
#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@
5 changes: 0 additions & 5 deletions cmake/config_posix.h.cmake

This file was deleted.

6 changes: 0 additions & 6 deletions cmake/config_windows.h.cmake

This file was deleted.

6 changes: 5 additions & 1 deletion libnfc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ IF(LIBUSB_FOUND)
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
ENDIF(LIBUSB_FOUND)

IF(LIBNFC_CONFFILES_MODE)
SET(CONF_SOURCES conf.c)
ENDIF(LIBNFC_CONFFILES_MODE)

# Library
SET(LIBRARY_SOURCES nfc.c nfc-device.c nfc-emulation.c nfc-internal.c conf.c iso14443-subr.c mirror-subr.c target-subr.c ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES})
SET(LIBRARY_SOURCES nfc.c nfc-device.c nfc-emulation.c nfc-internal.c iso14443-subr.c mirror-subr.c target-subr.c ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES} ${CONF_SOURCES})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

IF(LIBNFC_LOG)
Expand Down
16 changes: 2 additions & 14 deletions libnfc/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "conf.h"

#ifdef CONFFILES
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
Expand All @@ -45,16 +44,8 @@
#define LOG_CATEGORY "libnfc.config"
#define LOG_GROUP NFC_LOG_GROUP_CONFIG

#ifndef LIBNFC_SYSCONFDIR
// If this define does not already exists, we build it using SYSCONFDIR
#ifndef SYSCONFDIR
#error "SYSCONFDIR is not defined but required."
#endif // SYSCONFDIR
#define LIBNFC_SYSCONFDIR SYSCONFDIR"/nfc"
#endif // LIBNFC_SYSCONFDIR

#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf"
#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"
#define LIBNFC_CONFFILE LIBNFC_CONFDIR "/libnfc.conf"
#define LIBNFC_DEVICECONFDIR LIBNFC_CONFDIR "/devices.d"

static int
escaped_value(const char line[BUFSIZ], int i, char **value)
Expand Down Expand Up @@ -298,6 +289,3 @@ conf_load(nfc_context *context)
conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
}

#endif // CONFFILES