oahcy / thrid_repo_build_script

0 stars 0 forks source link

opanharmony 编译问题 #1

Open oahcy opened 2 years ago

oahcy commented 2 years ago

cmake命令

Command line:   D:\openharmony-sdk\native\3.0.0.0\build-tools\cmake\bin\cmake.exe -v -DRES_DIR=D:/native/engine -DCOCOS_X_PATH=D:/code/engine-native-ext/engine-native -DCOMMON_DIR=D:/native/engine/common -HD:\DevEcoStudioProjects\MyApplication_cocos\entry\..\ -BD:\DevEcoStudioProjects\MyApplication_cocos\entry\.cxx\debug\armeabi-v7a -DOHOS_ARCH=armeabi-v7a -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\DevEcoStudioProjects\MyApplication_cocos\entry\build\intermediates\cmake\debug\obj\armeabi-v7a -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=D:\openharmony-sdk\native\3.0.0.0 -DCMAKE_SYSTEM_NAME=OHOS -DCMAKE_OHOS_ARCH_ABI=armeabi-v7a -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=D:\openharmony-sdk\native\3.0.0.0\build\cmake\ohos.toolchain.cmake -G Ninja -DCMAKE_MAKE_PROGRAM=D:\openharmony-sdk\native\3.0.0.0\build-tools\cmake\bin\ninja.exe -DCMAKE_CXX_FLAGS=-std=c++14

编译 cpp

Command line:   D:\openharmony-sdk\native\3.0.0.0\llvm\bin\clang++.exe --target=arm-linux-ohos --gcc-toolchain=D:/openharmony-sdk/native/3.0.0.0/llvm --sysroot=D:/openharmony-sdk/native/3.0.0.0/sysroot  -DCC_DEBUG=1 -DCC_PLATFORM=9 -DCC_PLATFORM_ANDROID=3 -DCC_PLATFORM_LINUX=6 -DCC_PLATFORM_MAC_IOS=1 -DCC_PLATFORM_MAC_OSX=4 -DCC_PLATFORM_NX=8 -DCC_PLATFORM_OHOS=5 -DCC_PLATFORM_OPENHARMONY=9 -DCC_PLATFORM_QNX=7 -DCC_PLATFORM_WINDOWS=2 -DCC_USE_EDITBOX=1 -DCC_USE_GLES3 -DTBB_USE_EXCEPTIONS=0 -DUSE_AUDIO=0 -DUSE_DRAGONBONES=1 -DUSE_JOB_SYSTEM_TASKFLOW=1 -DUSE_JOB_SYSTEM_TBB=0 -DUSE_MIDDLEWARE=1 -DUSE_PHYSICS_PHYSX=0 -DUSE_SOCKET=0 -DUSE_SPINE=1 -DUSE_V8_DEBUGGER=1 -DUSE_VIDEO=0 -DUSE_WEBSOCKET_SERVER=0 -DUSE_WEBVIEW=0 -D__OPENHARMONY__=1 -Dcocos2d_EXPORTS -ID:/code/engine-native-ext/engine-native/cmake/../external/sources -ID:/code/engine-native-ext/engine-native/external/cmake/../ohos/armeabi-v7a/ext/usr/include -ID:/code/engine-native-ext/engine-native/external/sources -ID:/code/engine-native-ext/engine-native/external/cmake/../ohos/armeabi-v7a/include -ID:/code/engine-native-ext/engine-native/external/cmake/../ohos/armeabi-v7a/include/v8 -ID:/code/engine-native-ext/engine-native/external/cmake/../ohos/armeabi-v7a/include/sqlite -ID:/code/engine-native-ext/engine-native -ID:/code/engine-native-ext/engine-native/cocos -ID:/code/engine-native-ext/engine-native/cocos/renderer -ID:/code/engine-native-ext/engine-native/cocos/platform -ID:/code/engine-native-ext/engine-native/cocos/renderer/core -ID:/code/engine-native-ext/engine-native/cocos/editor-support -ID:/code/engine-native-ext/engine-native/cocos/bindings/jswrapper -ID:/code/engine-native-ext/engine-native/external/sources/EGL -ID:/code/engine-native-ext/engine-native/external/sources/khronos -ID:/code/engine-native-ext/engine-native/external/sources/pvmp3dec/src -ID:/code/engine-native-ext/engine-native/external/sources/pvmp3dec/include -ID:/code/engine-native-ext/engine-native/external/sources/tremolo/Tremolo -isystem D:/code/engine-native-ext/engine-native/external/cmake/../ohos/armeabi-v7a/include/uv -march=armv7a -g -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security  -std=c++14 -Werror=return-type -fPIC   -std=c++17 -MD -MT CMakeFiles/cocos2d.dir/D_/code/engine-native-ext/engine-native/cocos/base/base64.cpp.o -MF CMakeFiles\cocos2d.dir\D_\code\engine-native-ext\engine-native\cocos\base\base64.cpp.o.d -o CMakeFiles/cocos2d.dir/D_/code/engine-native-ext/engine-native/cocos/base/base64.cpp.o -c D:/code/engine-native-ext/engine-native/cocos/base/base64.cpp
oahcy commented 2 years ago

