Skip to content

Commit 84b313a

Browse files
committed
Introduce GIT_REVISION and LIBNFC_CONFDIR
1 parent df0a3be commit 84b313a

File tree

8 files changed

+31
-38
lines changed

8 files changed

+31
-38
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ build
1818
compile
1919
config.guess
2020
config.h
21-
config.h.in
2221
config.log
2322
config.status
2423
config.sub

CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@ SET(PACKAGE_NAME "libnfc")
1616
SET(PACKAGE_VERSION ${VERSION})
1717
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
1818

19-
# config.h
19+
FIND_PACKAGE(Git)
20+
IF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
21+
EXECUTE_PROCESS(
22+
COMMAND ${GIT_EXECUTABLE} describe
23+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
24+
OUTPUT_VARIABLE GIT_REVISION
25+
)
26+
STRING(REGEX REPLACE "\n$" "" GIT_REVISION "${GIT_REVISION}")
27+
ENDIF(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
28+
2029
IF(WIN32)
21-
SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
22-
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
2330
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32)
24-
IF(NOT MINGW)
25-
SET(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ${CMAKE_C_FLAGS}")
26-
ENDIF(NOT MINGW)
31+
SET(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ${CMAKE_C_FLAGS}")
2732
ELSE(WIN32)
2833
SET(_XOPEN_SOURCE 600)
29-
SET(SYSCONFDIR "/etc" CACHE PATH "System configuration directory")
30-
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
3134
ENDIF(WIN32)
32-
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
3335

36+
# config.h
37+
SET(LIBNFC_CONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/nfc" CACHE STRING "libnfc configuration directory")
3438
ADD_DEFINITIONS("-DHAVE_CONFIG_H")
39+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
40+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
3541

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

cmake/Makefile.am

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ SUBDIRS = modules
22

33
EXTRA_DIST = \
44
FixBundle.cmake.in \
5-
config_posix.h.cmake \
6-
config_windows.h.cmake \
5+
config.h.in \
76
LibNFCConfig.cmake.in \
87
LibNFCConfigVersion.cmake.in \
98
UseLibNFC.cmake

cmake/config.h.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifdef _WIN32
2+
#include "contrib/windows.h"
3+
#endif
4+
5+
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
6+
#cmakedefine GIT_REVISION "@GIT_REVISION@"
7+
#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@
8+
#cmakedefine LIBNFC_CONFDIR "@LIBNFC_CONFDIR@"

cmake/config_posix.h.cmake

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmake/config_windows.h.cmake

Lines changed: 0 additions & 6 deletions
This file was deleted.

libnfc/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ IF(LIBUSB_FOUND)
6060
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
6161
ENDIF(LIBUSB_FOUND)
6262

63+
IF(LIBNFC_CONFFILES_MODE)
64+
SET(CONF_SOURCES conf.c)
65+
ENDIF(LIBNFC_CONFFILES_MODE)
66+
6367
# Library
64-
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})
68+
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})
6569
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
6670

6771
IF(LIBNFC_LOG)

libnfc/conf.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "conf.h"
3232

33-
#ifdef CONFFILES
3433
#include <stdio.h>
3534
#include <stdlib.h>
3635
#include <ctype.h>
@@ -45,16 +44,8 @@
4544
#define LOG_CATEGORY "libnfc.config"
4645
#define LOG_GROUP NFC_LOG_GROUP_CONFIG
4746

48-
#ifndef LIBNFC_SYSCONFDIR
49-
// If this define does not already exists, we build it using SYSCONFDIR
50-
#ifndef SYSCONFDIR
51-
#error "SYSCONFDIR is not defined but required."
52-
#endif // SYSCONFDIR
53-
#define LIBNFC_SYSCONFDIR SYSCONFDIR"/nfc"
54-
#endif // LIBNFC_SYSCONFDIR
55-
56-
#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf"
57-
#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"
47+
#define LIBNFC_CONFFILE LIBNFC_CONFDIR "/libnfc.conf"
48+
#define LIBNFC_DEVICECONFDIR LIBNFC_CONFDIR "/devices.d"
5849

5950
static int
6051
escaped_value(const char line[BUFSIZ], int i, char **value)
@@ -298,6 +289,3 @@ conf_load(nfc_context *context)
298289
conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);
299290
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
300291
}
301-
302-
#endif // CONFFILES
303-

0 commit comments

Comments
 (0)