FindPCSC.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 or (at your option)
  6. # version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # Use pkgconfig on Linux
  16. if(NOT WIN32)
  17. find_package(PkgConfig QUIET)
  18. pkg_check_modules(PCSC libpcsclite)
  19. endif()
  20. if(NOT PCSC_FOUND)
  21. # Search for PC/SC headers on Mac and Windows
  22. # Additional search paths for Windows if not running in Visual Studio environment
  23. if (WIN32)
  24. # Resolve the ambiguity of using two names for one architechture
  25. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "x64")
  26. set(ARCH_DIR "x64")
  27. else()
  28. set(ARCH_DIR "${CMAKE_SYSTEM_PROCESSOR}")
  29. endif()
  30. # Locate Windows SDK Paths
  31. if (CMAKE_WINDOWS_KITS_10_DIR)
  32. set(WINSDKROOTC_INCLUDE "${CMAKE_WINDOWS_KITS_10_DIR}/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um")
  33. set(WINSDKROOTC_LIB "${CMAKE_WINDOWS_KITS_10_DIR}/LIB/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um/${ARCH_DIR}")
  34. else()
  35. set(WINSDKROOTC_INCLUDE "$ENV{ProgramFiles\(x86\)}/Windows Kits/10/Include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um")
  36. set(WINSDKROOTC_LIB "$ENV{ProgramFiles\(x86\)}/Windows Kits/10/LIB/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/um/${ARCH_DIR}")
  37. endif()
  38. endif()
  39. find_path(PCSC_INCLUDE_DIRS winscard.h
  40. HINTS
  41. ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}
  42. /usr/include/PCSC
  43. ${WINSDKROOTC_INCLUDE}
  44. PATH_SUFFIXES PCSC)
  45. # MAC library is PCSC, Windows library is WinSCard
  46. find_library(PCSC_LIBRARIES NAMES pcsclite libpcsclite WinSCard PCSC
  47. HINTS
  48. ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}
  49. ${WINSDKROOTC_LIB})
  50. endif()
  51. include(FindPackageHandleStandardArgs)
  52. find_package_handle_standard_args(PCSC DEFAULT_MSG PCSC_LIBRARIES PCSC_INCLUDE_DIRS)
  53. mark_as_advanced(PCSC_LIBRARIES PCSC_INCLUDE_DIRS)