FindPolarSSL.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Locate polarssl library
  2. # This module defines
  3. # POLARSSL_FOUND
  4. # POLARSSL_LIBRARY
  5. # POLARSSL_INCLUDE_DIR
  6. # POLARSSL_WORKS, this is true if polarssl is found and contains the methods
  7. # needed by dolphin-emu
  8. # validate cached values (but use them as hints)
  9. set(POLARSSL_INCLUDE_DIR_HINT POLARSSL_INCLUDE_DIR)
  10. set(POLARSSL_LIBRARY_HINT POLARSSL_LIBRARY)
  11. unset(POLARSSL_INCLUDE_DIR CACHE)
  12. unset(POLARSSL_LIBRARY CACHE)
  13. find_path(POLARSSL_INCLUDE_DIR polarssl/ssl.h HINTS ${POLARSSL_INCLUDE_DIR_HINT})
  14. find_library(POLARSSL_LIBRARY polarssl HINTS ${POLARSSL_LIBRARY_HINT})
  15. if(POLARSSL_INCLUDE_DIR STREQUAL POLARSSL_INCLUDE_DIR_HINT AND
  16. POLARSSL_LIBRARY STREQUAL POLARSSL_LIBRARY_HINT)
  17. # using cached values, be silent
  18. set(POLARSSL_FIND_QUIETLY TRUE)
  19. endif()
  20. if (POLARSSL_INCLUDE_DIR AND POLARSSL_LIBRARY)
  21. set (POLARSSL_FOUND TRUE)
  22. endif ()
  23. if (POLARSSL_FOUND)
  24. if (NOT POLARSSL_FIND_QUIETLY)
  25. message (STATUS "Found the polarssl libraries at ${POLARSSL_LIBRARY}")
  26. message (STATUS "Found the polarssl headers at ${POLARSSL_INCLUDE_DIR}")
  27. endif (NOT POLARSSL_FIND_QUIETLY)
  28. set(CMAKE_REQUIRED_INCLUDES ${POLARSSL_INCLUDE_DIR})
  29. set(CMAKE_REQUIRED_LIBRARIES ${POLARSSL_LIBRARY})
  30. unset(POLARSSL_WORKS CACHE)
  31. check_cxx_source_compiles("
  32. #include <polarssl/ctr_drbg.h>
  33. #include <polarssl/entropy.h>
  34. #include <polarssl/net.h>
  35. #include <polarssl/ssl.h>
  36. #include <polarssl/version.h>
  37. #if POLARSSL_VERSION_NUMBER < 0x01030000
  38. #error \"Shared PolarSSL version is too old\"
  39. #endif
  40. int main()
  41. {
  42. ssl_context ctx;
  43. ssl_session session;
  44. entropy_context entropy;
  45. ctr_drbg_context ctr_drbg;
  46. x509_crt cacert;
  47. x509_crt clicert;
  48. pk_context pk;
  49. ssl_init(&ctx);
  50. entropy_init(&entropy);
  51. const char* pers = \"dolphin-emu\";
  52. ctr_drbg_init(&ctr_drbg, entropy_func,
  53. &entropy,
  54. (const unsigned char*)pers,
  55. strlen(pers));
  56. ssl_set_rng(&ctx, ctr_drbg_random, &ctr_drbg);
  57. ssl_set_session(&ctx, &session);
  58. ssl_close_notify(&ctx);
  59. ssl_session_free(&session);
  60. ssl_free(&ctx);
  61. entropy_free(&entropy);
  62. return 0;
  63. }"
  64. POLARSSL_WORKS)
  65. else ()
  66. message (STATUS "Could not find polarssl")
  67. endif ()
  68. mark_as_advanced(POLARSSL_INCLUDE_DIR POLARSSL_LIBRARY)