CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. aria.c
  9. asn1parse.c
  10. asn1write.c
  11. base64.c
  12. bignum.c
  13. blowfish.c
  14. camellia.c
  15. ccm.c
  16. chacha20.c
  17. chachapoly.c
  18. cipher.c
  19. cipher_wrap.c
  20. cmac.c
  21. ctr_drbg.c
  22. des.c
  23. dhm.c
  24. ecdh.c
  25. ecdsa.c
  26. ecjpake.c
  27. ecp.c
  28. ecp_curves.c
  29. entropy.c
  30. entropy_poll.c
  31. error.c
  32. gcm.c
  33. havege.c
  34. hkdf.c
  35. hmac_drbg.c
  36. md.c
  37. md2.c
  38. md4.c
  39. md5.c
  40. md_wrap.c
  41. memory_buffer_alloc.c
  42. nist_kw.c
  43. oid.c
  44. padlock.c
  45. pem.c
  46. pk.c
  47. pk_wrap.c
  48. pkcs12.c
  49. pkcs5.c
  50. pkparse.c
  51. pkwrite.c
  52. platform.c
  53. platform_util.c
  54. poly1305.c
  55. ripemd160.c
  56. rsa.c
  57. rsa_internal.c
  58. sha1.c
  59. sha256.c
  60. sha512.c
  61. threading.c
  62. timing.c
  63. version.c
  64. version_features.c
  65. xtea.c
  66. )
  67. set(src_x509
  68. certs.c
  69. pkcs11.c
  70. x509.c
  71. x509_create.c
  72. x509_crl.c
  73. x509_crt.c
  74. x509_csr.c
  75. x509write_crt.c
  76. x509write_csr.c
  77. )
  78. set(src_tls
  79. debug.c
  80. net_sockets.c
  81. ssl_cache.c
  82. ssl_ciphersuites.c
  83. ssl_cli.c
  84. ssl_cookie.c
  85. ssl_srv.c
  86. ssl_ticket.c
  87. ssl_tls.c
  88. )
  89. if(CMAKE_COMPILER_IS_GNUCC)
  90. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes")
  91. endif(CMAKE_COMPILER_IS_GNUCC)
  92. if(CMAKE_COMPILER_IS_CLANG)
  93. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations -Wmissing-prototypes -Wdocumentation -Wno-documentation-deprecated-sync -Wunreachable-code")
  94. endif(CMAKE_COMPILER_IS_CLANG)
  95. if(UNSAFE_BUILD)
  96. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
  97. set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS_ASAN} -Wno-error")
  98. set(CMAKE_C_FLAGS_ASANDBG "${CMAKE_C_FLAGS_ASANDBG} -Wno-error")
  99. endif(UNSAFE_BUILD)
  100. if(WIN32)
  101. set(libs ${libs} ws2_32)
  102. endif(WIN32)
  103. if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  104. SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  105. SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
  106. SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  107. SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
  108. endif()
  109. if(HAIKU)
  110. set(libs ${libs} network)
  111. endif(HAIKU)
  112. if(USE_PKCS11_HELPER_LIBRARY)
  113. set(libs ${libs} pkcs11-helper)
  114. endif(USE_PKCS11_HELPER_LIBRARY)
  115. if(ENABLE_ZLIB_SUPPORT)
  116. set(libs ${libs} ${ZLIB_LIBRARIES})
  117. endif(ENABLE_ZLIB_SUPPORT)
  118. if(LINK_WITH_PTHREAD)
  119. set(libs ${libs} pthread)
  120. endif()
  121. if (NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
  122. message(FATAL_ERROR "Need to choose static or shared mbedtls build!")
  123. endif(NOT USE_STATIC_MBEDTLS_LIBRARY AND NOT USE_SHARED_MBEDTLS_LIBRARY)
  124. if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
  125. set(mbedtls_static_target "mbedtls_static")
  126. set(mbedx509_static_target "mbedx509_static")
  127. set(mbedcrypto_static_target "mbedcrypto_static")
  128. elseif(USE_STATIC_MBEDTLS_LIBRARY)
  129. set(mbedtls_static_target "mbedtls")
  130. set(mbedx509_static_target "mbedx509")
  131. set(mbedcrypto_static_target "mbedcrypto")
  132. endif()
  133. if(USE_STATIC_MBEDTLS_LIBRARY)
  134. add_library(${mbedcrypto_static_target} STATIC ${src_crypto})
  135. set_target_properties(${mbedcrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
  136. target_link_libraries(${mbedcrypto_static_target} ${libs})
  137. add_library(${mbedx509_static_target} STATIC ${src_x509})
  138. set_target_properties(${mbedx509_static_target} PROPERTIES OUTPUT_NAME mbedx509)
  139. target_link_libraries(${mbedx509_static_target} ${libs} ${mbedcrypto_static_target})
  140. add_library(${mbedtls_static_target} STATIC ${src_tls})
  141. set_target_properties(${mbedtls_static_target} PROPERTIES OUTPUT_NAME mbedtls)
  142. target_link_libraries(${mbedtls_static_target} ${libs} ${mbedx509_static_target})
  143. install(TARGETS ${mbedtls_static_target} ${mbedx509_static_target} ${mbedcrypto_static_target}
  144. DESTINATION ${LIB_INSTALL_DIR}
  145. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  146. endif(USE_STATIC_MBEDTLS_LIBRARY)
  147. if(USE_SHARED_MBEDTLS_LIBRARY)
  148. add_library(mbedcrypto SHARED ${src_crypto})
  149. set_target_properties(mbedcrypto PROPERTIES VERSION 2.16.5 SOVERSION 3)
  150. target_link_libraries(mbedcrypto ${libs})
  151. add_library(mbedx509 SHARED ${src_x509})
  152. set_target_properties(mbedx509 PROPERTIES VERSION 2.16.5 SOVERSION 0)
  153. target_link_libraries(mbedx509 ${libs} mbedcrypto)
  154. add_library(mbedtls SHARED ${src_tls})
  155. set_target_properties(mbedtls PROPERTIES VERSION 2.16.5 SOVERSION 12)
  156. target_link_libraries(mbedtls ${libs} mbedx509)
  157. install(TARGETS mbedtls mbedx509 mbedcrypto
  158. DESTINATION ${LIB_INSTALL_DIR}
  159. PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
  160. endif(USE_SHARED_MBEDTLS_LIBRARY)
  161. add_custom_target(lib DEPENDS mbedcrypto mbedx509 mbedtls)
  162. if(USE_STATIC_MBEDTLS_LIBRARY AND USE_SHARED_MBEDTLS_LIBRARY)
  163. add_dependencies(lib mbedcrypto_static mbedx509_static mbedtls_static)
  164. endif()