Skip to content

Commit

Permalink
Introduce GIT_REVISION and LIBNFC_CONFDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
ikspress committed Sep 1, 2024
1 parent df0a3be commit e11c30e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 39 deletions.
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
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@ 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)
SET(CMAKE_C_FLAGS " ${CMAKE_C_FLAGS}")
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})

# 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})

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

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

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 _XOPEN_SOURCE @_XOPEN_SOURCE@
#cmakedefine LIBNFC_CONFDIR "@LIBNFC_CONFDIR@"
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

0 comments on commit e11c30e

Please sign in to comment.