configure参数配置

export LDFLAGS=" --rtlib=compiler-rt -fuse-ld=lld -nostdlib "
export CFLAGS="-fuse-ld=lld --target=arm-linux-ohos --gcc-toolchain=D:/openharmony-sdk/native/3.0.0.0/llvm --sysroot=D:/openharmony-sdk/native/3.0.0.0/sysroot  -nostdinc "
 export PATH=$PATH:/cygdrive/d/openharmony-sdk/native/3.0.0.0/llvm/bin
 export CC=clang
 export LD=lld

  ../configure --host=arm-linux
oahcy commented 2 years ago

使用ninja编译sqlite

cmakelist.txt

cmake_minimum_required(VERSION 3.10)

# set the project name
project(sqlite3)
#for compile warning , not 
set(CMAKE_C_FLAGS "-march=armv7a ${CMAKE_C_FLAGS}")
# bug, not define map_shared on mman-common.h
add_definitions(-DMAP_SHARED=0x01)
# add the executable
add_library(sqlite3 sqlite3.c)

build.sh

ARCH=armeabi-v7a
cmake -S . -B ./bld -DOHOS_ARCH=$ARCH -G Ninja --toolchain D:/openharmony-sdk/native/3.0.0.0/build/cmake/ohos.toolchain.cmake
cmake --build ./bld
oahcy commented 2 years ago

32位第三方库问题

32 会有链接标准库的问题 , 需要加参数:set(CMAKE_CXX_FLAGS "-march=armv7a ${CMAKE_CXX_FLAGS}")

oahcy commented 2 years ago

glslang编译

OSDependent 需要手动改几处宏 :

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0600516e..9c13be01 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,8 @@ project(glslang LANGUAGES CXX)

 set_property(GLOBAL PROPERTY USE_FOLDERS ON)

+set(CMAKE_CXX_FLAGS "-march=armv7a ${CMAKE_CXX_FLAGS}")
+
 # Enable compile commands database
 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

diff --git a/glslang/CMakeLists.txt b/glslang/CMakeLists.txt
index dab5f8bf..a38c4ceb 100644
--- a/glslang/CMakeLists.txt
+++ b/glslang/CMakeLists.txt
@@ -31,14 +31,9 @@
 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.

-if(WIN32)
-    add_subdirectory(OSDependent/Windows)
-elseif(UNIX OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
-    add_subdirectory(OSDependent/Unix)
-else(WIN32)
-    message("unknown platform")
-endif(WIN32)

+    add_subdirectory(OSDependent/Unix)
+message("platform ${CMAKE_SYSTEM_NAME}")
 if(EMSCRIPTEN OR ENABLE_GLSLANG_JS)
     # May be enabled on non-Emscripten builds for binary-size testing.
     add_subdirectory(OSDependent/Web)
diff --git a/glslang/OSDependent/Unix/ossource.cpp b/glslang/OSDependent/Unix/ossource.cpp
index 3f029f02..b518e110 100644
--- a/glslang/OSDependent/Unix/ossource.cpp
+++ b/glslang/OSDependent/Unix/ossource.cpp
@@ -73,7 +73,7 @@ static void DetachThreadLinux(void *)
 //
 void OS_CleanupThreadData(void)
 {
-#if defined(__ANDROID__) || defined(__Fuchsia__)
+#if (1)
     DetachThreadLinux(NULL);
 #else
     int old_cancel_state, old_cancel_type;

编译脚本 , 参考了 https://github.com/YunHsiao/glslang build 分支

#!/bin/bash

set -x
set -e

if [ $# -eq 0 ]; then
    # ARCH=x86
    # ARCH=x86_64
    # ARCH=armeabi-v7a
    ARCH=arm64-v8a
else
    ARCH=$1
fi

# LLVM_STRIP=$NDK_ROOT/toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-strip.exe

BUILD_DIR=build-ohos-$ARCH
OHOS_SDK_ROOT=D:/openharmony-sdk/native/3.0.0.0
LLVM_STRIP=$OHOS_SDK_ROOT/llvm/bin/llvm-strip.exe
rm -rf $BUILD_DIR/output

cmake -B $BUILD_DIR \
    -GNinja \
    -DCMAKE_TOOLCHAIN_FILE=$OHOS_SDK_ROOT/build/cmake/ohos.toolchain.cmake \
    -DOHOS_ARCH=$ARCH \
    -DANDROID_PLATFORM=android-19 \
    -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_HLSL=OFF \
    -DENABLE_SPVREMAPPER=OFF \
    -DSKIP_GLSLANG_INSTALL=ON \
    -DSPIRV_SKIP_EXECUTABLES=ON

ninja -C $BUILD_DIR -v

mkdir $BUILD_DIR/output
find $BUILD_DIR -name "*.a" -exec $LLVM_STRIP --strip-debug {} \; -exec cp {} $BUILD_DIR/output \;

rm $BUILD_DIR/output/*SPIRV-Tools-link*
rm $BUILD_DIR/output/*SPIRV-Tools-reduce*