Fixed several issues

- Cmake errored out due to the ANDROID_NDK_* variables being used before being set/detected for the first time.
- Fixed one warning regarding one string replace in CMake.
- Fixed warnings when compiling SFML-Activity.
This commit is contained in:
Mario Liebisch 2014-03-11 18:56:40 +01:00 committed by Jonathan De Wachter
parent 75ddae7e90
commit 84bd8c6c5b
2 changed files with 38 additions and 33 deletions

View File

@ -367,32 +367,6 @@ if( ANDROID_FORBID_SYGWIN )
endif() endif()
endif() endif()
# detect current host platform
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x86" )
set( TOOL_OS_SUFFIX "" )
if( CMAKE_HOST_APPLE )
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_WIN32 )
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
set( TOOL_OS_SUFFIX ".exe" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_UNIX )
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
else()
message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif()
# see if we have path to Android NDK # see if we have path to Android NDK
__INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK )
if( NOT ANDROID_NDK ) if( NOT ANDROID_NDK )
@ -466,6 +440,32 @@ else()
sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" )
endif() endif()
# detect current host platform
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x86" )
set( TOOL_OS_SUFFIX "" )
if( CMAKE_HOST_APPLE )
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_WIN32 )
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows" )
set( TOOL_OS_SUFFIX ".exe" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
elseif( CMAKE_HOST_UNIX )
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86" )
if(NOT EXISTS "${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.6/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}")
set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" )
set( ANDROID_NDK_HOST_SYSTEM_ARCH "x64" )
endif()
else()
message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" )
endif()
# get all the details about standalone toolchain # get all the details about standalone toolchain
if( BUILD_WITH_STANDALONE_TOOLCHAIN ) if( BUILD_WITH_STANDALONE_TOOLCHAIN )
__DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" )
@ -538,7 +538,7 @@ __INIT_VARIABLE( ANDROID_ABI OBSOLETE_ARM_TARGET OBSOLETE_ARM_TARGETS VALUES ${A
# verify that target ABI is supported # verify that target ABI is supported
list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx )
if( __androidAbiIdx EQUAL -1 ) if( __androidAbiIdx EQUAL -1 )
string( REPLACE ";" "\", \"", PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" )
message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain.
Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\"
" ) " )

View File

@ -32,6 +32,10 @@
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-activity", __VA_ARGS__)) #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-activity", __VA_ARGS__))
namespace {
typedef void (*activityOnCreatePointer)(ANativeActivity*, void*, size_t);
}
std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo) std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
{ {
// This function reads the value of meta-data "sfml.app.lib_name" // This function reads the value of meta-data "sfml.app.lib_name"
@ -51,19 +55,20 @@ std::string getLibraryName(JNIEnv* lJNIEnv, jobject& objectActivityInfo)
// Get the value of meta-data named "sfml.app.lib_name" // Get the value of meta-data named "sfml.app.lib_name"
jclass classBundle = lJNIEnv->FindClass("android/os/Bundle"); jclass classBundle = lJNIEnv->FindClass("android/os/Bundle");
jmethodID methodGetString = lJNIEnv->GetMethodID(classBundle, "getString", "(Ljava/lang/String;)Ljava/lang/String;"); jmethodID methodGetString = lJNIEnv->GetMethodID(classBundle, "getString", "(Ljava/lang/String;)Ljava/lang/String;");
jobject objectValue = lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName); jstring valueString = (jstring)lJNIEnv->CallObjectMethod(objectMetaData, methodGetString, objectName);
// No meta-data "sfml.app.lib_name" was found so we abord and inform the user // No meta-data "sfml.app.lib_name" was found so we abord and inform the user
if (objectValue == NULL) if (valueString == NULL)
{ {
LOGE("No meta-data 'sfml.app.lib_name' found in AndroidManifest.xml file"); LOGE("No meta-data 'sfml.app.lib_name' found in AndroidManifest.xml file");
exit(1); exit(1);
} }
// Convert the application name to a C++ string and return it // Convert the application name to a C++ string and return it
const char* applicationName = lJNIEnv->GetStringUTFChars(objectValue, NULL); const jsize applicationNameLength = lJNIEnv->GetStringUTFLength(valueString);
std::string ret(applicationName); const char* applicationName = lJNIEnv->GetStringUTFChars(valueString, NULL);
lJNIEnv->ReleaseStringUTFChars(objectValue, applicationName); std::string ret(applicationName, applicationNameLength);
lJNIEnv->ReleaseStringUTFChars(valueString, applicationName);
return ret; return ret;
} }
@ -187,7 +192,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
// crashes (lJavaVM->DetachCurrentThread();) // crashes (lJavaVM->DetachCurrentThread();)
// Call the original ANativeActivity_onCreate function // Call the original ANativeActivity_onCreate function
void (*ANativeActivity_onCreate)(ANativeActivity*, void*, size_t) = dlsym(handle, "ANativeActivity_onCreate"); activityOnCreatePointer ANativeActivity_onCreate = (activityOnCreatePointer)dlsym(handle, "ANativeActivity_onCreate");
if (!ANativeActivity_onCreate) if (!ANativeActivity_onCreate)
{ {