Skip to content

Commit

Permalink
feat(cmake): add unified compiler toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
medns authored and zoomchan-cxj committed Jun 8, 2022
1 parent e750dac commit 7713364
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 59 deletions.
66 changes: 7 additions & 59 deletions android/sdk/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions buildconfig/cmake/compiler_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7713364

Please sign in to comment.