CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." ON)
  2. option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." OFF)
  3. option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." OFF)
  4. set(src_crypto
  5. aes.c
  6. aesni.c
  7. arc4.c
  8. asn1parse.c
  9. asn1write.c
  10. base64.c
  11. bignum.c
  12. blowfish.c
  13. camellia.c
  14. ccm.c
  15. cipher.c
  16. cipher_wrap.c
  17. cmac.c
  18. ctr_drbg.c
  19. des.c
  20. dhm.c
  21. ecdh.c
  22. ecdsa.c
  23. ecjpake.c
  24. ecp.c
  25. ecp_curves.c
  26. entropy.c
  27. entropy_poll.c
  28. error.c
  29. gcm.c
  30. havege.c
  31. hmac_drbg.c
  32. md.c
  33. md2.c
  34. md4.c
  35. md5.c
  36. md_wrap.c
  37. memory_buffer_alloc.c
  38. oid.c
  39. padlock.c
  40. pem.c
  41. pk.c
  42. pk_wrap.c
  43. pkcs12.c
  44. pkcs5.c
  45. pkparse.c
  46. pkwrite.c
  47. platform.c
  48. ripemd160.c
  49. rsa.c
  50. sha1.c
  51. sha256.c
  52. sha512.c
  53. threading.c
  54. timing.c
  55. version.c
  56. version_features.c
  57. xtea.c
  58. )
  59. set(src_x509
  60. certs.c
  61. pkcs11.c
  62. x509.c
  63. x509_create.c
  64. x509_crl.c
  65. x509_crt.c
  66. x509_csr.c
  67. x509write_crt.c
  68. x509write_csr.c
  69. )
  70. set(src_tls
  71. debug.c
  72. net_sockets.c
  73. ssl_cache.c
  74. ssl_ciphersuites.c
  75. ssl_cli.c
  76. ssl_cookie.c
  77. ssl_srv.c
  78. ssl_ticket.c
  79. ssl_tls.c
  80. )
  81. if(CMAKE_COMPILER_IS_GNUCC)
  82. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
  83. endif(CMAKE_COMPILER_IS_GNUCC)
  84. if(CMAKE_COMPILER_IS_CLANG)
  85. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
  86. endif(CMAKE_COMPILER_IS_CLANG)
  87. if(WIN32)
  88. set(libs ${libs} ws2_32)
  89. endif(WIN32)
  90. if(USE_PKCS11_HELPER_LIBRARY)
  91. set(libs ${libs} pkcs11-helper)
  92. endif(USE_PKCS11_HELPER_LIBRARY)
  93. if(ENABLE_ZLIB_SUPPORT)
  94. set(libs ${libs} ${ZLIB_LIBRARIES})
  95. endif(ENABLE_ZLIB_SUPPORT)
  96. if(LINK_WITH_PTHREAD)
  97. set(libs ${libs} pthread)
  98. endif()
  99. if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
  100. message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
  101. endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
  102. if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
  103. set(mbedtls_static_target "mbedtls_static")
  104. set(mbedx509_static_target "mbedx509_static")
  105. set(mbedcrypto_static_target "mbedcrypto_static")
  106. elseif(USE_STATIC_MBEDTLS_LIBRARY)
  107. set(mbedtls_static_target "mbedtls")
  108. set(mbedx509_static_target "mbedx509")
  109. set(mbedcrypto_static_target "mbedcrypto")
  110. endif()
  111. if(USE_STATIC_MBEDTLS_LIBRARY)
  112. add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
  113. set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
  114. target_link_libraries(${mbedcrypto_static_target} ${libs})
  115. add_library(${mbedx509_static_target} STATIC ${src_x509})
  116. set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
  117. target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
  118. add_library(${mbedtls_static_target} STATIC ${src_tls})
  119. set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
  120. target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
  121. install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
  122. DESTINATION ${LIB_INSTALL_DIR}
  123. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  124. endif(USE_STATIC_MBEDTLS_LIBRARY)
  125. if(USE_SHARED_MBEDTLS_LIBRARY)
  126. add_library(mbedcrypto SHARED ${src_crypto})
  127. set_target_properties(mbedcrypto PROPERTIES VERSION 2.4.2 SOVERSION 0)
  128. target_link_libraries(mbedcrypto ${libs})
  129. add_library(mbedx509 SHARED ${src_x509})
  130. set_target_properties(mbedx509 PROPERTIES VERSION 2.4.2 SOVERSION 0)
  131. target_link_libraries(mbedx509 ${libs} mbedcrypto)
  132. add_library(mbedtls SHARED ${src_tls})
  133. set_target_properties(mbedtls PROPERTIES VERSION 2.4.2 SOVERSION 10)
  134. target_link_libraries(mbedtls ${libs} mbedx509)
  135. install(TARGETS mbedtls mbedx509 mbedcrypto
  136. DESTINATION ${LIB_INSTALL_DIR}
  137. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  138. endif(USE_SHARED_MBEDTLS_LIBRARY)
  139. add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
  140. if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
  141. add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
  142. endif()