1
0

FindARIA.cmake 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Filename: FindARIA.cmake
  2. #
  3. # Usage:
  4. # find_package(ARIA [REQUIRED] [QUIET])
  5. #
  6. # Once complete this will define:
  7. # ARIA_FOUND - system has ARIA MagicCrypto
  8. # ARIA_INCLUDE_DIR - the include directory containing ARIA
  9. # ARIA_LIBRARY - the path to the libARIA library
  10. # ARIA_IS_LOCAL - optionally indicate the MagicCrypto is found locally in ./MagicCrypto
  11. set(ARIA_INCLUDE_DIR)
  12. set(ARIA_LIB_FILE)
  13. set(ARIA_IS_LOCAL)
  14. # when debugging cmake, ARIA_DIR environment variable can be manually set here:
  15. # set(ENV{ARIA_DIR} "~/MagicCrypto")
  16. # set(ENV{ARIA_DIR} "/mnt/c/workspace/MagicCrypto")
  17. # set(ENV{ARIA_DIR} "c:\\workspace\\MagicCrypto")
  18. # Make sure we have a ARIA_DIR environment variable with the path to MagicCrypto
  19. if ("$ENV{ARIA_DIR}" STREQUAL "")
  20. message(STATUS "The ARIA_DIR environment variable is not defined. Looking for headers in wolfssl/MagicCrypto")
  21. if (EXISTS "${WOLFSSL_ROOT}/MagicCrypto/")
  22. set(ARIA_INCLUDE_DIR "${WOLFSSL_ROOT}/MagicCrypto/include")
  23. message(STATUS "Found ARIA in local MagicCrypto directory ${ARIA_INCLUDE_DIR}")
  24. set(ARIA_IS_LOCAL 1)
  25. else()
  26. message(ERROR "ERROR: FindARIA.cmake missing ARIA_DIR value")
  27. message(STATUS "Please set ARIA_DIR environment variable path to your MagicCrypto or copy to wolfssl/MagicCrypto")
  28. endif()
  29. else()
  30. # If an environment variable is defined, the library CANNOT be in the local wolfssl directory.
  31. # See CMake documentation for target_include_directories()
  32. set(ARIA_IS_LOCAL)
  33. set(ARIA_INCLUDE_DIR "$ENV{ARIA_DIR}/include")
  34. message(STATUS "FindARIA.cmake found ARIA_INCLUDE_DIR = $ENV{ARIA_DIR}")
  35. message(STATUS "Checking environment location: ${ARIA_INCLUDE_DIR} and wolfSSL: ${WOLFSSL_ROOT}")
  36. get_filename_component(dir1 "${ARIA_INCLUDE_DIR}" REALPATH)
  37. get_filename_component(dir2 "${WOLFSSL_ROOT}/MagicCrypto/include" REALPATH)
  38. message(STATUS "Found location dir: ${dir1} and ${dir2}")
  39. if("${dir1}" STREQUAL "${dir2}")
  40. message(STATUS "${ARIA_INCLUDE_DIR} exists within ${WOLFSSL_ROOT}.")
  41. message(STATUS "Setting ARIA_IS_LOCAL flag and using wolfSSL path.")
  42. set(ARIA_IS_LOCAL 1)
  43. set(ARIA_INCLUDE_DIR "${WOLFSSL_ROOT}/MagicCrypto/include")
  44. else()
  45. if(EXISTS "${ARIA_INCLUDE_DIR}")
  46. message(STATUS "Confirmed directory exists: ${ARIA_INCLUDE_DIR}")
  47. else()
  48. message(FATAL_ERROR "Directory not found: ${ARIA_INCLUDE_DIR}")
  49. endif()
  50. message(STATUS "Confirmed ${ARIA_INCLUDE_DIR} is not in local wolfSSL root.")
  51. endif()
  52. endif()
  53. # Check that the appropriate files exist
  54. find_path(ARIA_INCLUDE_DIR NAMES "mcapi.h" )
  55. if (NOT EXISTS "${ARIA_INCLUDE_DIR}/mcapi.h")
  56. message(FATAL_ERROR "File does not exist at ${ARIA_INCLUDE_DIR}/mcapi.h")
  57. endif()
  58. if(NOT EXISTS "${ARIA_INCLUDE_DIR}/mcapi_error.h")
  59. message(FATAL_ERROR "File does not exist at ${ARIA_INCLUDE_DIR}/mcapi_error.h")
  60. endif()
  61. if(NOT EXISTS "${ARIA_INCLUDE_DIR}/mcapi_type.h")
  62. message(FATAL_ERROR "File does not exist at $ARIA_INCLUDE_DIR/mcapi_type.h")
  63. endif()
  64. if(EXISTS "$ENV{ARIA_DIR}/lib/libMagicCrypto.so")
  65. # Found ARIA binary via environment variable
  66. set(ARIA_LIBRARY "MagicCrypto")
  67. set(ARIA_LIB_FILE "$ENV{ARIA_DIR}/lib/libMagicCrypto.so")
  68. message(STATUS "ARIA Check: found libMagicCrypto.so via environment variable.")
  69. message(STATUS "Using ${ARIA_LIB_FILE}")
  70. else()
  71. # Did not find ARIA binary via environment variable, so let's look in the current wolfssl directory
  72. if(EXISTS "${WOLFSSL_ROOT}/MagicCrypto/lib/libMagicCrypto.so")
  73. # Found in the root of wolfssl, in ./MagicCrypto/lib
  74. set(ARIA_LIBRARY "MagicCrypto")
  75. set(ARIA_LIB_FILE "${WOLFSSL_ROOT}/MagicCrypto/lib/libMagicCrypto.so")
  76. message(STATUS "ARIA Check: found libMagicCrypto.so via WOLFSSL_ROOT")
  77. message(STATUS "Using ${ARIA_LIB_FILE}")
  78. else()
  79. # Could not find binary. Give up.
  80. message(ERROR "ARIA Check: could not find libMagicCrypto.so via WOLFSSL_ROOT\n"
  81. "Looked for ${WOLFSSL_ROOT}/MagicCrypto/lib/libMagicCrypto.so")
  82. endif()
  83. endif()
  84. mark_as_advanced(ARIA_INCLUDE_DIR ARIA_LIBRARY)
  85. include(FindPackageHandleStandardArgs)
  86. find_package_handle_standard_args(ARIA DEFAULT_MSG ARIA_INCLUDE_DIR ARIA_LIBRARY)
  87. # Some additional optional debugging messages, set to (1) to enable
  88. if(0)
  89. message(STATUS "")
  90. message(STATUS "ARIA Check: FindARIA.cmake")
  91. message(STATUS "ARIA Check: ARIA_INCLUDE_DIR: ${ARIA_INCLUDE_DIR}")
  92. message(STATUS "ARIA Check: ARIA_LIBRARY: ${ARIA_LIBRARY}")
  93. message(STATUS "ARIA Check: ARIA_FOUND: ${ARIA_FOUND}")
  94. message(STATUS "ARIA Check: CMAKE_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}")
  95. endif()