1
0

portfile.cmake 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. vcpkg_find_acquire_program(JOM)
  2. get_filename_component(JOM_EXE_PATH ${JOM} DIRECTORY)
  3. vcpkg_add_to_path("${PERL_EXE_PATH}")
  4. set(OPENSSL_SHARED no-shared)
  5. if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
  6. set(OPENSSL_SHARED shared)
  7. endif()
  8. vcpkg_find_acquire_program(NASM)
  9. get_filename_component(NASM_EXE_PATH ${NASM} DIRECTORY)
  10. vcpkg_add_to_path(PREPEND "${NASM_EXE_PATH}")
  11. set(CONFIGURE_COMMAND ${PERL} Configure
  12. enable-static-engine
  13. enable-capieng
  14. no-unit-test
  15. no-ssl2
  16. no-asm
  17. no-uplink
  18. no-tests
  19. -utf-8
  20. ${OPENSSL_SHARED}
  21. )
  22. if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
  23. set(OPENSSL_ARCH VC-WIN32-UWP)
  24. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64")
  25. set(OPENSSL_ARCH VC-WIN64A-UWP)
  26. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm")
  27. set(OPENSSL_ARCH VC-WIN32-ARM-UWP)
  28. elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
  29. set(OPENSSL_ARCH VC-WIN64-ARM-UWP)
  30. else()
  31. message(FATAL_ERROR "Unsupported target architecture: ${VCPKG_TARGET_ARCHITECTURE}")
  32. endif()
  33. set(OPENSSL_MAKEFILE "makefile")
  34. file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  35. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
  36. # Copy openssl sources.
  37. message(STATUS "Copying openssl release source files...")
  38. file(GLOB OPENSSL_SOURCE_FILES "${SOURCE_PATH}/*")
  39. foreach(SOURCE_FILE ${OPENSSL_SOURCE_FILES})
  40. file(COPY ${SOURCE_FILE} DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  41. endforeach()
  42. message(STATUS "Copying openssl release source files... done")
  43. set(SOURCE_PATH_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel")
  44. set(OPENSSLDIR_RELEASE "${CURRENT_PACKAGES_DIR}")
  45. message(STATUS "Configure ${TARGET_TRIPLET}-rel")
  46. vcpkg_execute_required_process(
  47. COMMAND ${CONFIGURE_COMMAND} ${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_RELEASE}" "--openssldir=${OPENSSLDIR_RELEASE}" -FS
  48. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  49. LOGNAME configure-perl-${TARGET_TRIPLET}-${VCPKG_BUILD_TYPE}-rel
  50. )
  51. message(STATUS "Configure ${TARGET_TRIPLET}-rel done")
  52. message(STATUS "Build ${TARGET_TRIPLET}-rel")
  53. # Openssl's buildsystem has a race condition which will cause JOM to fail at some point.
  54. # This is ok; we just do as much work as we can in parallel first, then follow up with a single-threaded build.
  55. make_directory("${SOURCE_PATH_RELEASE}/inc32/openssl")
  56. execute_process(
  57. COMMAND "${JOM}" -k -j ${VCPKG_CONCURRENCY} -f "${OPENSSL_MAKEFILE}" build_libs
  58. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  59. OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-out.log"
  60. ERROR_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-rel-0-err.log"
  61. )
  62. vcpkg_execute_required_process(
  63. COMMAND nmake -f "${OPENSSL_MAKEFILE}" install_dev
  64. WORKING_DIRECTORY "${SOURCE_PATH_RELEASE}"
  65. LOGNAME build-${TARGET_TRIPLET}-rel-1)
  66. message(STATUS "Build ${TARGET_TRIPLET}-rel done")
  67. endif()
  68. if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
  69. # Copy openssl sources.
  70. message(STATUS "Copying openssl debug source files...")
  71. file(GLOB OPENSSL_SOURCE_FILES ${SOURCE_PATH}/*)
  72. foreach(SOURCE_FILE ${OPENSSL_SOURCE_FILES})
  73. file(COPY "${SOURCE_FILE}" DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  74. endforeach()
  75. message(STATUS "Copying openssl debug source files... done")
  76. set(SOURCE_PATH_DEBUG "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg")
  77. set(OPENSSLDIR_DEBUG "${CURRENT_PACKAGES_DIR}/debug")
  78. message(STATUS "Configure ${TARGET_TRIPLET}-dbg")
  79. vcpkg_execute_required_process(
  80. COMMAND ${CONFIGURE_COMMAND} debug-${OPENSSL_ARCH} "--prefix=${OPENSSLDIR_DEBUG}" "--openssldir=${OPENSSLDIR_DEBUG}" -FS
  81. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  82. LOGNAME configure-perl-${TARGET_TRIPLET}-${VCPKG_BUILD_TYPE}-dbg
  83. )
  84. message(STATUS "Configure ${TARGET_TRIPLET}-dbg done")
  85. message(STATUS "Build ${TARGET_TRIPLET}-dbg")
  86. make_directory("${SOURCE_PATH_DEBUG}/inc32/openssl")
  87. execute_process(
  88. COMMAND "${JOM}" -k -j ${VCPKG_CONCURRENCY} -f "${OPENSSL_MAKEFILE}" build_libs
  89. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  90. OUTPUT_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-out.log"
  91. ERROR_FILE "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-dbg-0-err.log"
  92. )
  93. vcpkg_execute_required_process(
  94. COMMAND nmake -f "${OPENSSL_MAKEFILE}" install_dev
  95. WORKING_DIRECTORY "${SOURCE_PATH_DEBUG}"
  96. LOGNAME build-${TARGET_TRIPLET}-dbg-1)
  97. message(STATUS "Build ${TARGET_TRIPLET}-dbg done")
  98. endif()
  99. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/certs")
  100. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/private")
  101. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib/engines-1_1")
  102. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/certs")
  103. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/engines-1_1")
  104. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/private")
  105. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
  106. file(REMOVE
  107. "${CURRENT_PACKAGES_DIR}/bin/openssl.exe"
  108. "${CURRENT_PACKAGES_DIR}/debug/bin/openssl.exe"
  109. "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf"
  110. "${CURRENT_PACKAGES_DIR}/openssl.cnf"
  111. "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf"
  112. "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf.dist"
  113. "${CURRENT_PACKAGES_DIR}/openssl.cnf.dist"
  114. "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf"
  115. "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf.dist"
  116. "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf.dist"
  117. )
  118. if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
  119. # They should be empty, only the exes deleted above were in these directories
  120. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin/")
  121. file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin/")
  122. endif()
  123. file(READ "${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h" _contents)
  124. string(REPLACE "<winsock.h>" "<winsock2.h>" _contents "${_contents}")
  125. file(WRITE "${CURRENT_PACKAGES_DIR}/include/openssl/dtls1.h" "${_contents}")
  126. file(READ "${CURRENT_PACKAGES_DIR}/include/openssl/rand.h" _contents)
  127. string(REPLACE "# include <windows.h>" "#ifndef _WINSOCKAPI_\n#define _WINSOCKAPI_\n#endif\n# include <windows.h>" _contents "${_contents}")
  128. file(WRITE "${CURRENT_PACKAGES_DIR}/include/openssl/rand.h" "${_contents}")
  129. vcpkg_copy_pdbs()
  130. file(INSTALL "${SOURCE_PATH}/LICENSE.txt" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)