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

Fix CMake issues #737

Open
wants to merge 3 commits 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
204 changes: 91 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)
ikspress-archive marked this conversation as resolved.
Show resolved Hide resolved
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 \${prefix})
set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
set(libdir \${prefix}/${CMAKE_INSTALL_LIBDIR})

# 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,25 @@ SET(CPACK_COMPONENT_HEADERS_DISABLED TRUE)
SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
SET(CPACK_COMPONENT_EXAMPLES_DEPENDS libraries)

# Binary Package
if(WIN32)
set(CPACK_GENERATOR ZIP WIX)
elseif(APPLE)
set(CPACK_GENERATOR TGZ productbuild)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(CPACK_GENERATOR TGZ RPM DEB)

# Automatically include runtime dependencies (libc, libstdc++) fro Debian
# (RPM includes these dependencies automagically)
# YMMV, therefore commented
# set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "TRUE")
else()
set(CPACK_GENERATOR TGZ)
endif()
# 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@ )
Loading