From 3ea00ebab1f5d83e2ce95789ae6fc673bf159875 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 15 Apr 2021 17:15:09 +0800 Subject: [PATCH] fix(cmake): fix cmake build failed at soft link workspace GitOrigin-RevId: 78b50a4f3a4fd0b762d39a91259f34e72997d04a --- .../cross_build_android_arm_inference.sh | 2 +- .../cmake-build/cross_build_ios_arm_inference.sh | 2 +- .../cmake-build/cross_build_linux_arm_inference.sh | 2 +- scripts/cmake-build/host_build.sh | 4 ++-- scripts/cmake-build/utils/utils.sh | 14 +++++++++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/cmake-build/cross_build_android_arm_inference.sh b/scripts/cmake-build/cross_build_android_arm_inference.sh index bdd1f3975..7ae369629 100755 --- a/scripts/cmake-build/cross_build_android_arm_inference.sh +++ b/scripts/cmake-build/cross_build_android_arm_inference.sh @@ -111,7 +111,7 @@ function cmake_build() { echo "create build dir" mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR unset IFS cmake -G "$MAKEFILE_TYPE Makefiles" \ -DCMAKE_TOOLCHAIN_FILE="$NDK_ROOT/build/cmake/android.toolchain.cmake" \ diff --git a/scripts/cmake-build/cross_build_ios_arm_inference.sh b/scripts/cmake-build/cross_build_ios_arm_inference.sh index 196578cd1..290e7673c 100755 --- a/scripts/cmake-build/cross_build_ios_arm_inference.sh +++ b/scripts/cmake-build/cross_build_ios_arm_inference.sh @@ -108,7 +108,7 @@ function cmake_build() { echo "create build dir" mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR cmake -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DIOS_TOOLCHAIN_ROOT=$TOOLCHAIN \ diff --git a/scripts/cmake-build/cross_build_linux_arm_inference.sh b/scripts/cmake-build/cross_build_linux_arm_inference.sh index 2ca7b360c..ec1e4390b 100755 --- a/scripts/cmake-build/cross_build_linux_arm_inference.sh +++ b/scripts/cmake-build/cross_build_linux_arm_inference.sh @@ -131,7 +131,7 @@ function cmake_build() { echo "create build dir" mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR cmake -G "$MAKEFILE_TYPE Makefiles" \ -DCMAKE_C_FLAGS=$CMAKE_C_FLAGS \ -DCMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS \ diff --git a/scripts/cmake-build/host_build.sh b/scripts/cmake-build/host_build.sh index 7f7830c91..58f970d6e 100755 --- a/scripts/cmake-build/host_build.sh +++ b/scripts/cmake-build/host_build.sh @@ -97,7 +97,7 @@ function cmake_build() { echo "create build dir" mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR cmake \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DMGE_INFERENCE_ONLY=$MGE_INFERENCE_ONLY \ @@ -229,7 +229,7 @@ function cmake_build_windows() { echo "create build dir" mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR echo "now try build windows native with cmake/clang-ci/Ninja/Visual Studio ....." export CFLAGS=-$MGE_WINDOWS_BUILD_MARCH export CXXFLAGS=-$MGE_WINDOWS_BUILD_MARCH diff --git a/scripts/cmake-build/utils/utils.sh b/scripts/cmake-build/utils/utils.sh index 0b1fe8fed..87704c256 100755 --- a/scripts/cmake-build/utils/utils.sh +++ b/scripts/cmake-build/utils/utils.sh @@ -9,6 +9,18 @@ if [[ $OS =~ "NT" ]]; then MAKEFILE_TYPE="Unix" fi +READLINK=readlink +if [ $OS = "Darwin" ];then + READLINK=greadlink +fi + +function cd_real_build_dir() { + REAL_DIR=$($READLINK -f $1) + echo "may alias dir: $1" + echo "cd real build dir: ${REAL_DIR}" + cd ${REAL_DIR} +} + function build_flatc() { BUILD_DIR=$1/build_dir/host_flatc/build INSTALL_DIR=$BUILD_DIR/../install @@ -25,7 +37,7 @@ function build_flatc() { mkdir -p $BUILD_DIR mkdir -p $INSTALL_DIR - cd $BUILD_DIR + cd_real_build_dir $BUILD_DIR cmake -G "$MAKEFILE_TYPE Makefiles" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \ -- GitLab