diff --git a/CMakeLists.txt b/CMakeLists.txt index 9281226135..ef5f89018b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,7 +211,7 @@ else() endif() # Dependencies version, this must match the number in external_deps/build.sh -set(DEPS_VERSION 10) +set(DEPS_VERSION 11) option(USE_EXTERNAL_DEPS "Download or reuse dependencies from EXTERNAL_DEPS_DIR (mandatory for building and running NaCl .nexe binaries)." ON) @@ -482,7 +482,7 @@ if (DEPS_DIR) # Add to paths set(CMAKE_FIND_ROOT_PATH ${DEPS_DIR} ${CMAKE_FIND_ROOT_PATH}) set(CMAKE_INCLUDE_PATH ${DEPS_DIR} ${DEPS_DIR}/include ${CMAKE_INCLUDE_PATH}) - set(CMAKE_FRAMEWORK_PATH ${DEPS_DIR} ${CMAKE_FRAMEWORK_PATH}) + set(CMAKE_FRAMEWORK_PATH ${DEPS_DIR}/lib ${CMAKE_FRAMEWORK_PATH}) set(CMAKE_PREFIX_PATH ${DEPS_DIR} ${CMAKE_PREFIX_PATH}) if (DAEMON_PARENT_SCOPE_DIR) # Also set parent scope so the top level CMakeLists can find precompiled deps @@ -1055,11 +1055,16 @@ if (DEPS_DIR AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER OR BUILD_DUMM # Mac requires some libraries from external_deps if (APPLE) - add_custom_command(TARGET runtime_deps PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${DEPS_DIR}/SDL2.framework - ${FULL_OUTPUT_DIR}/SDL2.framework - ) + file(GLOB RUNTIME_FRAMEWORKS ${DEPS_DIR}/lib/*.framework) + foreach(RUNTIME_FRAMEWORK ${RUNTIME_FRAMEWORKS}) + get_filename_component(RUNTIME_FRAMEWORK_NAME ${RUNTIME_FRAMEWORK} NAME) + add_custom_command(TARGET runtime_deps PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${RUNTIME_FRAMEWORK} + ${FULL_OUTPUT_DIR}/${RUNTIME_FRAMEWORK_NAME} + ) + endforeach() + file(GLOB RUNTIME_LIBS ${DEPS_DIR}/lib/*.dylib) foreach(RUNTIME_LIB ${RUNTIME_LIBS}) add_custom_command(TARGET runtime_deps PRE_BUILD diff --git a/cmake/cross-toolchain-mingw32.cmake b/cmake/cross-toolchain-mingw32.cmake index 3c97d7a0e6..6056ed43b3 100644 --- a/cmake/cross-toolchain-mingw32.cmake +++ b/cmake/cross-toolchain-mingw32.cmake @@ -8,7 +8,7 @@ set( CMAKE_CXX_COMPILER i686-w64-mingw32-g++ ) set( CMAKE_RC_COMPILER i686-w64-mingw32-windres ) # Target prefix -set( CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 ) +set( CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32;${CMAKE_PREFIX_PATH} ) # Find programs using host paths and headers/libraries using target paths set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) diff --git a/cmake/cross-toolchain-mingw64.cmake b/cmake/cross-toolchain-mingw64.cmake index fb308a4556..c0ffe2a84b 100644 --- a/cmake/cross-toolchain-mingw64.cmake +++ b/cmake/cross-toolchain-mingw64.cmake @@ -8,7 +8,7 @@ set( CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++ ) set( CMAKE_RC_COMPILER x86_64-w64-mingw32-windres ) # Target prefix -set( CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32 ) +set( CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32;${CMAKE_PREFIX_PATH} ) # Find programs using host paths and headers/libraries using target paths set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) diff --git a/external_deps/build.sh b/external_deps/build.sh index baa8b2359d..e799e6ff67 100755 --- a/external_deps/build.sh +++ b/external_deps/build.sh @@ -14,7 +14,7 @@ CURL="$(command -v curl)" # This should match the DEPS_VERSION in CMakeLists.txt. # This is mostly to ensure the path the files end up at if you build deps yourself # are the same as the ones when extracting from the downloaded packages. -DEPS_VERSION=10 +DEPS_VERSION=11 # Package download pages PKGCONFIG_BASEURL='https://pkg-config.freedesktop.org/releases' @@ -46,24 +46,26 @@ WASMTIME_BASEURL='https://github.com/bytecodealliance/wasmtime/releases' # Package versions PKGCONFIG_VERSION=0.29.2 -NASM_VERSION=2.16.01 -ZLIB_VERSION=1.2.13 -GMP_VERSION=6.2.1 -NETTLE_VERSION=3.8.1 -CURL_VERSION=7.83.1 -SDL2_VERSION=2.26.5 +NASM_VERSION=2.16.03 +ZLIB_VERSION=1.3.1 +GMP_VERSION=6.3.0 +NETTLE_VERSION=3.10.1 +CURL_VERSION=8.12.1 +SDL2_VERSION=2.32.2 GLEW_VERSION=2.2.0 -PNG_VERSION=1.6.39 -JPEG_VERSION=2.1.5.1 -WEBP_VERSION=1.3.2 +PNG_VERSION=1.6.47 +JPEG_VERSION=3.0.1 +# WebP 1.5.0 requires vld1q_u8_x4() on arm64, but GCC 8.3.0 from Debian Buster doesn't provide it. +WEBP_VERSION=1.4.0 +# OpenAL 1.24.2 requires for_each_n() from C++ 20, but GCC 8.3.0 from Debian Buster doesn't provide it. OPENAL_VERSION=1.23.1 OGG_VERSION=1.3.5 VORBIS_VERSION=1.3.7 -OPUS_VERSION=1.4 +OPUS_VERSION=1.5.2 OPUSFILE_VERSION=0.12 NACLSDK_VERSION=44.0.2403.155 NACLRUNTIME_REVISION=2aea5fcfce504862a825920fcaea1a8426afbd6f -NCURSES_VERSION=6.2 +NCURSES_VERSION=6.5 WASISDK_VERSION=16.0 WASMTIME_VERSION=2.0.2 @@ -75,13 +77,15 @@ CXX='false' LD='ld' AR='ar' RANLIB='ranlib' -CONFIGURE_SHARED=(--disable-shared --enable-static) +LIBS_SHARED='OFF' +LIBS_STATIC='ON' +CMAKE_TOOLCHAIN='' # Always reset flags, we heavily cross-compile and must not inherit any stray flag # from environment. -CFLAGS='' -CXXFLAGS='' CPPFLAGS='' -LDFLAGS='' +CFLAGS='-O2 -fPIC' +CXXFLAGS='-O2 -fPIC' +LDFLAGS='-O2 -fPIC' log() { level="${1}"; shift @@ -166,6 +170,52 @@ download_extract() { extract "${tarball_file}" "${extract_dir}" } +configure_build() { + local configure_args=(--disable-shared --enable-static) + + configure_args=() + + if [ "${LIBS_SHARED}" = 'ON' ] + then + configure_args+=(--enable-shared) + else + configure_args+=(--disable-shared) + fi + + if [ "${LIBS_STATIC}" = 'ON' ] + then + configure_args+=(--enable-static) + else + configure_args+=(--disable-static) + fi + + ./configure \ + --host="${HOST}" \ + --prefix="${PREFIX}" \ + --libdir="${PREFIX}/lib" \ + "${configure_args[@]}" \ + "${@}" + + make + make install +} + +cmake_build() { + local cmake_args=() + + cmake -S . -B build \ + -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN}" \ + -DCMAKE_BUILD_TYPE='Release' \ + -DCMAKE_PREFIX_PATH="${PREFIX}" \ + -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ + -DBUILD_SHARED_LIBS="${LIBS_SHARED}" \ + "${cmake_args[@]}" \ + "${@}" + + cmake --build build + cmake --install build +} + # Build pkg-config build_pkgconfig() { local dir_name="pkg-config-${PKGCONFIG_VERSION}" @@ -177,10 +227,8 @@ build_pkgconfig() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" --with-internal-glib - make - make install + + configure_build --with-internal-glib } # Build NASM @@ -216,19 +264,18 @@ build_zlib() { "${download_only}" && return - cd "${dir_name}" + local zlib_cmake_args=(-DCMAKE_C_FLAGS="${CFLAGS} -DZLIB_CONST") + case "${PLATFORM}" in - windows-*-*) - LOC="${CFLAGS}" make -f win32/Makefile.gcc PREFIX="${HOST}-" - make -f win32/Makefile.gcc install BINARY_PATH="${PREFIX}/bin" LIBRARY_PATH="${PREFIX}/lib" INCLUDE_PATH="${PREFIX}/include" SHARED_MODE=1 - ;; - *) - # The default -O3 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O3" ./configure --prefix="${PREFIX}" --libdir="${PREFIX}/lib" --static --const - make - make install + windows-*-*) + zlib_cmake_args+=(-DBUILD_SHARED_LIBS=ON) ;; esac + + cd "${dir_name}" + + cmake_build "${zlib_cmake_args[@]}" \ + -DZLIB_BUILD_EXAMPLES=OFF } # Build GMP @@ -243,7 +290,6 @@ build_gmp() { "${download_only}" && return - cd "${dir_name}" case "${PLATFORM}" in windows-*-msvc) # Configure script gets confused if we override the compiler. Shouldn't @@ -255,19 +301,21 @@ build_gmp() { ;; esac - # The default -O2 is dropped when there's user-provided CFLAGS. + local gmp_configure_args=() + case "${PLATFORM}" in macos-*-*) # The assembler objects are incompatible with PIE - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" --disable-assembly + gmp_configure_args+=(--disable-assembly) ;; *) - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" ;; esac - make - make install + cd "${dir_name}" + + configure_build "${gmp_configure_args[@]}" + case "${PLATFORM}" in windows-*-msvc) export CC="${CC_BACKUP}" @@ -288,10 +336,8 @@ build_nettle() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" - make - make install + + configure_build } # Build cURL @@ -306,10 +352,77 @@ build_curl() { "${download_only}" && return cd "${dir_name}" - # The user-provided CFLAGS doesn't drop the default -O2 - ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" --without-ssl --without-libssh2 --without-librtmp --without-libidn2 --without-brotli --without-zstd --disable-file --disable-ldap --disable-crypto-auth --disable-gopher --disable-ftp --disable-tftp --disable-dict --disable-imap --disable-mqtt --disable-smtp --disable-pop3 --disable-telnet --disable-rtsp --disable-threaded-resolver --disable-alt-svc "${CONFIGURE_SHARED[@]}" - make - make install + + cmake_build \ + -DBUILD_CURL_EXE=OFF \ + -DBUILD_TESTING=OFF \ + -DENABLE_THREADED_RESOLVER=OFF \ + -DENABLE_UNIX_SOCKETS=OFF \ + -DUSE_HTTPSRR=OFF \ + -DUSE_LIBIDN2=OFF \ + -DUSE_LIBRTMP=OFF \ + -DUSE_MSH3=OFF \ + -DUSE_NGHTTP2=OFF \ + -DUSE_NGTCP2=OFF \ + -DUSE_OPENSSL_QUIC=OFF \ + -DUSE_QUICHE=OFF \ + -DUSE_WIN32_IDN=OFF \ + -DCURL_BROTLI=OFF \ + -DCURL_ZLIB=ON \ + -DCURL_ZSTD=OFF \ + -DCURL_ENABLE_SSL=OFF \ + -DCURL_USE_BEARSSL=OFF \ + -DCURL_USE_GSSAPI=OFF \ + -DCURL_USE_LIBPSL=OFF \ + -DCURL_USE_LIBSSH=OFF \ + -DCURL_USE_LIBSSH2=OFF \ + -DCURL_USE_MBEDTLS=OFF \ + -DCURL_USE_NSS=OFF \ + -DCURL_USE_OPENSSL=OFF \ + -DCURL_USE_WOLFSSL=ON \ + -DCURL_DISABLE_ALTSVC=ON \ + -DCURL_DISABLE_AWS=ON \ + -DCURL_DISABLE_BASIC_AUTH=ON \ + -DCURL_DISABLE_BEARER_AUTH=ON \ + -DCURL_DISABLE_BINDLOCAL=ON \ + -DCURL_DISABLE_CA_SEARCH=ON \ + -DCURL_DISABLE_COOKIES=ON \ + -DCURL_DISABLE_CRYPTO_AUTH=ON \ + -DCURL_DISABLE_DICT=ON \ + -DCURL_DISABLE_DIGEST_AUTH=ON \ + -DCURL_DISABLE_DOH=ON \ + -DCURL_DISABLE_FILE=ON \ + -DCURL_DISABLE_FTP=ON \ + -DCURL_DISABLE_GETOPTIONS=ON \ + -DCURL_DISABLE_GOPHER=ON \ + -DCURL_DISABLE_HSTS=ON \ + -DCURL_DISABLE_HTTP=ON \ + -DCURL_DISABLE_HTTP_AUTH=ON \ + -DCURL_DISABLE_IMAP=ON \ + -DCURL_DISABLE_IPFS=ON \ + -DCURL_DISABLE_KERBEROS_AUTH=ON \ + -DCURL_DISABLE_LDAP=ON \ + -DCURL_DISABLE_LDAPS=ON \ + -DCURL_DISABLE_LIBCURL_OPTION=ON \ + -DCURL_DISABLE_MIME=ON \ + -DCURL_DISABLE_MQTT=ON \ + -DCURL_DISABLE_NETRC=ON \ + -DCURL_DISABLE_NEGOTIATE_AUTH=ON \ + -DCURL_DISABLE_NTLM=ON \ + -DCURL_DISABLE_OPENSSL_AUTO_LOAD=ON \ + -DCURL_DISABLE_PARSEDATE=ON \ + -DCURL_DISABLE_POP3=ON \ + -DCURL_DISABLE_PROGRESS_METER=ON \ + -DCURL_DISABLE_PROXY=ON \ + -DCURL_DISABLE_RTSP=ON \ + -DCURL_DISABLE_SHA512_256=ON \ + -DCURL_DISABLE_SHUFFLE_DNS=ON \ + -DCURL_DISABLE_SMB=ON \ + -DCURL_DISABLE_SMTP=ON \ + -DCURL_DISABLE_SOCKETPAIR=ON \ + -DCURL_DISABLE_TELNET=ON \ + -DCURL_DISABLE_TFTP=ON \ + -DCURL_DISABLE_WEBSOCKETS=ON } # Build SDL2 @@ -366,15 +479,14 @@ build_sdl2() { cp "${sdl2_lib_dir}/"*.dll "${PREFIX}/SDL2/${sdl2_lib_dir}" ;; macos-*-*) - rm -rf "${PREFIX}/SDL2.framework" - cp -R "SDL2.framework" "${PREFIX}" + rm -rf "${PREFIX}/lib/SDL2.framework" + cp -R "SDL2.framework" "${PREFIX}/lib" ;; *) cd "${dir_name}" - # The default -O3 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O3" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" - make - make install + + cmake_build + # Workaround for an SDL2 CMake bug, we need to provide # a bin/ directory even when nothing is used from it. mkdir -p "${PREFIX}/bin" @@ -396,6 +508,7 @@ build_glew() { "${download_only}" && return cd "${dir_name}" + case "${PLATFORM}" in windows-*-*) make SYSTEM="linux-mingw${BITNESS}" GLEW_DEST="${PREFIX}" CC="${CC}" AR="${AR}" RANLIB="${RANLIB}" STRIP="${HOST}-strip" LD="${LD}" CFLAGS.EXTRA="${CFLAGS}" LDFLAGS.EXTRA="${LDFLAGS}" @@ -430,10 +543,11 @@ build_png() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" - make - make install + + cmake_build \ + -DPNG_EXECUTABLES=OFF \ + -DPNG_SHARED="${LIBS_SHARED}" \ + -DPNG_STATIC="${LIBS_STATIC}" } # Build JPEG @@ -486,25 +600,29 @@ build_jpeg() { ;; esac - local jpeg_cmake_call=(cmake -S . -B build -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ - -DCMAKE_C_FLAGS="${CFLAGS}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ - -DCMAKE_SYSTEM_NAME="${SYSTEM_NAME}" -DCMAKE_SYSTEM_PROCESSOR="${SYSTEM_PROCESSOR}" \ - -DWITH_JPEG8=1) + local jpeg_cmake_args=() - cd "${dir_name}" case "${PLATFORM}" in - windows-*-mingw) - "${jpeg_cmake_call[@]}" -DCMAKE_TOOLCHAIN_FILE="${SCRIPT_DIR}/../cmake/cross-toolchain-mingw${BITNESS}.cmake" -DENABLE_SHARED=0 - ;; - windows-*-msvc) - "${jpeg_cmake_call[@]}" -DCMAKE_TOOLCHAIN_FILE="${SCRIPT_DIR}/../cmake/cross-toolchain-mingw${BITNESS}.cmake" -DENABLE_SHARED=1 + windows-*-*) ;; *) - "${jpeg_cmake_call[@]}" -DENABLE_SHARED=0 + # Workaround for: undefined reference to `log10' + # The CMakeLists.txt file only does -lm if UNIX, + # but UNIX may not be true on Linux. + jpeg_cmake_args=(-DUNIX=True) ;; esac - make -C build - make -C build install + + cd "${dir_name}" + + cmake_build \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DENABLE_SHARED="${LIBS_SHARED}" \ + -DENABLE_STATIC="${LIBS_STATIC}" \ + -DCMAKE_SYSTEM_NAME="${SYSTEM_NAME}" \ + -DCMAKE_SYSTEM_PROCESSOR="${SYSTEM_PROCESSOR}" \ + -DWITH_JPEG8=1 \ + "${jpeg_cmake_args[@]}" } # Build WebP @@ -518,10 +636,20 @@ build_webp() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" --disable-libwebpdemux "${CONFIGURE_SHARED[@]}" - make - make install + + # WEBP_LINK_STATIC is ON by default + + cmake_build \ + -DWEBP_BUILD_ANIM_UTILS=OFF \ + -DWEBP_BUILD_CWEBP=OFF \ + -DWEBP_BUILD_DWEBP=OFF \ + -DWEBP_BUILD_EXTRAS=OFF \ + -DWEBP_BUILD_GIF2WEBP=OFF \ + -DWEBP_BUILD_IMG2WEBP=OFF \ + -DWEBP_BUILD_LIBWEBPMUX=OFF \ + -DWEBP_BUILD_VWEBP=OFF \ + -DWEBP_BUILD_WEBPINFO=OFF \ + -DWEBP_BUILD_WEBPMUX=OFF } # Build OpenAL @@ -531,15 +659,10 @@ build_openal() { local dir_name="openal-soft-${OPENAL_VERSION}-bin" local archive_name="${dir_name}.zip" ;; - macos-*-*|linux-*-*) + *) local dir_name="openal-soft-${OPENAL_VERSION}" local archive_name="${dir_name}.tar.bz2" - local openal_cmake_call=(cmake -S . -B . -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ - -DCMAKE_C_FLAGS="${CFLAGS}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \ - -DCMAKE_BUILD_TYPE=Release -DALSOFT_EXAMPLES=OFF) - ;; - *) - log error 'Unsupported platform for OpenAL' + local openal_cmake_args=(-DCMAKE_BUILD_TYPE=Release -DALSOFT_EXAMPLES=OFF) ;; esac @@ -566,16 +689,21 @@ build_openal() { ;; macos-*-*) cd "${dir_name}" - "${openal_cmake_call[@]}" - make - make install + + cmake_build \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DALSOFT_EXAMPLES=OFF \ + -DLIBTYPE=SHARED + install_name_tool -id "@rpath/libopenal.${OPENAL_VERSION}.dylib" "${PREFIX}/lib/libopenal.${OPENAL_VERSION}.dylib" ;; - linux-*-*) + *) cd "${dir_name}" - "${openal_cmake_call[@]}" -DLIBTYPE=STATIC - make - make install + + cmake_build \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DALSOFT_EXAMPLES=OFF + -DLIBTYPE=STATIC ;; esac } @@ -591,13 +719,13 @@ build_ogg() { "${download_only}" && return cd "${dir_name}" + # This header breaks the vorbis and opusfile Mac builds cat <(echo '#include ') include/ogg/os_types.h > os_types.tmp mv os_types.tmp include/ogg/os_types.h - # The user-provided CFLAGS doesn't drop the default -O2 - ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" - make - make install + + # The provided CMakeLists.txt doesn't have an install target. + configure_build } # Build Vorbis @@ -611,10 +739,19 @@ build_vorbis() { "${download_only}" && return cd "${dir_name}" - # The user-provided CFLAGS doesn't drop the default -O3 - ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" --disable-examples - make - make install + + case "${PLATFORM}" in + windows-*-msvc) + # Workaround a build issue on MinGW: + # See: https://github.com/microsoft/vcpkg/issues/22990 + # and: https://github.com/microsoft/vcpkg/pull/23761 + ls win32/vorbis.def win32/vorbisenc.def win32/vorbisfile.def \ + | xargs -I{} -P3 sed -e 's/LIBRARY//' -i {} + ;; + esac + + cmake_build \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 } # Build Opus @@ -627,19 +764,27 @@ build_opus() { "${download_only}" && return - cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. + local opus_cmake_args=() + case "${PLATFORM}" in windows-*-*) - # With MinGW _FORTIFY_SOURCE (added by configure) can only by used with -fstack-protector enabled. - CFLAGS="${CFLAGS} -O2 -D_FORTIFY_SOURCE=0" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" - ;; - *) - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" + # With MinGW, we would get this error: + # undefined reference to `__stack_chk_guard' + opus_cmake_args+=(-DOPUS_FORTIFY_SOURCE=OFF -DOPUS_STACK_PROTECTOR=OFF) ;; esac - make - make install + + cd "${dir_name}" + + cmake_build "${opus_cmake_args[@]}" \ + -DOPUS_BUILD_PROGRAMS=OFF \ + -DOPUS_BUILD_TESTING=OFF \ + -DOPUS_X86_MAY_HAVE_SSE=ON \ + -DOPUS_X86_MAY_HAVE_SSE2=ON \ + -DOPUS_X86_PRESUME_SSE=ON \ + -DOPUS_X86_PRESUME_SSE2=ON \ + -DOPUS_X86_MAY_HAVE_SSE4_1=OFF \ + -DOPUS_X86_MAY_HAVE_AVX2=OFF } # Build OpusFile @@ -653,10 +798,8 @@ build_opusfile() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" "${CONFIGURE_SHARED[@]}" --disable-http - make - make install + + configure_build --disable-http } # Build ncurses @@ -671,11 +814,11 @@ build_ncurses() { "${download_only}" && return cd "${dir_name}" - # The default -O2 is dropped when there's user-provided CFLAGS. + # Configure terminfo search dirs based on the ones used in Debian. By default it will only look in (only) the install directory. - CFLAGS="${CFLAGS} -O2" ./configure --host="${HOST}" --prefix="${PREFIX}" --libdir="${PREFIX}/lib" --enable-widec "${CONFIGURE_SHARED[@]}" --with-terminfo-dirs=/etc/terminfo:/lib/terminfo --with-default-terminfo-dir=/usr/share/terminfo - make - make install + configure_build \ + --with-terminfo-dirs=/etc/terminfo:/lib/terminfo \ + --with-default-terminfo-dir=/usr/share/terminfo } # "Builds" (downloads) the WASI SDK @@ -974,6 +1117,13 @@ build_install() { ;; esac + case "${PLATFORM}" in + windows-*-*) + # CMake looks for libSDL2.a and aborts if missing if this file exists: + rm -rf "${PKG_PREFIX}/lib/cmake/SDL2/SDL2staticTargets.cmake" + ;; + esac + # Remove empty directories find "${PKG_PREFIX}/" -mindepth 1 -type d -empty -delete } @@ -1000,8 +1150,10 @@ build_wipe() { # Common setup code common_setup() { HOST="${2}" + "common_setup_${1}" common_setup_arch + DOWNLOAD_DIR="${WORK_DIR}/download_cache" PKG_BASEDIR="${PLATFORM}_${DEPS_VERSION}" BUILD_BASEDIR="build-${PKG_BASEDIR}" @@ -1012,10 +1164,12 @@ common_setup() { PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig" CPPFLAGS+=" -I${PREFIX}/include" LDFLAGS+=" -L${PREFIX}/lib" + mkdir -p "${DOWNLOAD_DIR}" mkdir -p "${PREFIX}/bin" mkdir -p "${PREFIX}/include" mkdir -p "${PREFIX}/lib" + export CC CXX LD AR RANLIB PKG_CONFIG PKG_CONFIG_PATH PATH CFLAGS CXXFLAGS CPPFLAGS LDFLAGS } @@ -1051,24 +1205,27 @@ common_setup_arch() { # Lua does use this one, which results in compiler warnings. But this is OK because # the Windows build of Lua is only used in developer gamelogic builds, and Microsoft # supports %lld since Visual Studio 2013. Also we don't build Lua anymore. -common_setup_msvc() { - CONFIGURE_SHARED=(--enable-shared --disable-static) - # Libtool bug prevents -static-libgcc from being set in LDFLAGS - CC="${HOST}-gcc -static-libgcc" - CXX="${HOST}-g++ -static-libgcc" +common_setup_windows() { LD="${HOST}-ld" AR="${HOST}-ar" RANLIB="${HOST}-ranlib" CFLAGS+=' -D__USE_MINGW_ANSI_STDIO=0' + CMAKE_TOOLCHAIN="${SCRIPT_DIR}/../cmake/cross-toolchain-mingw${BITNESS}.cmake" +} + +common_setup_msvc() { + LIBS_SHARED='ON' + LIBS_STATIC='OFF' + # Libtool bug prevents -static-libgcc from being set in LDFLAGS + CC="${HOST}-gcc -static-libgcc" + CXX="${HOST}-g++ -static-libgcc" + common_setup_windows } common_setup_mingw() { CC="${HOST}-gcc" CXX="${HOST}-g++" - LD="${HOST}-ld" - AR="${HOST}-ar" - RANLIB="${HOST}-ranlib" - CFLAGS+=' -D__USE_MINGW_ANSI_STDIO=0' + common_setup_windows } common_setup_macos() { @@ -1263,6 +1420,7 @@ fi # Enable parallel build export MAKEFLAGS="-j`nproc 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 1`" export SCONSFLAGS="${MAKEFLAGS}" +export CMAKE_BUILD_PARALLEL_LEVEL="$(nproc 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 1)" # Setup platform platform="${1}"; shift