1
0

portfile.cmake 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. vcpkg_find_acquire_program(NASM)
  2. get_filename_component(NASM_EXE_PATH "${NASM}" DIRECTORY)
  3. vcpkg_add_to_path(PREPEND "${NASM_EXE_PATH}")
  4. vcpkg_find_acquire_program(JOM)
  5. if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
  6. set(OPENSSL_SHARED shared)
  7. else()
  8. set(OPENSSL_SHARED no-shared no-module)
  9. endif()
  10. vcpkg_cmake_get_vars(cmake_vars_file)
  11. include("${cmake_vars_file}")
  12. set(ENV{CC} "${VCPKG_DETECTED_CMAKE_C_COMPILER}")
  13. set(ENV{CXX} "${VCPKG_DETECTED_CMAKE_CXX_COMPILER}")
  14. set(ENV{AR} "${VCPKG_DETECTED_CMAKE_AR}")
  15. set(ENV{LD} "${VCPKG_DETECTED_CMAKE_LINKER}")
  16. set(CONFIGURE_OPTIONS
  17. enable-static-engine
  18. enable-capieng
  19. no-ssl2
  20. no-tests
  21. ${OPENSSL_SHARED}
  22. )
  23. if(DEFINED OPENSSL_USE_NOPINSHARED)
  24. set(CONFIGURE_OPTIONS ${CONFIGURE_OPTIONS} no-pinshared)
  25. endif()
  26. if(OPENSSL_NO_AUTOLOAD_CONFIG)
  27. set(CONFIGURE_OPTIONS ${CONFIGURE_OPTIONS} no-autoload-config)
  28. endif()
  29. set(CONFIGURE_COMMAND "${PERL}" Configure ${CONFIGURE_OPTIONS})
  30. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
  31. set(OPENSSL_ARCH VC-WIN32)
  32. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  33. set(OPENSSL_ARCH VC-WIN64A)
  34. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
  35. set(OPENSSL_ARCH VC-WIN32-ARM)
  36. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  37. set(OPENSSL_ARCH VC-WIN64-ARM)
  38. else()
  39. message(FATAL_ERROR "Unsupported target architecture: ${VCPKG_TARGET_ARCHITECTURE}")
  40. endif()
  41. set(OPENSSL_MAKEFILE "makefile")
  42. file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel"
  43. "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  44. # Clang always uses /Z7; Patching /Zi /Fd<Name> out of openssl requires more work.
  45. if (VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "Clang" OR VCPKG_LIBRARY_LINKAGE STREQUAL static)
  46. set(OPENSSL_BUILD_MAKES_PDBS OFF)
  47. else()
  48. set(OPENSSL_BUILD_MAKES_PDBS ON)
  49. endif()
  50. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  51. # Copy openssl sources.
  52. message(STATUS "Copying openssl release source files...")
  53. file(COPY "${SOURCE_PATH}/" DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  54. message(STATUS "Copying openssl release source files... done")
  55. set(SOURCE_PATH_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  56. set(OPENSSLDIR_RELEASE "${CURRENT_PACKAGES_DIR}")
  57. # Remove install rules for pdbs if they don't exist
  58. if(NOT OPENSSL_BUILD_MAKES_PDBS)
  59. file(READ "${SOURCE_PATH_RELEASE}/Configurations/windows-makefile.tmpl" contents)
  60. string(REGEX REPLACE [["\$\(PERL\)" "\$\(SRCDIR\)\\util\\copy.pl" \$\(INSTALL_(ENGINE|MODULE|SHLIB|PROGRAM)PDBS\)]] "echo " contents "${contents}")
  61. string(REGEX REPLACE [["\$\(PERL\)" "\$\(SRCDIR\)\\util\\copy.pl" ossl_static.pdb]] "echo " contents "${contents}")
  62. file(WRITE "${SOURCE_PATH_RELEASE}/Configurations/windows-makefile.tmpl" "${contents}")
  63. endif()
  64. set(ENV{CFLAGS} "${VCPKG_COMBINED_C_FLAGS_RELEASE}")
  65. set(ENV{CXXFLAGS} "${VCPKG_COMBINED_CXX_FLAGS_RELEASE}")
  66. set(ENV{LDFLAGS} "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE}")
  67. set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_RELEASE}")
  68. message(STATUS "Configure ${TARGET_TRIPLET}-rel")
  69. vcpkg_execute_required_process(
  70. COMMAND ${CONFIGURE_COMMAND} ${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_RELEASE}" "--openssldir=${OPENSSLDIR_RELEASE}" -FS
  71. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  72. LOGNAME configure-perl-${TARGET_TRIPLET}-rel
  73. )
  74. message(STATUS "Configure ${TARGET_TRIPLET}-rel done")
  75. message(STATUS "Build ${TARGET_TRIPLET}-rel")
  76. # Openssl's buildsystem has a race condition which will cause JOM to fail at some point.
  77. # This is ok; we just do as much work as we can in parallel first, then follow up with a single-threaded build.
  78. make_directory("${SOURCE_PATH_RELEASE}/inc32/openssl")
  79. execute_process(
  80. COMMAND "${JOM}" -k -j "${VCPKG_CONCURRENCY}" -f "${OPENSSL_MAKEFILE}"
  81. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  82. OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-out.log"
  83. ERROR_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-err.log"
  84. )
  85. vcpkg_execute_required_process(
  86. COMMAND "${JOM}" -j 1 -f "${OPENSSL_MAKEFILE}" install_sw install_ssldirs
  87. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  88. LOGNAME build-${TARGET_TRIPLET}-rel-1)
  89. message(STATUS "Build ${TARGET_TRIPLET}-rel done")
  90. endif()
  91. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  92. # Copy openssl sources.
  93. message(STATUS "Copying openssl debug source files...")
  94. file(COPY "${SOURCE_PATH}/" DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  95. message(STATUS "Copying openssl debug source files... done")
  96. set(SOURCE_PATH_DEBUG "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  97. # Remove install rules for pdbs if they don't exist
  98. if(NOT OPENSSL_BUILD_MAKES_PDBS)
  99. file(READ "${SOURCE_PATH_DEBUG}/Configurations/windows-makefile.tmpl" contents)
  100. string(REGEX REPLACE [["\$\(PERL\)" "\$\(SRCDIR\)\\util\\copy.pl" \$\(INSTALL_(ENGINE|MODULE|SHLIB|PROGRAM)PDBS\)]] "echo " contents "${contents}")
  101. string(REGEX REPLACE [["\$\(PERL\)" "\$\(SRCDIR\)\\util\\copy.pl" ossl_static.pdb]] "echo " contents "${contents}")
  102. file(WRITE "${SOURCE_PATH_DEBUG}/Configurations/windows-makefile.tmpl" "${contents}")
  103. endif()
  104. set(OPENSSLDIR_DEBUG "${CURRENT_PACKAGES_DIR}/debug")
  105. set(ENV{CFLAGS} "${VCPKG_COMBINED_C_FLAGS_DEBUG}")
  106. set(ENV{CXXFLAGS} "${VCPKG_COMBINED_CXX_FLAGS_DEBUG}")
  107. set(ENV{LDFLAGS} "${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG}")
  108. set(ENV{ARFLAGS} "${VCPKG_COMBINED_STATIC_LINKER_FLAGS_DEBUG}")
  109. message(STATUS "Configure ${TARGET_TRIPLET}-dbg")
  110. vcpkg_execute_required_process(
  111. COMMAND ${CONFIGURE_COMMAND} debug-${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_DEBUG}" "--openssldir=${OPENSSLDIR_DEBUG}" -FS
  112. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  113. LOGNAME configure-perl-${TARGET_TRIPLET}-dbg
  114. )
  115. message(STATUS "Configure ${TARGET_TRIPLET}-dbg done")
  116. message(STATUS "Build ${TARGET_TRIPLET}-dbg")
  117. make_directory("${SOURCE_PATH_DEBUG}/inc32/openssl")
  118. execute_process(
  119. COMMAND "${JOM}" -k -j "${VCPKG_CONCURRENCY}" -f "${OPENSSL_MAKEFILE}"
  120. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  121. OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-out.log"
  122. ERROR_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-err.log"
  123. )
  124. vcpkg_execute_required_process(
  125. COMMAND "${JOM}" -j 1 -f "${OPENSSL_MAKEFILE}" install_sw install_ssldirs
  126. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  127. LOGNAME build-${TARGET_TRIPLET}-dbg-1)
  128. message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
  129. if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic AND NOT VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "Clang")
  130. file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/ossl-modules/legacy.pdb" "${CURRENT_PACKAGES_DIR}/debug/bin/legacy.pdb")
  131. file(RENAME "${CURRENT_PACKAGES_DIR}/lib/ossl-modules/legacy.pdb" "${CURRENT_PACKAGES_DIR}/bin/legacy.pdb")
  132. endif()
  133. endif()
  134. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/certs")
  135. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/private")
  136. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib/engines-1_1")
  137. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib/engines-3")
  138. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/certs")
  139. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/engines-1_1")
  140. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/engines-3")
  141. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/private")
  142. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
  143. if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
  144. if(NOT VCPKG_BUILD_TYPE)
  145. file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/ossl-modules/legacy.dll" "${CURRENT_PACKAGES_DIR}/debug/bin/legacy.dll")
  146. endif()
  147. file(RENAME "${CURRENT_PACKAGES_DIR}/lib/ossl-modules/legacy.dll" "${CURRENT_PACKAGES_DIR}/bin/legacy.dll")
  148. endif()
  149. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/ossl-modules")
  150. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib/ossl-modules")
  151. file(REMOVE
  152. "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf"
  153. "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf.dist"
  154. "${CURRENT_PACKAGES_DIR}/openssl.cnf.dist"
  155. "${CURRENT_PACKAGES_DIR}/debug/bin/openssl.exe"
  156. "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf"
  157. "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf.dist"
  158. "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf"
  159. "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf.dist"
  160. )
  161. file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/openssl/")
  162. file(RENAME "${CURRENT_PACKAGES_DIR}/bin/openssl.exe" "${CURRENT_PACKAGES_DIR}/tools/openssl/openssl.exe")
  163. file(RENAME "${CURRENT_PACKAGES_DIR}/openssl.cnf" "${CURRENT_PACKAGES_DIR}/tools/openssl/openssl.cnf")
  164. vcpkg_copy_tool_dependencies("${CURRENT_PACKAGES_DIR}/tools/openssl")
  165. if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
  166. # They should be empty, only the exes deleted above were in these directories
  167. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin/")
  168. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin/")
  169. endif()
  170. vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h"
  171. "<winsock.h>"
  172. "<winsock2.h>"
  173. )
  174. vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/openssl/rand.h"
  175. "# include <windows.h>"
  176. "#ifndef _WINSOCKAPI_\n#define _WINSOCKAPI_\n#endif\n# include <windows.h>"
  177. )
  178. vcpkg_copy_pdbs()
  179. file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)