|
| 1 | +cmake_minimum_required(VERSION 3.5.1) |
| 2 | + |
| 3 | +project(Superbuild) |
| 4 | + |
| 5 | +# Set a default build type if none was specified |
| 6 | +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 7 | + message(STATUS "Setting build type to 'Release' as none was specified.") |
| 8 | + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) |
| 9 | + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS |
| 10 | + "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| 11 | +endif() |
| 12 | + |
| 13 | +option(BUILD_SHARED_LIBS "Build with shared libs." ON) |
| 14 | +option(USE_EXTERNAL_INSTALL "If enabled, install dependencies to CMAKE_INSTALL_PREFIX." OFF) |
| 15 | +mark_as_advanced(USE_EXTERNAL_INSTALL) |
| 16 | + |
| 17 | +include(ExternalProject) |
| 18 | + |
| 19 | +set_property(DIRECTORY PROPERTY EP_PREFIX ${Superbuild_BINARY_DIR}) |
| 20 | +set(install_prefix ${Superbuild_BINARY_DIR}/install) |
| 21 | +if (USE_EXTERNAL_INSTALL) |
| 22 | + set(install_prefix ${CMAKE_INSTALL_PREFIX}) |
| 23 | +else() |
| 24 | + mark_as_advanced(CMAKE_INSTALL_PREFIX) |
| 25 | +endif() |
| 26 | + |
| 27 | +#[[ |
| 28 | +Default Cmake configuration flags. |
| 29 | +Ref: https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html |
| 30 | +]] |
| 31 | +set(default_cmake_args |
| 32 | + "-DCMAKE_PREFIX_PATH:PATH=${install_prefix};${DRAKE_SUPERBUILD_PREFIX_PATH};${CMAKE_PREFIX_PATH}" |
| 33 | + "-DCMAKE_INSTALL_PREFIX:PATH=${install_prefix}" |
| 34 | + "-DCMAKE_FIND_ROOT_PATH:PATH=${install_prefix}" |
| 35 | + "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}" |
| 36 | + "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON" |
| 37 | + "-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}" |
| 38 | + "-DENABLE_TESTING:BOOL=OFF" |
| 39 | + "-DENABLE_PROGRAMS:BOOL=OFF" |
| 40 | + "-DBUILD_DOCUMENTATION:BOOL=OFF" |
| 41 | + "-DBUILD_EXAMPLES:BOOL=OFF" |
| 42 | + "-DBUILD_TESTING:BOOL=OFF" |
| 43 | + "-DCMAKE_C_FLAGS:STRING=-fPIC" |
| 44 | +) |
| 45 | + |
| 46 | +#[[ |
| 47 | +Build zlib-ng with zlib compatible API enabled. |
| 48 | +]] |
| 49 | +ExternalProject_Add(zlib |
| 50 | + URL https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.5.tar.gz |
| 51 | + URL_HASH SHA256=eca3fe72aea7036c31d00ca120493923c4d5b99fe02e6d3322f7c88dbdcd0085 |
| 52 | + CMAKE_ARGS |
| 53 | + ${default_cmake_args} |
| 54 | + #[[ Build with ZLIB compatible API ]] |
| 55 | + -DZLIB_COMPAT:BOOL=ON |
| 56 | + -DZLIB_ENABLE_TESTS:BOOL=OFF |
| 57 | + #[[ Required to ensure the current ${install_prefix} is always taken into account, |
| 58 | + as ${CMAKE_INSTALL_PREFIX} is cached persistently. |
| 59 | + Ref: https://github.com/zlib-ng/zlib-ng/blob/2.0.5/cmake/detect-install-dirs.cmake ]] |
| 60 | + -DBIN_INSTALL_DIR:PATH=${install_prefix}/bin |
| 61 | + -DLIB_INSTALL_DIR:PATH=${install_prefix}/lib |
| 62 | + -DINC_INSTALL_DIR:PATH=${install_prefix}/include |
| 63 | + -DPKGCONFIG_INSTALL_DIR:PATH=${install_prefix}/lib/pkgconfig |
| 64 | +) |
| 65 | + |
| 66 | +#[[ |
| 67 | +mbedTLS does at present not support https://github.com/zlib-ng/zlib-ng/blob/2.0.5/cmake/detect-install-dirs.cmakeED25519, making it unsuitable for some SSH setups, and at present not a decent |
| 68 | +dependency option for libssh2. |
| 69 | +
|
| 70 | +Target review of ED25519 support is Q3 2021. |
| 71 | +Ref: https://github.com/ARMmbed/mbedtls/issues/2452#issuecomment-802683144 |
| 72 | +Ref: https://github.com/ARMmbed/mbedtls/pull/3245 |
| 73 | +
|
| 74 | +ExternalProject_Add(mbedtls |
| 75 | + URL https://github.com/ARMmbed/mbedtls/archive/refs/tags/v2.27.0.tar.gz |
| 76 | + URL_HASH SHA256=2a07856e541f0e5f6eaee4f78018c52f25bd244ed76f9020dea54a8b02cac6ea |
| 77 | + PATCH_COMMAND |
| 78 | + ./scripts/config.pl set MBEDTLS_THREADING_C && |
| 79 | + ./scripts/config.pl set MBEDTLS_THREADING_PTHREAD && |
| 80 | + ./scripts/config.pl set MBEDTLS_MD4_C |
| 81 | + CMAKE_ARGS |
| 82 | + ${default_cmake_args} |
| 83 | + -DUSE_SHARED_MBEDTLS_LIBRARY:BOOL=${BUILD_SHARED_LIBS} |
| 84 | +) |
| 85 | +]] |
| 86 | + |
| 87 | +#[[ |
| 88 | +Build OpenSSL. |
| 89 | +OpenSSL does not publish any cmake directives, and we have to configure everything ourselves. |
| 90 | +Ref: https://github.com/openssl/openssl/blob/openssl-3.0.0/INSTALL.md |
| 91 | +]] |
| 92 | +set(default_openssl_args |
| 93 | + "--prefix=${install_prefix}" |
| 94 | + #[[ Path on the TARGET system where we expect the (certificate) configuration to live. |
| 95 | + The current allows to piggy back off Debian's ca-certificate package while maintaining our own OpenSSL version. ]] |
| 96 | + "--openssldir=/etc/ssl" |
| 97 | + #[[ Enforce the directory to ${install_prefix}/lib. As depending on the build system, Configure may otherwise choose |
| 98 | + to use /lib64. Which makes locating the libraries more difficult. ]] |
| 99 | + "--libdir=lib" |
| 100 | + "--with-zlib-include=${install_prefix}/include" |
| 101 | + "--with-zlib-lib=${install_prefix}/lib" |
| 102 | + "--release" |
| 103 | + "--banner=Configured" |
| 104 | +) |
| 105 | +if(NOT BUILD_SHARED_LIBS) |
| 106 | + list(APPEND default_openssl_args "no-shared") |
| 107 | + list(APPEND default_openssl_args "-static") |
| 108 | +endif() |
| 109 | +ExternalProject_Add(openssl |
| 110 | + DEPENDS zlib |
| 111 | + URL https://www.openssl.org/source/openssl-3.0.0.tar.gz |
| 112 | + URL_HASH SHA256=59eedfcb46c25214c9bd37ed6078297b4df01d012267fe9e9eee31f61bc70536 |
| 113 | + CONFIGURE_COMMAND <SOURCE_DIR>/Configure ${default_openssl_args} |
| 114 | + BUILD_COMMAND make build_sw |
| 115 | + INSTALL_COMMAND make install_sw |
| 116 | +) |
| 117 | + |
| 118 | +#[[ |
| 119 | +Build libssh2. |
| 120 | +At present with OpenSSL as a backend, see mbedTLS doc block for reasoning. |
| 121 | +]] |
| 122 | +set(default_libssh2_args |
| 123 | + "-DENABLE_ZLIB_COMPRESSION:BOOL=ON" |
| 124 | + "-DCRYPTO_BACKEND:STRING=OpenSSL" |
| 125 | + #[[ -DCRYPTO_BACKEND:STRING=mbedTLS ]] |
| 126 | +) |
| 127 | +if(NOT BUILD_SHARED_LIBS) |
| 128 | + list(APPEND default_libssh2_args "-DOPENSSL_USE_STATIC_LIBS:BOOL=TRUE") |
| 129 | +endif() |
| 130 | +ExternalProject_Add(libssh2 |
| 131 | + DEPENDS zlib |
| 132 | + DEPENDS openssl |
| 133 | + URL https://github.com/libssh2/libssh2/archive/refs/tags/libssh2-1.10.0.tar.gz |
| 134 | + URL_HASH SHA256=31469ccfc71a5247c926e3f0938e122cbb7a7a4a1bdf1cf2d3121f78b558d261 |
| 135 | + CMAKE_ARGS |
| 136 | + ${default_cmake_args} |
| 137 | + ${default_libssh2_args} |
| 138 | +) |
| 139 | + |
| 140 | +#[[ |
| 141 | +Build libgit2 with the above dependencies, or explicit defined builtins. |
| 142 | +]] |
| 143 | +ExternalProject_Add(libgit2 |
| 144 | + DEPENDS zlib |
| 145 | + DEPENDS openssl |
| 146 | + DEPENDS libssh2 |
| 147 | + URL https://github.com/libgit2/libgit2/archive/109b4c887ffb63962c7017a66fc4a1f48becb48e.tar.gz |
| 148 | + URL_HASH SHA256=bc4ef7d6628d2248995bbd86ad77eb96376d683e7121779c7abde480928ae21a |
| 149 | + CMAKE_ARGS |
| 150 | + ${default_cmake_args} |
| 151 | + -DBUILD_CLAR:BOOL:BOOL=OFF |
| 152 | + -DTHREADSAFE:BOOL=ON |
| 153 | + -DUSE_BUNDLED_ZLIB:BOOL=OFF |
| 154 | + -DUSE_HTTP_PARSER:STRING=builtin |
| 155 | + -DREGEX_BACKEND:STRING=builtin |
| 156 | + -DUSE_HTTPS:STRING=OpenSSL |
| 157 | + #[[ -DUSE_HTTPS:STRING=mbedTLS ]] |
| 158 | +) |
0 commit comments