Skip to content

Commit

Permalink
Fix CMake issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ikspress-archive committed Jul 25, 2024
1 parent df0a3be commit 44f54a9
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 214 deletions.
191 changes: 78 additions & 113 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
cmake_minimum_required (VERSION 2.6)

if (NOT DEFINED CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
endif ()

project (libnfc C)

SET(VERSION_MAJOR "1")
Expand All @@ -15,6 +11,9 @@ SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
SET(PACKAGE_NAME "libnfc")
SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
SET(PACKAGE_DESCRIPTION "Near Field Communication (NFC) library")

INCLUDE(GNUInstallDirs)

# config.h
IF(WIN32)
Expand Down Expand Up @@ -67,31 +66,23 @@ ENDIF(LIBNFC_CONFFILES_MODE)
option (BUILD_EXAMPLES "build examples ON/OFF" ON)
option (BUILD_UTILS "build utils ON/OFF" ON)

option (BUILD_DEBPKG "build debian package ON/OFF" OFF)
if(MSVC)
option (BUILD_MANUAL "build man-pages ON/OFF" OFF)
else(MSVC)
option (BUILD_MANUAL "build man-pages ON/OFF" ON)
endif(MSVC)

option (INSTALL_BUNDLE "Assemble a standalone bundle application" OFF)

# Doxygen
SET(builddir "${CMAKE_BINARY_DIR}")
SET(top_srcdir "${CMAKE_SOURCE_DIR}")
INCLUDE(UseDoxygen)

IF(DEFINED CMAKE_INSTALL_LIBDIR)
SET(libdir ${CMAKE_INSTALL_LIBDIR})
ELSE(DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib)
SET(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
ENDIF(DEFINED CMAKE_INSTALL_LIBDIR)

IF(DEFINED INCLUDE_INSTALL_DIR)
SET(includedir ${INCLUDE_INSTALL_DIR})
ELSE(DEFINED INCLUDE_INSTALL_DIR)
SET(INCLUDE_INSTALL_DIR include)
SET(includedir ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR})
ENDIF(DEFINED INCLUDE_INSTALL_DIR)

IF(NOT DEFINED SHARE_INSTALL_PREFIX)
SET(SHARE_INSTALL_PREFIX share)
ENDIF(NOT DEFINED SHARE_INSTALL_PREFIX)
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
SET(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})

# Additonnal GCC flags
IF(CMAKE_COMPILER_IS_GNUCC)
Expand Down Expand Up @@ -126,28 +117,36 @@ IF(MINGW)
ENDIF (NOT DLLTOOL)
ENDIF(MINGW)

# pkg-config
IF(NOT WIN32)
# Set some pkg-config variables
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix ${CMAKE_INSTALL_PREFIX})
SET(PACKAGE "libnfc")
IF(LIBNFC_DRIVER_PN53X_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_PN53X_USB)
IF(LIBNFC_DRIVER_ACR122_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_ACR122_USB)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
IF(LIBNFC_DRIVER_PN53X_USB)
SET(PKG_REQ ${PKG_REQ} "libusb-0.1")
ENDIF(LIBNFC_DRIVER_PN53X_USB)
IF(LIBNFC_DRIVER_ACR122_USB)
SET(PKG_REQ ${PKG_REQ} "libusb-0.1")
ENDIF(LIBNFC_DRIVER_ACR122_USB)
ELSE(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
IF(LIBNFC_DRIVER_PN53X_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_PN53X_USB)
IF(LIBNFC_DRIVER_ACR122_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_ACR122_USB)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
IF(LIBNFC_DRIVER_PCSC)
SET(PKG_REQ ${PKG_REQ} "libpcsclite")
ENDIF(LIBNFC_DRIVER_PCSC)
IF(LIBNFC_DRIVER_ACR122_PCSC)
SET(PKG_REQ ${PKG_REQ} "libpcsclite")
ENDIF(LIBNFC_DRIVER_ACR122_PCSC)
# CMake lists are separated by a semi colon, replace with colon
STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
ENDIF(NOT WIN32)
LIST(SORT PKG_REQ)
LIST(REMOVE_DUPLICATES PKG_REQ)
# CMake lists are separated by a semi colon, replace with colon
STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

INCLUDE(LibnfcDrivers)

Expand All @@ -167,16 +166,15 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(PCSC_INCLUDE_DIRS)
IF(PCSC_FOUND)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
ENDIF(PCSC_INCLUDE_DIRS)
ENDIF(PCSC_FOUND)

IF(LIBUSB_INCLUDE_DIRS)
IF(LIBUSB_FOUND)
INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS})
SET(LIBUSB_FOUND TRUE)
ENDIF(LIBUSB_INCLUDE_DIRS)
ENDIF(LIBUSB_FOUND)

