From ca5854db052d4dac7f47baf68b1d5e406dee0588 Mon Sep 17 00:00:00 2001 From: superzheng Date: Wed, 1 Jun 2022 23:58:18 +0800 Subject: [PATCH] feat(cmake): add unified compiler toolchain --- android/sdk/src/main/jni/CMakeLists.txt | 66 ++---------------- .../cmake/InfraPackagesModule.cmake | 0 buildconfig/cmake/compiler_toolchain.cmake | 67 +++++++++++++++++++ 3 files changed, 74 insertions(+), 59 deletions(-) rename {build => buildconfig}/cmake/InfraPackagesModule.cmake (100%) create mode 100644 buildconfig/cmake/compiler_toolchain.cmake diff --git a/android/sdk/src/main/jni/CMakeLists.txt b/android/sdk/src/main/jni/CMakeLists.txt index 695910e12..0fdf7a304 100644 --- a/android/sdk/src/main/jni/CMakeLists.txt +++ b/android/sdk/src/main/jni/CMakeLists.txt @@ -22,74 +22,22 @@ cmake_minimum_required(VERSION 3.14) project("hippy") -include("../../../../../build/cmake/InfraPackagesModule.cmake") +include("../../../../../buildconfig/cmake/InfraPackagesModule.cmake") +include("../../../../../buildconfig/cmake/compiler_toolchain.cmake") set(CMAKE_VERBOSE_MAKEFILE on) set(CMAKE_VISIBILITY_INLINES_HIDDEN on) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_EXTENSIONS off) -if (${ANDROID_STL} STREQUAL "c++_static") - string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--exclude-libs,libc++_static.a") - string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--exclude-libs,libc++abi.a") -endif() - -# region ABI_COMPILE_OPTIONS -set(ABI_COMPILE_OPTIONS - -fomit-frame-pointer - -fno-threadsafe-statics - -fno-strict-aliasing - -fno-short-enums - -fno-unique-section-names - -fno-trigraphs - -Werror - -Wall - -Wextra - -Wextra-semi - -Wconversion - -Wimplicit-fallthrough - -Wloop-analysis - -Wmissing-field-initializers - -Wunused-local-typedefs - -Wstring-conversion - -Wthread-safety - -Wtautological-overlap-compare - -Wunreachable-code - -Wenum-compare-conditional - -Wheader-hygiene - -Wshadow - -Wno-unused-parameter - -Wno-trigraphs - --param=ssp-buffer-size=4 - -pipe - -Os) - -message("ANDROID_ABI: ${ANDROID_ABI}") -if (${ANDROID_ABI} STREQUAL "armeabi-v7a") - set(ABI_COMPILE_OPTIONS ${ABI_COMPILE_OPTIONS} - -mfloat-abi=softfp) -elseif (${ANDROID_ABI} STREQUAL "arm64-v8a") - # (Empty) -elseif (${ANDROID_ABI} STREQUAL "x86") - set(ABI_COMPILE_OPTIONS ${ABI_COMPILE_OPTIONS} - -m32 - -mssse3 - -mfpmath=sse) -elseif (${ANDROID_ABI} STREQUAL "x86_64") - set(ABI_COMPILE_OPTIONS ${ABI_COMPILE_OPTIONS} - -m64 - -mpopcnt - -msse4.2) -else() - message(FATAL_ERROR "${ANDROID_ABI} is not supported") -endif() - if (${HIDDEN_LIBRARY_SYMBOL} STREQUAL "true") set(CMAKE_CXX_VISIBILITY_PRESET hidden) endif() -message("ABI_COMPILE_OPTIONS: ${ABI_COMPILE_OPTIONS}") -# endregion +if (${ANDROID_STL} STREQUAL "c++_static") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--exclude-libs,libc++_static.a") + string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--exclude-libs,libc++abi.a") +endif() # region dependencies add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../core/third_party/base ${CMAKE_CURRENT_BINARY_DIR}/core/third_party/base) @@ -170,7 +118,7 @@ endif() # endregion add_library(${CMAKE_PROJECT_NAME} SHARED ${CORE_SRC} ${URL_PARSER_SRC} ${JNI_SRC}) -target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE ${ABI_COMPILE_OPTIONS}) +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS}) if (${HIDDEN_LIBRARY_SYMBOL} STREQUAL "true") set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES LINK_DEPENDS ${PROJECT_SOURCE_DIR}/minimum_exports.lst) diff --git a/build/cmake/InfraPackagesModule.cmake b/buildconfig/cmake/InfraPackagesModule.cmake similarity index 100% rename from build/cmake/InfraPackagesModule.cmake rename to buildconfig/cmake/InfraPackagesModule.cmake diff --git a/buildconfig/cmake/compiler_toolchain.cmake b/buildconfig/cmake/compiler_toolchain.cmake new file mode 100644 index 000000000..d58fa5d65 --- /dev/null +++ b/buildconfig/cmake/compiler_toolchain.cmake @@ -0,0 +1,67 @@ +# +# Tencent is pleased to support the open source community by making +# Hippy available. +# +# Copyright (C) 2022 THL A29 Limited, a Tencent company. +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(COMPILE_OPTIONS + -fomit-frame-pointer + -fno-threadsafe-statics + -fno-strict-aliasing + -fno-short-enums + -fno-unique-section-names + -fno-trigraphs + -Werror + -Wall + -Wextra + -Wextra-semi + -Wconversion + -Wimplicit-fallthrough + -Wloop-analysis + -Wmissing-field-initializers + -Wunused-local-typedefs + -Wstring-conversion + -Wthread-safety + -Wtautological-overlap-compare + -Wunreachable-code + -Wenum-compare-conditional + -Wheader-hygiene + -Wshadow + -Wno-unused-parameter + -Wno-trigraphs + --param=ssp-buffer-size=4 + -pipe + -Os) + + if (ANDROID_NDK) + if (${ANDROID_ABI} STREQUAL "armeabi-v7a") + set(COMPILE_OPTIONS ${COMPILE_OPTIONS} + -mfloat-abi=softfp) + elseif (${ANDROID_ABI} STREQUAL "x86") + set(COMPILE_OPTIONS ${COMPILE_OPTIONS} + -m32 + -mssse3 + -mfpmath=sse) + elseif (${ANDROID_ABI} STREQUAL "x86_64") + set(COMPILE_OPTIONS ${COMPILE_OPTIONS} + -m64 + -mpopcnt + -msse4.2) + endif() + endif() +endif()