Browse Source

Attempt to fix Android build with PCH enabled targeting API >= 16.
Fix #1100.
[skip appveyor] [ci only: Android, OSX, Emscripten]

Yao Wei Tjong 姚伟忠 10 years ago
parent
commit
ed28d2b24f

+ 3 - 3
CMake/Modules/Urho3D-CMake-common.cmake

@@ -820,13 +820,13 @@ macro (enable_pch HEADER_PATHNAME)
                     # At the moment it seems using the function is the "only way" to get the export flags into a CMake variable
                     # Additionally, CMake implementation of 'VISIBILITY_INLINES_HIDDEN' has a bug (tested in 2.8.12.2) that it erroneously sets the flag for C compiler too
                     add_compiler_export_flags (COMPILER_EXPORT_FLAGS)
-                    # To cater for Android/CMake toolchain which already adds -fPIC flags into the CMake C and CXX compiler flags and MinGW which already uses PIC for all codes
-                    if (NOT ANDROID AND NOT MINGW)
+                    # To cater for MinGW which already uses PIC for all codes
+                    if (NOT MINGW)
                         set (COMPILER_EXPORT_FLAGS "${COMPILER_EXPORT_FLAGS} -fPIC")
                     endif ()
                 elseif (PROJECT_NAME STREQUAL Urho3D AND NOT ${TARGET_NAME} STREQUAL Urho3D AND URHO3D_LIB_TYPE STREQUAL SHARED)
                     # If it is one of the Urho3D library dependency then use the same PIC flag as Urho3D library
-                    if (NOT ANDROID AND NOT MINGW)
+                    if (NOT MINGW)
                         set (COMPILER_EXPORT_FLAGS -fPIC)
                     endif ()
                 endif ()

+ 2 - 8
CMake/Toolchains/android.toolchain.cmake

@@ -1463,15 +1463,9 @@ if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
  set( CMAKE_EXE_LINKER_FLAGS    "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" )
 endif()
 
-# pie/pic
-if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) )
- set( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
+# Urho3D: CMake is able to take care of the PIC flag by itself, so we only need to worry about the PIE flag for executable target targeting API level 16+ (Android 4.1+)
+if( NOT ANDROID_NATIVE_API_LEVEL LESS 16 )
  set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
-else()
- set( CMAKE_POSITION_INDEPENDENT_CODE FALSE )
- # Urho3D: Use upper case flags to be consistent with CMake (avoid both PIC and pic being added which may cause problem with suitabiblity selection of precompiled header)
- set( CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}" )
- set( CMAKE_C_FLAGS   "-fPIC ${CMAKE_C_FLAGS}" )
 endif()
 
 # configure rtti