# version.rc for Windows
IF(WIN32)
Expand All @@ -202,72 +200,40 @@ if (BUILD_EXAMPLES)
add_subdirectory (examples)
endif ()

if (NOT MSVC)
# config script install path
if ( NOT DEFINED LIBNFC_CMAKE_CONFIG_DIR )
set ( LIBNFC_CMAKE_CONFIG_DIR lib${LIB_SUFFIX}/cmake/libnfc )
endif ()

set ( LIBNFC_INCLUDE_DIR ${includedir} )
set ( LIBNFC_INCLUDE_DIRS ${LIBNFC_INCLUDE_DIR} )
list ( APPEND LIBNFC_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIRS} )
set ( LIBNFC_LIBRARY nfc )
set ( LIBNFC_LIBRARIES ${LIBNFC_LIBRARY} )
list ( APPEND LIBNFC_LIBRARIES ${LIBUSB_LIBRARIES} )
set ( LIBNFC_LIBRARY_DIRS ${libdir} )
set ( LIBNFC_ROOT_DIR ${prefix} )
set ( LIBNFC_VERSION_STRING ${VERSION} )
set ( LIBNFC_VERSION_MAJOR ${VERSION_MAJOR} )
set ( LIBNFC_VERSION_MINOR ${VERSION_MINOR} )
set ( LIBNFC_VERSION_PATCH ${VERSION_PATCH} )

set ( LIBNFC_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBNFC_CMAKE_CONFIG_DIR}/UseLibNFC.cmake )



if(CMAKE_VERSION VERSION_LESS 2.8.8)
configure_file ( cmake/LibNFCConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake @ONLY )
configure_file ( cmake/LibNFCConfigVersion.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfigVersion.cmake @ONLY )
else ()
include(CMakePackageConfigHelpers)
configure_package_config_file (
cmake/LibNFCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
INSTALL_DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
PATH_VARS
LIBNFC_USE_FILE
LIBNFC_ROOT_DIR
LIBNFC_INCLUDE_DIR
LIBNFC_INCLUDE_DIRS
LIBNFC_LIBRARY_DIRS
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file (
LibNFCConfigVersion.cmake
VERSION ${LIBNFC_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
endif ()

install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfigVersion.cmake
cmake/UseLibNFC.cmake
DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
)

endif ()

# Binary Package
IF(WIN32)
SET(CPACK_GENERATOR "ZIP")
ELSE(WIN32)
SET(CPACK_GENERATOR "TBZ2")
IF(BUILD_DEBPKG)
SET(CPACK_GENERATOR "DEB")
ENDIF(BUILD_DEBPKG)
ENDIF(WIN32)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library")
set(INCLUDE_INSTALL_DIRS ${includedir})
set(LIBNFC_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/LibNFC)
set(LIBNFC_DEFINITIONS "")
set(LIBNFC_LIBRARIES ${LIBNFC_LIBRARY})
list(APPEND LIBNFC_LIBRARIES ${PKG_REQ})
set(LIBNFC_LIBRARY nfc)
set(LIBNFC_USE_FILE UseLibNFC.cmake)
set(LIBRARY_INSTALL_DIRS ${libdir})

include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/LibNFCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
INSTALL_DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
PATH_VARS INCLUDE_INSTALL_DIRS LIBRARY_INSTALL_DIRS
)
write_basic_package_version_file(
LibNFCConfigVersion.cmake
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfigVersion.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseLibNFC.cmake
DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
)

#install required libraries
IF(INSTALL_BUNDLE)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/FixBundle.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FixBundle.cmake @ONLY)
INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/FixBundle.cmake)
ENDIF(INSTALL_BUNDLE)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${PACKAGE_DESCRIPTION})
SET(CPACK_PACKAGE_VENDOR "Roel Verdult")
SET(CPACK_PACKAGE_CONTACT "Roel Verdult <[email protected]>")

Expand Down Expand Up @@ -295,13 +261,12 @@ SET(CPACK_COMPONENT_HEADERS_DISABLED TRUE)
SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
SET(CPACK_COMPONENT_EXAMPLES_DEPENDS libraries)

