From 84b313abcc8e79128efdb9302e63aad2e0522d84 Mon Sep 17 00:00:00 2001 From: Yang Kun <91833768+ikspress@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:58:12 +0800 Subject: [PATCH] Introduce GIT_REVISION and LIBNFC_CONFDIR --- .gitignore | 1 - CMakeLists.txt | 24 +++++++++++++++--------- cmake/Makefile.am | 3 +-- cmake/config.h.in | 8 ++++++++ cmake/config_posix.h.cmake | 5 ----- cmake/config_windows.h.cmake | 6 ------ libnfc/CMakeLists.txt | 6 +++++- libnfc/conf.c | 16 ++-------------- 8 files changed, 31 insertions(+), 38 deletions(-) create mode 100644 cmake/config.h.in delete mode 100644 cmake/config_posix.h.cmake delete mode 100644 cmake/config_windows.h.cmake diff --git a/.gitignore b/.gitignore index c0baedf7..73b9157d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ build compile config.guess config.h -config.h.in config.log config.status config.sub diff --git a/CMakeLists.txt b/CMakeLists.txt index a8605fa4..8348f386 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,22 +16,28 @@ 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 "-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ${CMAKE_C_FLAGS}") 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) ENDIF(WIN32) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) +# config.h +SET(LIBNFC_CONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/nfc" CACHE STRING "libnfc configuration directory") 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) diff --git a/cmake/Makefile.am b/cmake/Makefile.am index 904f6325..8d42a2fa 100644 --- a/cmake/Makefile.am +++ b/cmake/Makefile.am @@ -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 diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..084914ed --- /dev/null +++ b/cmake/config.h.in @@ -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@" diff --git a/cmake/config_posix.h.cmake b/cmake/config_posix.h.cmake deleted file mode 100644 index 72d4a74d..00000000 --- a/cmake/config_posix.h.cmake +++ /dev/null @@ -1,5 +0,0 @@ -#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" -#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" -#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" -#cmakedefine _XOPEN_SOURCE @_XOPEN_SOURCE@ -#cmakedefine SYSCONFDIR "@SYSCONFDIR@" diff --git a/cmake/config_windows.h.cmake b/cmake/config_windows.h.cmake deleted file mode 100644 index 34fb2e64..00000000 --- a/cmake/config_windows.h.cmake +++ /dev/null @@ -1,6 +0,0 @@ -#include "contrib/windows.h" - -#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@" -#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" -#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@" -#cmakedefine LIBNFC_SYSCONFDIR "@LIBNFC_SYSCONFDIR@" diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index d3321778..6c56d584 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -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) diff --git a/libnfc/conf.c b/libnfc/conf.c index 785c310e..3d906b2f 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -30,7 +30,6 @@ #include "conf.h" -#ifdef CONFFILES #include #include #include @@ -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) @@ -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 -