Index: b/CMakeLists.txt =================================================================== --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,167 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +cmake_minimum_required( VERSION 2.8 ) + + +##### general package setup ##################### + +project( pcsc-lite ) + +set( PACKAGE ${CMAKE_PROJECT_NAME} ) +set( VERSION 1.4.102 ) + + +##### optional stuff ############################ + +option( WITH_DEBUGATR "Enable ATR debug messages from pcscd" OFF ) +option( WITH_LIBHAL "Enable build with libhal" OFF ) +option( WITH_LIBUSB "Enable build with libusb" ON ) +option( WITH_SCF "Use SCF for reader support" OFF ) + +set( PCSCLITE_HP_DROPDIR ${CMAKE_INSTALL_PREFIX}/pcsc/drivers + CACHE PATH "Directory containing USB drivers" ) +set( USE_IPCDIR /var/run/pcscd + CACHE PATH "Directory containing IPC files" ) + + +##### include essential cmake modules ########### + +include( CheckFunctionExists ) +include( CheckIncludeFiles ) +include( CheckLibraryExists ) +include( FindPkgConfig ) +include( TestBigEndian ) +include( GNUInstallDirs OPTIONAL ) + + +##### include our cmake modules ################# + +set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" ) + +include( TDEMacros ) +tde_setup_architecture_flags( ) + + +##### setup install paths ####################### + +if( CMAKE_INSTALL_LIBDIR ) + tde_setup_install_path( LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ) +endif( ) + +include( TDESetupPaths ) +tde_setup_paths( ) + + +#### pkg-config variables ####################### + +set( prefix ${CMAKE_INSTALL_PREFIX} ) +string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" + exec_prefix ${EXEC_INSTALL_PREFIX} ) +string( REGEX REPLACE "^${EXEC_INSTALL_PREFIX}" "\${exec_prefix}" + libdir ${LIB_INSTALL_DIR} ) +string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" + includedir ${INCLUDE_INSTALL_DIR} ) + +set( confdir ${SYSCONF_INSTALL_DIR} ) +set( confdir_exp ${SYSCONF_INSTALL_DIR} ) +set( ipcdir ${USE_IPCDIR} ) +set( localstatedir_exp /var/run CACHE PATH "" ) +set( sbindir_exp ${SBIN_INSTALL_DIR} ) +set( sysconfdir_exp ${SYSCONF_INSTALL_DIR} ) +set( usbdropdir ${PCSCLITE_HP_DROPDIR} ) + + +##### configure checks ########################## + +set( PCSC_ARCH "${CMAKE_SYSTEM_NAME}" ) +set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} ${PCSC_ARCH}" ) + +check_function_exists( daemon HAVE_DAEMON ) +check_function_exists( getopt_long HAVE_GETOPT_LONG ) +check_function_exists( nanosleep HAVE_NANOSLEEP ) +check_function_exists( strlcat HAVE_STRLCAT ) +check_function_exists( strlcpy HAVE_STRLCPY ) +check_function_exists( vsnprintf HAVE_VSNPRINTF ) +check_include_files( "dlfcn.h" HAVE_DLFCN_H ) +check_include_files( "dl.h" HAVE_DL_H ) +check_include_files( "getopt.h" HAVE_GETOPT_H ) +check_include_files( "syslog.h" HAVE_SYSLOG_H ) +check_include_files( "sys/filio.h" HAVE_SYS_FILIO_H ) + +set( DL_LIBRARIES dl ) +check_library_exists( ${DL_LIBRARIES} dlopen /lib HAVE_LIBDL ) +if( NOT HAVE_LIBDL ) + unset( DL_LIBRARIES ) + check_function_exists( dlopen HAVE_DLOPEN ) + if( HAVE_DLOPEN ) + set( HAVE_LIBDL 1 ) + endif( HAVE_DLOPEN ) +endif( NOT HAVE_LIBDL ) + +if( WITH_LIBHAL ) + pkg_check_modules( LIBHAL hal ) + if( NOT LIBHAL_FOUND ) + tde_message_fatal( "libhal are required but not found on your system" ) + endif( NOT LIBHAL_FOUND ) + + set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} libhal" ) + set( HAVE_LIBHAL 1 ) +endif( WITH_LIBHAL ) + +if( WITH_LIBUSB ) + pkg_check_modules( LIBUSB libusb ) + if( NOT LIBUSB_FOUND ) + tde_message_fatal( "libusb are required but not found on your system" ) + endif( NOT LIBUSB_FOUND ) + + set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} libusb" ) + set( HAVE_LIBUSB 1 ) +endif( WITH_LIBUSB ) + +if( WITH_SCF ) + set( SMARTCARD_LIBRARIES smartcard ) + check_library_exists( ${SMARTCARD_LIBRARIES} SCF_strerror "" HAVE_SCF ) + if( NOT HAVE_SCF ) + tde_message_fatal( "smartcard lib are required but not found on your system" ) + endif( NOT HAVE_SCF ) +endif( WITH_SCF ) + +find_package(FLEX) +find_package(Threads) + +test_big_endian( HAVE_BIGENDIAN ) +if( HAVE_BIGENDIAN ) + set( host_to_ccid_16 "((((x) >> 8) & 0xFF) + ((x & 0xFF) << 8))" ) + set( host_to_ccid_32 "((((x) >> 24) & 0xFF) + (((x) >> 8) & 0xFF00) + ((x & 0xFF00) << 8) + (((x) & 0xFF) << 24))" ) +else( HAVE_BIGENDIAN ) + set( host_to_ccid_16 "(x)" ) + set( host_to_ccid_32 "(x)" ) +endif( HAVE_BIGENDIAN ) + +set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} usbdropdir=${usbdropdir}" ) +if( WITH_DEBUGATR ) + set( ATR_DEBUG 1) + set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} debugatr" ) +endif( WITH_DEBUGATR ) +set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} confdir=${confdir}" ) +set( PCSCLITE_FEATURES "${PCSCLITE_FEATURES} ipcdir=${ipcdir}" ) + + +##### write configure files ##################### + +configure_file( config.h.cmake config.h @ONLY ) +add_definitions( -DHAVE_CONFIG_H ) + + +##### build ##################################### + +tde_auto_add_subdirectories() Index: b/config.h.cmake =================================================================== --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,65 @@ + +/* display ATR parsing debug messages. */ +#cmakedefine ATR_DEBUG + +/* Define to 1 if you have the `daemon' function. */ +#cmakedefine HAVE_DAEMON + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DLFCN_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_DL_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_GETOPT_H + +/* Define to 1 if you have the `getopt_long' function. */ +#cmakedefine HAVE_GETOPT_LONG + +/* Libhal is available */ +#cmakedefine HAVE_LIBHAL + +/* Libusb is available */ +#cmakedefine HAVE_LIBUSB + +/* Define to 1 if you have the `nanosleep' function. */ +#cmakedefine HAVE_NANOSLEEP + +/* Define to 1 if you have the `strlcat' function. */ +#cmakedefine HAVE_STRLCAT + +/* Define to 1 if you have the `strlcpy' function. */ +#cmakedefine HAVE_STRLCPY + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYSLOG_H + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_FILIO_H + +/* Define to 1 if you have the `vsnprintf' function. */ +#cmakedefine HAVE_VSNPRINTF + +/* Name of package */ +#define PACKAGE "@CMAKE_PROJECT_NAME@" + +/* Enabled PC/SC lite features */ +#define PCSCLITE_FEATURES "@PCSCLITE_FEATURES@" + +/* directory containing USB drivers */ +#cmakedefine PCSCLITE_HP_DROPDIR "@PCSCLITE_HP_DROPDIR@" + +/* PC/SC target architecture */ +#define PCSC_ARCH "@PCSC_ARCH@" + +/* Define to necessary symbol if this constant uses a non-standard name on + your system. */ +#cmakedefine PTHREAD_CREATE_JOINABLE @PTHREAD_CREATE_JOINABLE@ + +/* directory containing IPC files */ +#cmakedefine USE_IPCDIR "@USE_IPCDIR@" + +/* Version number of package */ +#cmakedefine VERSION "@VERSION@" + Index: b/doc/CMakeLists.txt =================================================================== --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,43 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + + +##### man pages ################################# + +configure_file( pcscd.8.in pcscd.8 @ONLY ) +configure_file( reader.conf.5.in reader.conf.5 @ONLY ) +configure_file( update-reader.conf.8.in update-reader.conf.8 @ONLY ) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/reader.conf.5 + DESTINATION + ${MAN_INSTALL_DIR}/man5 +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/pcscd.8 + ${CMAKE_CURRENT_BINARY_DIR}/update-reader.conf.8 + DESTINATION + ${MAN_INSTALL_DIR}/man8 +) + + +##### api doc ################################### + +configure_file( doxygen.conf.in doxygen.conf @ONLY ) + + +##### subdir #################################### + +tde_auto_add_subdirectories() + Index: b/doc/example/CMakeLists.txt =================================================================== --- /dev/null +++ b/doc/example/CMakeLists.txt @@ -0,0 +1,32 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}/src + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_BINARY_DIR}/src/PCSC + ${CMAKE_SOURCE_DIR}/src/PCSC + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} +) + + +##### pcsc_demo ################################# + +set( target pcsc_demo ) + +tde_add_executable( + ${target} + SOURCES pcsc_demo.c + LINK pcsclite-shared +) + Index: b/etc/CMakeLists.txt =================================================================== --- /dev/null +++ b/etc/CMakeLists.txt @@ -0,0 +1,21 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + + +configure_file( pcscd.init.in pcscd.init @ONLY ) +configure_file( reader.conf.in reader.conf @ONLY ) +configure_file( update-reader.conf.in update-reader.conf @ONLY ) + +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/reader.conf + DESTINATION ${SYSCONF_INSTALL_DIR}/reader.conf.d ) +install( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/update-reader.conf + DESTINATION ${SBIN_INSTALL_DIR} ) + Index: b/src/CMakeLists.txt =================================================================== --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,200 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/PCSC + ${CMAKE_CURRENT_SOURCE_DIR}/PCSC +) + + +#### pkg-config ################################# + +configure_file( libpcsclite.pc.in libpcsclite.pc @ONLY ) +install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libpcsclite.pc + DESTINATION ${PKGCONFIG_INSTALL_DIR} ) + + +##### build subdir ############################## + +tde_auto_add_subdirectories() + + +#### pcsclite library ########################### + +set( target pcsclite ) + +if( HAVE_SCF ) + set( PCSC_CLIENT_SRC winscard_scf.c ) +else( HAVE_SCF ) + set( PCSC_CLIENT_SRC winscard_clnt.c ) +endif( HAVE_SCF ) + +set( ${target}_SRCS + debug.c + debug.h + dyn_hpux.c + dyn_macosx.c + dyn_unix.c + error.c + ${PCSC_CLIENT_SRC} + strlcat.c + strlcpy.c + sys_unix.c + thread_unix.c + utils.c + winscard_msg.c +) + +tde_add_library( + ${target} SHARED + VERSION 1.0.0 + SOURCES ${${target}_SRCS} + LINK ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES} ${SMARTCARD_LIBRARIES} + DESTINATION ${LIB_INSTALL_DIR} +) + +tde_add_library( + ${target} STATIC_PIC + SOURCES ${${target}_SRCS} + LINK ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES} ${SMARTCARD_LIBRARIES} + DESTINATION ${LIB_INSTALL_DIR} +) + +set_property( + TARGET ${target}-shared + APPEND PROPERTY COMPILE_DEFINITIONS + LIBPCSCLITE +) + +set_property( + TARGET ${target}-static + APPEND PROPERTY COMPILE_DEFINITIONS + LIBPCSCLITE +) + + +#### pcscd ####################################### + +if( NOT HAVE_SCF ) + + set( target pcscd ) + + set( ${target}_SRCS + atrhandler.c + atrhandler.h + configfile.h + ${CMAKE_CURRENT_BINARY_DIR}/configfile.c + debuglog.c + dyn_generic.h + dyn_hpux.c + dyn_macosx.c + dyn_unix.c + eventhandler.c + eventhandler.h + hotplug_generic.c + hotplug.h + hotplug_libhal.c + hotplug_libusb.c + hotplug_linux.c + hotplug_macosx.c + ifdwrapper.c + ifdwrapper.h + misc.h + parser.h + pcscdaemon.c + pcscd.h + pcscd.h.in + PCSC/debuglog.h + PCSC/ifdhandler.h + PCSC/pcsclite.h + PCSC/pcsclite.h + PCSC/winscard.h + PCSC/wintypes.h + powermgt_generic.c + powermgt_generic.h + powermgt_macosx.c + prothandler.c + prothandler.h + readerfactory.c + readerfactory.h + strlcat.c + strlcpy.c + strlcpycat.h + sys_generic.h + sys_unix.c + thread_generic.h + thread_unix.c + ${CMAKE_CURRENT_BINARY_DIR}/tokenparser.c + utils.c + utils.h + winscard.c + winscard_msg.c + winscard_msg.h + winscard_msg_srv.c + winscard_svc.c + winscard_svc.h + ) + + tde_add_executable( + ${target} + SOURCES ${${target}_SRCS} + LINK + ${CMAKE_THREAD_LIBS_INIT} ${DL_LIBRARIES} + ${LIBUSB_LIBRARIES} ${LIBHAL_LIBRARIES} + DESTINATION ${SBIN_INSTALL_DIR} + ) + + set_property( + TARGET ${target} + APPEND PROPERTY COMPILE_DEFINITIONS + PCSCD + ) + +endif( NOT HAVE_SCF ) + + +#### testpcsc ################################### + +tde_add_executable( + testpcsc + SOURCES testpcsc.c + LINK pcsclite-shared +) + +tde_add_executable( + pcsc-wirecheck-gen + SOURCES pcsc-wirecheck-gen.c +) + +tde_add_executable( + pcsc-wirecheck + SOURCES + lassert.h + ${CMAKE_CURRENT_BINARY_DIR}/pcsc-wirecheck-dist.c + pcsc-wirecheck-main.c +) + +add_custom_command( + OUTPUT + pcsc-wirecheck-dist.c + COMMAND + ./pcsc-wirecheck-gen > pcsc-wirecheck-dist.c + DEPENDS + pcsc-wirecheck-gen +) + +flex_target( confifile configfile.l ${CMAKE_CURRENT_BINARY_DIR}/configfile.c ) + +flex_target( tokenparser tokenparser.l ${CMAKE_CURRENT_BINARY_DIR}/tokenparser.c COMPILE_FLAGS -Ptp ) + Index: b/src/PCSC/CMakeLists.txt =================================================================== --- /dev/null +++ b/src/PCSC/CMakeLists.txt @@ -0,0 +1,31 @@ +################################################# +# +# (C) 2015 Slávek Banko +# slavek (DOT) banko (AT) axis.cz +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + + +##### pcsclite headers ########################## + +configure_file( pcsclite.h.in pcsclite.h @ONLY ) +configure_file( reader.h.in reader.h @ONLY ) + +set( PCSC_INCLUDES + debuglog.h + ifdhandler.h + ${CMAKE_CURRENT_BINARY_DIR}/pcsclite.h + ${CMAKE_CURRENT_BINARY_DIR}/reader.h + winscard.h + wintypes.h +) + +install( + FILES ${PCSC_INCLUDES} + DESTINATION ${INCLUDE_INSTALL_DIR}/PCSC +) +