# Binary Package
SET(CPACK_GENERATOR "ZIP" CACHE STRING "Default binary package generator")
# Source Package
IF(WIN32)
SET(CPACK_SOURCE_GENERATOR "ZIP")
ELSE(WIN32)
SET(CPACK_SOURCE_GENERATOR "ZIP;TBZ2")
ENDIF(WIN32)

SET(CPACK_SOURCE_GENERATOR "SOURCE_ZIP" CACHE STRING "Default source package generator")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "libnfc-${VERSION}")
SET(CPACK_SOURCE_IGNORE_FILES "~$" "/\\\\.git/" "bin/")

INCLUDE(InstallRequiredSystemLibraries)
INCLUDE(CPack)
2 changes: 1 addition & 1 deletion cmake/FixBundle.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ SET(bundle "${CMAKE_INSTALL_PREFIX}/bin/nfc-list@CMAKE_EXECUTABLE_SUFFIX@")
# set other_libs to a list of additional libs that cannot be reached by dependency analysis
SET(other_libs "")

SET(dirs "@LIBUSB_LIBRARY_DIR@")
SET(dirs "@LIBUSB_LIBRARY_DIRS@")

fixup_bundle("${bundle}" "${other_libs}" "${dirs}")
23 changes: 10 additions & 13 deletions cmake/LibNFCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
# LIBNFC_FOUND - True if LibNFC was found on your system
# LIBNFC_USE_FILE - The file making LibNFC usable
# LIBNFC_DEFINITIONS - Definitions needed to build with LibNFC
# LIBNFC_INCLUDE_DIR - Directory where nfc/nfc.h can be found
# LIBNFC_INCLUDE_DIRS - List of directories of LibNFC and it's dependencies
# LIBNFC_LIBRARY - LibNFC library location
# LIBNFC_LIBRARIES - List of libraries to link against LibNFC library
# LIBNFC_LIBRARY_DIRS - List of directories containing LibNFC' libraries
# LIBNFC_ROOT_DIR - The base directory of LibNFC
# LIBNFC_VERSION_STRING - A human-readable string containing the version
# LIBNFC_VERSION_MAJOR - The major version of LibNFC
# LIBNFC_VERSION_MINOR - The minor version of LibNFC
# LIBNFC_VERSION_PATCH - The patch version of LibNFC

set ( LIBNFC_FOUND 1 )
set ( LIBNFC_USE_FILE "@LIBNFC_USE_FILE@" )
@PACKAGE_INIT@

