CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. # Based on original work by David Manura
  2. # Copyright (C) 2007-2012 LuaDist.
  3. # Copyright (C) 2013 Brian Sidebotham
  4. # Copyright (C) 2016-2019 Jean-Luc Barriere
  5. # Redistribution and use of this file is allowed according to the terms of the
  6. # MIT license.
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a copy
  9. # of this software and associated documentation files (the "Software"), to deal
  10. # in the Software without restriction, including without limitation the rights
  11. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. # copies of the Software, and to permit persons to whom the Software is
  13. # furnished to do so, subject to the following ctallnditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included in all
  16. # copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. # SOFTWARE.
  25. set( CMAKE_LEGACY_CYGWIN_WIN32 0 )
  26. project( openssl )
  27. cmake_minimum_required( VERSION 3.1.0 )
  28. set( CMAKE_DISABLE_SOURCE_CHANGES ON )
  29. set( CMAKE_DISABLE_IN_SOURCE_BUILD ON )
  30. set( CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" )
  31. option( WITH_APPS "Build applications" OFF )
  32. # OpenSSL version detection imported from FindOpenSSL.cmake
  33. file( STRINGS "${PROJECT_SOURCE_DIR}/include/openssl/opensslv.h" openssl_version_str
  34. REGEX "^#[\t ]*define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*" )
  35. function(from_hex HEX DEC)
  36. string( TOUPPER "${HEX}" HEX )
  37. set( _res 0 )
  38. string( LENGTH "${HEX}" _strlen )
  39. while( _strlen GREATER 0 )
  40. math( EXPR _res "${_res} * 16" )
  41. string( SUBSTRING "${HEX}" 0 1 NIBBLE )
  42. string( SUBSTRING "${HEX}" 1 -1 HEX )
  43. if( NIBBLE STREQUAL "A" )
  44. math( EXPR _res "${_res} + 10" )
  45. elseif( NIBBLE STREQUAL "B" )
  46. math( EXPR _res "${_res} + 11" )
  47. elseif( NIBBLE STREQUAL "C" )
  48. math( EXPR _res "${_res} + 12" )
  49. elseif( NIBBLE STREQUAL "D" )
  50. math( EXPR _res "${_res} + 13" )
  51. elseif( NIBBLE STREQUAL "E" )
  52. math( EXPR _res "${_res} + 14" )
  53. elseif( NIBBLE STREQUAL "F" )
  54. math( EXPR _res "${_res} + 15" )
  55. else()
  56. math( EXPR _res "${_res} + ${NIBBLE}" )
  57. endif()
  58. string( LENGTH "${HEX}" _strlen )
  59. endwhile()
  60. set( ${DEC} ${_res} PARENT_SCOPE )
  61. endfunction()
  62. string( REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$"
  63. "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}" )
  64. list( GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR )
  65. list( GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR )
  66. from_hex( "${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR )
  67. list( GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX )
  68. from_hex( "${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX )
  69. list( GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH )
  70. if( NOT OPENSSL_VERSION_PATCH STREQUAL "00" )
  71. from_hex( "${OPENSSL_VERSION_PATCH}" _tmp )
  72. # 96 is the ASCII code of 'a' minus 1
  73. math( EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96" )
  74. unset( _tmp )
  75. string( ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING )
  76. endif()
  77. set( OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}" )
  78. message( STATUS "OpenSSL version ${OPENSSL_VERSION}" )
  79. set( VERSION_MAJOR ${OPENSSL_VERSION_MAJOR} )
  80. set( VERSION_MINOR ${OPENSSL_VERSION_MINOR} )
  81. set( VERSION_PATCH ${OPENSSL_VERSION_FIX} )
  82. set( VERSION_STRING ${OPENSSL_VERSION} )
  83. set( LIB_VERSION ${VERSION_MAJOR}.${VERSION_MINOR} )
  84. set( LIB_SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR} )
  85. add_definitions( -DOPENSSL_NO_ASM )
  86. add_definitions( -DOPENSSL_NO_STATIC_ENGINE )
  87. if( MSVC )
  88. include( MSVCRuntime )
  89. configure_msvc_runtime()
  90. add_definitions( "-DOPENSSLDIR=\"C:/ssl\"" )
  91. add_definitions( "-DENGINESDIR=\"C:/engines-1.1\"" )
  92. else()
  93. add_definitions( "-DOPENSSLDIR=\"/usr/local/ssl\"" )
  94. add_definitions( "-DENGINESDIR=\"/usr/local/engines-1.1\"" )
  95. endif()
  96. if( APPLE )
  97. set( CMAKE_MACOSX_RPATH ON )
  98. add_definitions( -DOPENSSL_SYSNAME_MACOSX )
  99. endif()
  100. if( WIN32 )
  101. set( CMAKE_SHARED_LIBRARY_PREFIX "lib" )
  102. set( CMAKE_STATIC_LIBRARY_PREFIX "lib" )
  103. endif()
  104. if( WIN32 AND NOT CYGWIN )
  105. add_definitions( -DOPENSSL_SYSNAME_WIN32 )
  106. add_definitions( -DWIN32_LEAN_AND_MEAN )
  107. add_definitions( -D_CRT_SECURE_NO_WARNINGS )
  108. if(BUILD_SHARED_LIBS)
  109. # avoid conflict: ocsp.h and wincrypt.h
  110. add_definitions( -D_WINDLL )
  111. endif()
  112. endif()
  113. if( MINGW )
  114. set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--export-all" )
  115. endif()
  116. include( CheckTypeSize )
  117. check_type_size( "long" LONG_INT )
  118. check_type_size( "long long" LONG_LONG_INT )
  119. check_type_size( "int" INT )
  120. if( HAVE_LONG_INT AND (${LONG_INT} EQUAL 8) )
  121. set( SIXTY_FOUR_BIT_LONG ON )
  122. elseif( HAVE_LONG_LONG_INT AND (${LONG_LONG_INT} EQUAL 8) )
  123. set( SIXTY_FOUR_BIT ON )
  124. else()
  125. set( THIRTY_TWO_BIT ON )
  126. endif()
  127. if( MSVC OR ( WIN32 AND MINGW AND NOT CYGWIN ) )
  128. set( OPENSSL_EXPORT_VAR_AS_FUNCTION 1 )
  129. endif()
  130. # Begin configure public headers
  131. file( COPY ${PROJECT_SOURCE_DIR}/include/internal DESTINATION include )
  132. file( COPY ${PROJECT_SOURCE_DIR}/include/openssl DESTINATION include )
  133. file( READ ${PROJECT_SOURCE_DIR}/opensslconf.h.cmake CONF )
  134. set( CONF "
  135. #define OPENSSL_NO_MD2
  136. #define OPENSSL_NO_RC5
  137. #define OPENSSL_NO_RFC3779
  138. #define OPENSSL_NO_EC_NISTP_64_GCC_128
  139. ${CONF}" )
  140. file( WRITE ${PROJECT_BINARY_DIR}/opensslconf.h.cmake "${CONF}" )
  141. configure_file( ${PROJECT_BINARY_DIR}/opensslconf.h.cmake
  142. ${PROJECT_BINARY_DIR}/include/openssl/opensslconf.h )
  143. # End configure public headers
  144. add_subdirectory(crypto)
  145. add_subdirectory(ssl)
  146. if(WITH_APPS AND NOT ANDROID AND NOT IOS)
  147. add_subdirectory(apps)
  148. endif()
  149. file( READ ${PROJECT_SOURCE_DIR}/c_rehash.cmake C_REHASH )
  150. string( REPLACE "@OPENSSLDIR@" "${OPENSSLDIR}" C_REHASH "${C_REHASH}" )
  151. string( REPLACE "@CMAKE_INSTALL_PREFIX@" "${CMAKE_INSTALL_PREFIX}" C_REHASH "${C_REHASH}" )
  152. file( WRITE ${PROJECT_BINARY_DIR}/c_rehash "${C_REHASH}" )
  153. file( GLOB PUBLIC_HEADERS "${PROJECT_BINARY_DIR}/include/openssl/*.h" )
  154. install( FILES ${PUBLIC_HEADERS} DESTINATION include/openssl )
  155. # install( FILES
  156. # ${PROJECT_BINARY_DIR}/c_rehash
  157. # FAQ LICENSE README README.ENGINE
  158. #DESTINATION share/openssl )
  159. # install( DIRECTORY doc DESTINATION share )
  160. # Generate the package target
  161. set( CPACK_GENERATOR ZIP TGZ )
  162. set( CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}" )
  163. set( CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR} )
  164. set( CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR} )
  165. set( CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH} )
  166. set( CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${VERSION_STRING}" )
  167. include( CPack )