From f3db8a8fd7297728c4b3d49ee1a11e3a0167a82c Mon Sep 17 00:00:00 2001 From: Cam Ng Date: Thu, 16 May 2024 09:44:44 +0700 Subject: [PATCH] feat: fix zlib error on Mac arm v4 --- third-party/CMakeLists.txt | 100 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index df2b3b5..d1d2eae 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -24,9 +24,6 @@ ExternalProject_Add( -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} ) -############################### -# Install dependencies for engine - # trantor for logging utils ExternalProject_Add( trantor @@ -50,10 +47,35 @@ ExternalProject_Add( -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} ) +if(WIN32) + # Add dlfcn-win32 as an external project + ExternalProject_Add( + dlfcn-win32 + GIT_REPOSITORY https://github.com/dlfcn-win32/dlfcn-win32 + GIT_TAG v1.4.1 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=release + -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_TESTS=OFF + ) +endif() + ############################### -# Install dependencies for Python -if(UNIX) - # Download and install XZUtils for zlib +# Install Python3 dependencies +if(APPLE) + # Download and install OpenSSL + ExternalProject_Add( + OpenSSL + URL https://www.openssl.org/source/openssl-3.3.0.tar.gz + PREFIX ${THIRD_PARTY_INSTALL_PATH} + CONFIGURE_COMMAND ./configure --prefix= + BUILD_COMMAND make -j8 + INSTALL_COMMAND make install + BUILD_IN_SOURCE 1 + ) + + # Download and install XZUtils ExternalProject_Add( XZUtils GIT_REPOSITORY https://github.com/tukaani-project/xz @@ -64,51 +86,37 @@ if(UNIX) -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF ) - if(APPLE) - # Download and install OpenSSL - ExternalProject_Add( - OpenSSL - URL https://www.openssl.org/source/openssl-3.3.0.tar.gz - PREFIX ${THIRD_PARTY_INSTALL_PATH} - CONFIGURE_COMMAND ./Configure --prefix= --openssldir= - BUILD_COMMAND make -j12 - INSTALL_COMMAND make install - BUILD_IN_SOURCE 1 - ) - - else() - # Download and install libffi - ExternalProject_Add( +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + # Download and install zlib + ExternalProject_Add( + zlib + GIT_REPOSITORY https://github.com/madler/zlib + GIT_TAG v1.3.1 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=release + -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_TESTS=OFF + ) + # Download and install libffi + ExternalProject_Add( libffi URL ftp://sourceware.org/pub/libffi/libffi-3.1.tar.gz URL_MD5 f5898b29bbfd70502831a212d9249d10 PREFIX ${THIRD_PARTY_INSTALL_PATH} CONFIGURE_COMMAND ./configure --prefix= --enable-shared - BUILD_COMMAND make -j12 + BUILD_COMMAND make -j8 INSTALL_COMMAND make install BUILD_IN_SOURCE 1 - ) - - ExternalProject_Add_Step( + ) + ExternalProject_Add_Step( libffi move_includes COMMAND ${CMAKE_COMMAND} -E make_directory ${THIRD_PARTY_INSTALL_PATH}/include COMMAND ${CMAKE_COMMAND} -E copy_directory /lib/libffi-3.1/include ${THIRD_PARTY_INSTALL_PATH}/include DEPENDEES install WORKING_DIRECTORY ${THIRD_PARTY_INSTALL_PATH} - ) - endif() - -else() # WINDOWS - # Add dlfcn-win32 as an external project - ExternalProject_Add( - dlfcn-win32 - GIT_REPOSITORY https://github.com/dlfcn-win32/dlfcn-win32 - GIT_TAG v1.4.1 - CMAKE_ARGS - -DCMAKE_BUILD_TYPE=release - -DCMAKE_INSTALL_PREFIX=${THIRD_PARTY_INSTALL_PATH} - -DBUILD_SHARED_LIBS=OFF - -DBUILD_TESTS=OFF ) endif() @@ -125,12 +133,10 @@ if (UNIX) # APPLE and LINUX set(PYTHON_INSTALL_CONFIG_BUILD "--build=x86_64-apple-darwin") endif() set(PYTHON_INSTALL_CONFIG_SSL "--with-openssl=${THIRD_PARTY_INSTALL_PATH}") - set(PYTHON_INSTALL_CONFIG_ZLIB "--with-zlib=${THIRD_PARTY_INSTALL_PATH}") else() set(PYTHON_INSTALL_CONFIG_HOST "") set(PYTHON_INSTALL_CONFIG_BUILD "") set(PYTHON_INSTALL_CONFIG_SSL "") - set(PYTHON_INSTALL_CONFIG_ZLIB "") endif() # Download and install Python3 from source @@ -138,7 +144,7 @@ if (UNIX) # APPLE and LINUX Python3 URL https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz PREFIX ${THIRD_PARTY_INSTALL_PATH} - CONFIGURE_COMMAND ./configure --prefix= --enable-optimizations --with-ensurepip=install --enable-shared ${PYTHON_INSTALL_CONFIG_HOST} ${PYTHON_INSTALL_CONFIG_BUILD} ${PYTHON_INSTALL_CONFIG_SSL} --with-openssl-rpath=auto + CONFIGURE_COMMAND ./configure --prefix= --enable-optimizations --with-ensurepip=install --enable-shared ${PYTHON_INSTALL_CONFIG_HOST} ${PYTHON_INSTALL_CONFIG_BUILD} ${PYTHON_INSTALL_CONFIG_SSL} BUILD_COMMAND make -j12 INSTALL_COMMAND make install BUILD_IN_SOURCE 1 @@ -148,7 +154,7 @@ if (UNIX) # APPLE and LINUX if(APPLE) add_dependencies(Python3 XZUtils OpenSSL) else() # Linux - add_dependencies(Python3 XZUtils libffi) + add_dependencies(Python3 zlib libffi) endif() else() # WINDOWS @@ -157,9 +163,9 @@ else() # WINDOWS PREFIX "${CMAKE_BINARY_DIR}/python" URL "https://www.python.org/ftp/python/3.10.4/python-3.10.4-amd64.exe" DOWNLOAD_NO_EXTRACT 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" + CONFIGURE_COMMAND "" # No configure command + BUILD_COMMAND "" # No build command + INSTALL_COMMAND "" # No install command ) # Download and install from binary @@ -173,4 +179,4 @@ add_dependencies(trantor c-ares) include_directories(${THIRD_PARTY_INSTALL_PATH}/include) link_directories(${THIRD_PARTY_INSTALL_PATH}/lib) -# target_link_libraries( ...) +# target_link_libraries( ...) \ No newline at end of file