set ( LIBNFC_FOUND TRUE )
set ( LIBNFC_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/@LIBNFC_USE_FILE@" )

set ( LIBNFC_DEFINITIONS "@LIBNFC_DEFINITIONS@" )
set ( LIBNFC_INCLUDE_DIR "@LIBNFC_INCLUDE_DIR@" )
set ( LIBNFC_INCLUDE_DIRS "@LIBNFC_INCLUDE_DIRS@" )
set ( LIBNFC_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIRS@" )
set ( LIBNFC_LIBRARY "@LIBNFC_LIBRARY@" )
set ( LIBNFC_LIBRARIES "@LIBNFC_LIBRARIES@" )
set ( LIBNFC_LIBRARY_DIRS "@LIBNFC_LIBRARY_DIRS@" )
set ( LIBNFC_ROOT_DIR "@LIBNFC_ROOT_DIR@" )

set ( LIBNFC_VERSION_STRING "@LIBNFC_VERSION_STRING@" )
set ( LIBNFC_VERSION_MAJOR "@LIBNFC_VERSION_MAJOR@" )
set ( LIBNFC_VERSION_MINOR "@LIBNFC_VERSION_MINOR@" )
set ( LIBNFC_VERSION_PATCH "@LIBNFC_VERSION_PATCH@" )
set ( LIBNFC_LIBRARY_DIRS "@PACKAGE_LIBRARY_INSTALL_DIRS@" )

set ( LIBNFC_VERSION_STRING "@VERSION@" )
set ( LIBNFC_VERSION_MAJOR @VERSION_MAJOR@ )
set ( LIBNFC_VERSION_MINOR @VERSION_MINOR@ )
set ( LIBNFC_VERSION_PATCH @VERSION_PATCH@ )
78 changes: 22 additions & 56 deletions cmake/modules/FindLIBUSB.cmake
Original file line number Diff line number Diff line change
@@ -1,63 +1,29 @@
# This CMake script wants to use libusb functionality, therefore it looks
# for libusb include files and libraries.
# - Try to find libusb or libusb-win32
# Once done this will define
#
# Operating Systems Supported:
# - Unix (requires pkg-config)
# Tested with Ubuntu 9.04 and Fedora 11
# - Windows (requires MinGW)
# Tested with Windows XP/Windows 7
#
# This should work for both 32 bit and 64 bit systems.
#
# Author: F. Kooman <[email protected]>
# LIBUSB_FOUND - True if libusb found
# LIBUSB_INCLUDE_DIRS - The path to the libusb headers
# LIBUSB_LIBRARY_DIRS - The path to the libusb library
# LIBUSB_LIBRARIES - The libraries needed by libusb
#

# FreeBSD has built-in libusb since 800069
IF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
EXEC_PROGRAM(sysctl ARGS -n kern.osreldate OUTPUT_VARIABLE FREEBSD_VERSION)
SET(MIN_FREEBSD_VERSION 800068)
IF(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION})
SET(LIBUSB_FOUND TRUE)
SET(LIBUSB_INCLUDE_DIRS "/usr/include")
SET(LIBUSB_LIBRARIES "usb")
SET(LIBUSB_LIBRARY_DIRS "/usr/lib/")
ENDIF(FREEBSD_VERSION GREATER ${MIN_FREEBSD_VERSION})
ENDIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
FIND_PACKAGE(PkgConfig)
# Skip searching for libusb-0.1 on Windows, use libusb-win32 instead
IF(PKG_CONFIG_FOUND AND NOT WIN32)
PKG_SEARCH_MODULE(LIBUSB libusb libusb-0.1)
PKG_CHECK_MODULES(LIBUSB ${LIBUSB_MODULE_NAME})
ENDIF(PKG_CONFIG_FOUND AND NOT WIN32)

IF(NOT LIBUSB_FOUND)
IF(WIN32)
IF(MINGW)
FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/include" NO_SYSTEM_ENVIRONMENT_PATH)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/lib/gcc")
SET(LIBUSB_LIBRARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/bin/x86/")
ELSE(MINGW)
FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "$ENV{ProgramW6432}/libusb-win32/include" NO_SYSTEM_ENVIRONMENT_PATH)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramW6432}/libusb-win32/lib/msvc_x64")
SET(LIBUSB_LIBRARY_DIR "$ENV{ProgramW6432}/libusb-win32/bin/amd64/")
ENDIF(MINGW)
# Must fix up variable to avoid backslashes during packaging
STRING(REGEX REPLACE "\\\\" "/" LIBUSB_LIBRARY_DIR ${LIBUSB_LIBRARY_DIR})
ELSE(WIN32)
# If not under Windows we use PkgConfig
FIND_PACKAGE (PkgConfig)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(LIBUSB REQUIRED libusb)
ELSE(PKG_CONFIG_FOUND)
MESSAGE(FATAL_ERROR "Could not find PkgConfig")
ENDIF(PKG_CONFIG_FOUND)
ENDIF(WIN32)

IF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES)
SET(LIBUSB_FOUND TRUE)
ENDIF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES)
FIND_PATH(LIBUSB_INCLUDE_DIRS NAMES usb.h lusb0_usb.h)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb libusb0)
GET_FILENAME_COMPONENT(LIBUSB_LIBRARY_DIRS ${LIBUSB_LIBRARIES} PATH CACHE)
ENDIF(NOT LIBUSB_FOUND)

IF(LIBUSB_FOUND)
IF(NOT LIBUSB_FIND_QUIETLY)
MESSAGE(STATUS "Found LIBUSB: ${LIBUSB_LIBRARIES} ${LIBUSB_INCLUDE_DIRS}")
ENDIF (NOT LIBUSB_FIND_QUIETLY)
ELSE(LIBUSB_FOUND)
IF(LIBUSB_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find LIBUSB")
ENDIF(LIBUSB_FIND_REQUIRED)
ENDIF(LIBUSB_FOUND)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB REQUIRED_VARS
LIBUSB_INCLUDE_DIRS
LIBUSB_LIBRARIES
LIBUSB_LIBRARY_DIRS
)
MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIRS LIBUSB_LIBRARIES LIBUSB_LIBRARY_DIRS)
Loading

0 comments on commit 44f54a9

Please sign in to comment.