From 6051a49c78a36b82e77a62e09f0ba5a5b5d14532 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 12 Jun 2020 15:11:04 -0400 Subject: Visual Studio: Add Android support --- Help/release/dev/visual-studio-android.rst | 7 ++ Modules/CMakeDetermineCompilerId.cmake | 29 +++++- Modules/CompilerId/VS-10.vcxproj.in | 4 +- Modules/Platform/Android-Clang.cmake | 3 + Modules/Platform/Android-Determine.cmake | 61 ++++++++++++- Modules/Platform/Android-Initialize.cmake | 2 +- Modules/Platform/Android/VCXProjInspect.vcxproj.in | 38 ++++++++ Source/cmGlobalVisualStudio10Generator.cxx | 100 +++++++++++++++++---- Source/cmGlobalVisualStudio10Generator.h | 16 ++++ Source/cmGlobalVisualStudio14Generator.cxx | 6 ++ Source/cmGlobalVisualStudio14Generator.h | 6 ++ Source/cmGlobalVisualStudioVersionedGenerator.cxx | 38 ++++++++ Source/cmGlobalVisualStudioVersionedGenerator.h | 2 + Source/cmVisualStudio10TargetGenerator.cxx | 59 ++++++++++-- Source/cmVisualStudio10TargetGenerator.h | 2 + Tests/CMakeLists.txt | 61 +++++++++---- Tests/RunCMake/Android/RunCMakeTest.cmake | 53 +++++++++-- Tests/RunCMake/Android/ndk-arm64-v8a-stderr.txt | 7 ++ Tests/RunCMake/Android/ndk-armeabi-arm-stderr.txt | 7 ++ .../RunCMake/Android/ndk-armeabi-thumb-stderr.txt | 7 ++ .../Android/ndk-armeabi-v7a-neon-stderr.txt | 7 ++ Tests/RunCMake/Android/ndk-armeabi-v7a-stderr.txt | 7 ++ Tests/RunCMake/Android/ndk-x86-stderr.txt | 7 ++ Tests/RunCMake/Android/ndk-x86_64-stderr.txt | 7 ++ Tests/RunCMake/CMakeLists.txt | 4 +- Tests/VSAndroid/AndroidManifest.xml | 16 ++++ Tests/VSAndroid/CMakeLists.txt | 57 ++++++++++++ Tests/VSAndroid/build.xml | 4 + Tests/VSAndroid/jni/first.c | 22 +++++ Tests/VSAndroid/jni/first.h | 22 +++++ Tests/VSAndroid/jni/second.c | 25 ++++++ Tests/VSAndroid/proguard-android.txt | 57 ++++++++++++ Tests/VSAndroid/res/values/strings.xml | 4 + .../VSAndroid/src/com/example/twolibs/TwoLibs.java | 46 ++++++++++ Tests/VSNsightTegra/AndroidManifest.xml | 16 ---- Tests/VSNsightTegra/CMakeLists.txt | 57 ------------ Tests/VSNsightTegra/build.xml | 4 - Tests/VSNsightTegra/jni/first.c | 22 ----- Tests/VSNsightTegra/jni/first.h | 22 ----- Tests/VSNsightTegra/jni/second.c | 25 ------ Tests/VSNsightTegra/proguard-android.txt | 57 ------------ Tests/VSNsightTegra/res/values/strings.xml | 4 - .../src/com/example/twolibs/TwoLibs.java | 46 ---------- 43 files changed, 731 insertions(+), 315 deletions(-) create mode 100644 Help/release/dev/visual-studio-android.rst create mode 100644 Modules/Platform/Android/VCXProjInspect.vcxproj.in create mode 100644 Tests/RunCMake/Android/ndk-arm64-v8a-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-armeabi-arm-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-armeabi-thumb-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-armeabi-v7a-neon-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-armeabi-v7a-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-x86-stderr.txt create mode 100644 Tests/RunCMake/Android/ndk-x86_64-stderr.txt create mode 100644 Tests/VSAndroid/AndroidManifest.xml create mode 100644 Tests/VSAndroid/CMakeLists.txt create mode 100644 Tests/VSAndroid/build.xml create mode 100644 Tests/VSAndroid/jni/first.c create mode 100644 Tests/VSAndroid/jni/first.h create mode 100644 Tests/VSAndroid/jni/second.c create mode 100644 Tests/VSAndroid/proguard-android.txt create mode 100644 Tests/VSAndroid/res/values/strings.xml create mode 100644 Tests/VSAndroid/src/com/example/twolibs/TwoLibs.java delete mode 100644 Tests/VSNsightTegra/AndroidManifest.xml delete mode 100644 Tests/VSNsightTegra/CMakeLists.txt delete mode 100644 Tests/VSNsightTegra/build.xml delete mode 100644 Tests/VSNsightTegra/jni/first.c delete mode 100644 Tests/VSNsightTegra/jni/first.h delete mode 100644 Tests/VSNsightTegra/jni/second.c delete mode 100644 Tests/VSNsightTegra/proguard-android.txt delete mode 100644 Tests/VSNsightTegra/res/values/strings.xml delete mode 100644 Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java diff --git a/Help/release/dev/visual-studio-android.rst b/Help/release/dev/visual-studio-android.rst new file mode 100644 index 0000000..4e1a110 --- /dev/null +++ b/Help/release/dev/visual-studio-android.rst @@ -0,0 +1,7 @@ +visual-studio-android +--------------------- + +* The :ref:`Visual Studio Generators` for Visual Studio 2015 and above gained + support for the Visual Studio Tools for Android. This allows you to set + :variable:`CMAKE_SYSTEM_NAME` to `Android` to generate `.vcxproj` files for + the Android tools. diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index df48fa5..ebfd5a4 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -248,7 +248,7 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_PostBuildEvent_Command "") if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$") set(id_cl_var "ClangClExecutable") - elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Cc][Ll][Aa][Nn][Gg][Cc][Ll]$") + elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Cc][Ll][Aa][Nn][Gg]([Cc][Ll]$|_[0-9])") set(id_cl "$(CLToolExe)") elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*") set(id_cl clang.exe) @@ -310,17 +310,36 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} set(id_PreferredToolArchitecture "") endif() if(CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone") + set(id_keyword "Win32Proj") set(id_system "Windows Phone") elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + set(id_keyword "Win32Proj") set(id_system "Windows Store") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(id_keyword "Android") + set(id_system "Android") else() + set(id_keyword "Win32Proj") set(id_system "") endif() - if(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)") + if(id_keyword STREQUAL "Android") + if(CMAKE_GENERATOR MATCHES "Visual Studio 14") + set(id_system_version "2.0") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + set(id_system_version "3.0") + else() + set(id_system_version "") + endif() + elseif(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)") set(id_system_version "${CMAKE_MATCH_1}") else() set(id_system_version "") endif() + if(id_keyword STREQUAL "Android") + set(id_config_type "DynamicLibrary") + else() + set(id_config_type "Application") + endif() if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) set(id_WindowsTargetPlatformVersion "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") endif() @@ -333,9 +352,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} string(APPEND id_CustomGlobals "<${CMAKE_MATCH_1}>${CMAKE_MATCH_2}\n ") endif() endforeach() - if(id_platform STREQUAL ARM64) + if(id_keyword STREQUAL "Android") + set(id_WindowsSDKDesktopARMSupport "") + elseif(id_platform STREQUAL "ARM64") set(id_WindowsSDKDesktopARMSupport "true") - elseif(id_platform STREQUAL ARM) + elseif(id_platform STREQUAL "ARM") set(id_WindowsSDKDesktopARMSupport "true") else() set(id_WindowsSDKDesktopARMSupport "") diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in index b48a332..3598fc7 100644 --- a/Modules/CompilerId/VS-10.vcxproj.in +++ b/Modules/CompilerId/VS-10.vcxproj.in @@ -9,7 +9,7 @@ {CAE07175-D007-4FC3-BFE8-47B392814159} CompilerId@id_lang@ - Win32Proj + @id_keyword@ @id_system@ @id_system_version@ @id_WindowsTargetPlatformVersion@ @@ -24,7 +24,7 @@ @id_PreferredToolArchitecture@ - Application + @id_config_type@ @id_toolset@ MultiByte diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake index 759448b..160eada 100644 --- a/Modules/Platform/Android-Clang.cmake +++ b/Modules/Platform/Android-Clang.cmake @@ -53,4 +53,7 @@ macro(__android_compiler_clang lang) endif() list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}") endif() + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(_ANDROID_STL_NOSTDLIBXX 1) + endif() endmacro() diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake index 2225897..11a0504 100644 --- a/Modules/Platform/Android-Determine.cmake +++ b/Modules/Platform/Android-Determine.cmake @@ -7,8 +7,8 @@ # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with -# that functionality for now. Later we may try to integrate this. -if(CMAKE_GENERATOR MATCHES "Visual Studio") +# that functionality for now. +if(CMAKE_GENERATOR_PLATFORM STREQUAL "Tegra-Android") return() endif() @@ -27,6 +27,63 @@ endif() cmake_policy(PUSH) cmake_policy(SET CMP0057 NEW) # if IN_LIST +# If using Android tools for Visual Studio, compile a sample project to get the +# sysroot. +if(CMAKE_GENERATOR MATCHES "Visual Studio") + if(NOT CMAKE_SYSROOT) + set(vcx_platform ${CMAKE_GENERATOR_PLATFORM}) + if(CMAKE_GENERATOR MATCHES "Visual Studio 1[45]") + set(vcx_sysroot_var "Sysroot") + else() + set(vcx_sysroot_var "SysrootLink") + endif() + if(CMAKE_GENERATOR MATCHES "Visual Studio 14") + set(vcx_revision "2.0") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]") + set(vcx_revision "3.0") + else() + set(vcx_revision "") + endif() + configure_file(${CMAKE_ROOT}/Modules/Platform/Android/VCXProjInspect.vcxproj.in + ${CMAKE_PLATFORM_INFO_DIR}/VCXProjInspect.vcxproj @ONLY) + execute_process( + COMMAND "${CMAKE_VS_MSBUILD_COMMAND}" "VCXProjInspect.vcxproj" + "/p:Configuration=Debug" "/p:Platform=${vcx_platform}" + WORKING_DIRECTORY ${CMAKE_PLATFORM_INFO_DIR} + OUTPUT_VARIABLE VCXPROJ_INSPECT_OUTPUT + ERROR_VARIABLE VCXPROJ_INSPECT_OUTPUT + RESULT_VARIABLE VCXPROJ_INSPECT_RESULT + ) + if(NOT CMAKE_SYSROOT AND VCXPROJ_INSPECT_OUTPUT MATCHES "CMAKE_SYSROOT=([^%\r\n]+)[\r\n]") + # Strip VS diagnostic output from the end of the line. + string(REGEX REPLACE " \\(TaskId:[0-9]*\\)$" "" _sysroot "${CMAKE_MATCH_1}") + if(EXISTS "${_sysroot}") + file(TO_CMAKE_PATH "${_sysroot}" CMAKE_SYSROOT) + endif() + endif() + if(VCXPROJ_INSPECT_RESULT) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining the sysroot for the Android NDK failed. +The output was: +${VCXPROJ_INSPECT_RESULT} +${VCXPROJ_INSPECT_OUTPUT} + +") + else() + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining the sysroot for the Android NDK succeeded. +The output was: +${VCXPROJ_INSPECT_RESULT} +${VCXPROJ_INSPECT_OUTPUT} + +") + endif() + endif() + if(NOT CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION) + set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang") + endif() +endif() + # If the user provided CMAKE_SYSROOT for us, extract information from it. set(_ANDROID_SYSROOT_NDK "") set(_ANDROID_SYSROOT_API "") diff --git a/Modules/Platform/Android-Initialize.cmake b/Modules/Platform/Android-Initialize.cmake index b90dd7a..5019c28 100644 --- a/Modules/Platform/Android-Initialize.cmake +++ b/Modules/Platform/Android-Initialize.cmake @@ -6,7 +6,7 @@ # Support for NVIDIA Nsight Tegra Visual Studio Edition was previously # implemented in the CMake VS IDE generators. Avoid interfering with -# that functionality for now. Later we may try to integrate this. +# that functionality for now. if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android") return() endif() diff --git a/Modules/Platform/Android/VCXProjInspect.vcxproj.in b/Modules/Platform/Android/VCXProjInspect.vcxproj.in new file mode 100644 index 0000000..6919d2c --- /dev/null +++ b/Modules/Platform/Android/VCXProjInspect.vcxproj.in @@ -0,0 +1,38 @@ + + + + + Debug + @vcx_platform@ + + + + {14D44772-ECF7-47BD-9E29-BC62FAF940A5} + VCXProjInspect + Android + Android + @vcx_revision@ + + + + + + DynamicLibrary + MultiByte + + + + + + <_ProjectFileVersion>10.0.30319.1 + false + + + + %40echo CMAKE_SYSROOT=$(@vcx_sysroot_var@) + + + + + + diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index cef9062..3805546 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -508,18 +508,16 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf) mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); return false; } - std::string v = this->GetInstalledNsightTegraVersion(); - if (v.empty()) { - mf->IssueMessage(MessageType::FATAL_ERROR, - "CMAKE_SYSTEM_NAME is 'Android' but " - "'NVIDIA Nsight Tegra Visual Studio Edition' " - "is not installed."); - return false; + if (mf->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM") == "Tegra-Android") { + if (!this->InitializeTegraAndroid(mf)) { + return false; + } + } else { + this->SystemIsAndroid = true; + if (!this->InitializeAndroid(mf)) { + return false; + } } - this->DefaultPlatformName = "Tegra-Android"; - this->DefaultPlatformToolset = "Default"; - this->NsightTegraVersion = v; - mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v); } return true; @@ -561,6 +559,31 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf) return false; } +bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf) +{ + std::string v = this->GetInstalledNsightTegraVersion(); + if (v.empty()) { + mf->IssueMessage(MessageType::FATAL_ERROR, + "CMAKE_SYSTEM_NAME is 'Android' but " + "'NVIDIA Nsight Tegra Visual Studio Edition' " + "is not installed."); + return false; + } + this->DefaultPlatformName = "Tegra-Android"; + this->DefaultPlatformToolset = "Default"; + this->NsightTegraVersion = v; + mf->AddDefinition("CMAKE_VS_NsightTegra_VERSION", v); + return true; +} + +bool cmGlobalVisualStudio10Generator::InitializeAndroid(cmMakefile* mf) +{ + std::ostringstream e; + e << this->GetName() << " does not support Android."; + mf->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return false; +} + bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset( std::string& toolset) const { @@ -595,6 +618,28 @@ void cmGlobalVisualStudio10Generator::Generate() { this->LongestSource = LongestSourcePath(); this->cmGlobalVisualStudio8Generator::Generate(); + if (!this->AndroidExecutableWarnings.empty() && + !this->CMakeInstance->GetIsInTryCompile()) { + std::ostringstream e; + /* clang-format off */ + e << + "You are using Visual Studio tools for Android, which does not support " + "standalone executables. However, the following executable targets do " + "not have the ANDROID_GUI property set, and thus will not be built as " + "expected. They will be built as shared libraries with executable " + "filenames:\n" + " "; + /* clang-format on */ + bool first = true; + for (auto const& name : this->AndroidExecutableWarnings) { + if (!first) { + e << ", "; + } + first = false; + e << name; + } + this->CMakeInstance->IssueMessage(MessageType::WARNING, e.str()); + } if (this->LongestSource.Length > 0) { cmLocalGenerator* lg = this->LongestSource.Target->GetLocalGenerator(); std::ostringstream e; @@ -661,8 +706,14 @@ std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString() if (!this->GeneratorToolset.empty()) { return this->GeneratorToolset; } - if (!this->DefaultPlatformToolset.empty()) { - return this->DefaultPlatformToolset; + if (this->SystemIsAndroid) { + if (!this->DefaultAndroidToolset.empty()) { + return this->DefaultAndroidToolset; + } + } else { + if (!this->DefaultPlatformToolset.empty()) { + return this->DefaultPlatformToolset; + } } static std::string const empty; return empty; @@ -876,7 +927,10 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) epg.Attribute("Label", "Globals"); cmXMLElement(epg, "ProjectGuid") .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}"); - cmXMLElement(epg, "Keyword").Content("Win32Proj"); + cmXMLElement(epg, "Keyword") + .Content(mf->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android" + ? "Android" + : "Win32Proj"); cmXMLElement(epg, "Platform").Content(this->GetPlatformName()); if (this->GetSystemName() == "WindowsPhone") { cmXMLElement(epg, "ApplicationType").Content("Windows Phone"); @@ -886,15 +940,21 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf) cmXMLElement(epg, "ApplicationType").Content("Windows Store"); cmXMLElement(epg, "ApplicationTypeRevision") .Content(this->GetApplicationTypeRevision()); + } else if (this->GetSystemName() == "Android") { + cmXMLElement(epg, "ApplicationType").Content("Android"); + cmXMLElement(epg, "ApplicationTypeRevision") + .Content(this->GetApplicationTypeRevision()); } if (!this->WindowsTargetPlatformVersion.empty()) { cmXMLElement(epg, "WindowsTargetPlatformVersion") .Content(this->WindowsTargetPlatformVersion); } - if (this->GetPlatformName() == "ARM64") { - cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true"); - } else if (this->GetPlatformName() == "ARM") { - cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true"); + if (this->GetSystemName() != "Android") { + if (this->GetPlatformName() == "ARM64") { + cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true"); + } else if (this->GetPlatformName() == "ARM") { + cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true"); + } } } cmXMLElement(eprj, "Import") @@ -1206,6 +1266,10 @@ std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion() std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const { + if (this->GetSystemName() == "Android") { + return this->GetAndroidApplicationTypeRevision(); + } + // Return the first two '.'-separated components of the Windows version. std::string::size_type end1 = this->SystemVersion.find('.'); std::string::size_type end2 = diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index bd5c4be..0c53537 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -4,6 +4,7 @@ #define cmGlobalVisualStudio10Generator_h #include +#include #include "cmGlobalVisualStudio8Generator.h" #include "cmVisualStudio10ToolsetOptions.h" @@ -43,6 +44,11 @@ public: void EnableLanguage(std::vector const& languages, cmMakefile*, bool optional) override; + void AddAndroidExecutableWarning(const std::string& name) + { + this->AndroidExecutableWarnings.insert(name); + } + bool IsCudaEnabled() const { return this->CudaEnabled; } /** Generating for Nsight Tegra VS plugin? */ @@ -100,6 +106,9 @@ public: /** Return true if building for WindowsStore */ bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; } + /** Return true if building for Android */ + bool TargetsAndroid() const { return this->SystemIsAndroid; } + const char* GetCMakeCFGIntDir() const override { return "$(Configuration)"; } bool Find64BitTools(cmMakefile* mf); @@ -128,6 +137,8 @@ public: /** Return the first two components of CMAKE_SYSTEM_VERSION. */ std::string GetApplicationTypeRevision() const; + virtual const char* GetAndroidApplicationTypeRevision() const { return ""; } + cmIDEFlagTable const* GetClFlagTable() const; cmIDEFlagTable const* GetCSharpFlagTable() const; cmIDEFlagTable const* GetRcFlagTable() const; @@ -148,6 +159,8 @@ protected: virtual bool InitializeWindowsCE(cmMakefile* mf); virtual bool InitializeWindowsPhone(cmMakefile* mf); virtual bool InitializeWindowsStore(cmMakefile* mf); + virtual bool InitializeTegraAndroid(cmMakefile* mf); + virtual bool InitializeAndroid(cmMakefile* mf); virtual bool ProcessGeneratorToolsetField(std::string const& key, std::string const& value); @@ -171,6 +184,7 @@ protected: std::string GeneratorToolsetCudaCustomDir; std::string DefaultPlatformToolset; std::string DefaultPlatformToolsetHostArchitecture; + std::string DefaultAndroidToolset; std::string WindowsTargetPlatformVersion; std::string SystemName; std::string SystemVersion; @@ -188,6 +202,7 @@ protected: bool SystemIsWindowsCE = false; bool SystemIsWindowsPhone = false; bool SystemIsWindowsStore = false; + bool SystemIsAndroid = false; private: class Factory; @@ -211,6 +226,7 @@ private: std::string MSBuildCommand; bool MSBuildCommandInitialized; cmVisualStudio10ToolsetOptions ToolsetOptions; + std::set AndroidExecutableWarnings; virtual std::string FindMSBuildCommand(); std::string FindDevEnvCommand() override; std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); } diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index f549b6a..451d448 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -109,6 +109,7 @@ cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator( "ProductDir", vc14Express, cmSystemTools::KeyWOW64_32); this->DefaultPlatformToolset = "v140"; + this->DefaultAndroidToolset = "Clang_3_8"; this->DefaultCLFlagTableName = "v140"; this->DefaultCSharpFlagTableName = "v140"; this->DefaultLibFlagTableName = "v14"; @@ -159,6 +160,11 @@ bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf) return true; } +bool cmGlobalVisualStudio14Generator::InitializeAndroid(cmMakefile*) +{ + return true; +} + bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf, bool required) { diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index ccc2917..39353f2 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -23,12 +23,18 @@ public: bool MatchesGeneratorName(const std::string& name) const override; + const char* GetAndroidApplicationTypeRevision() const override + { + return "2.0"; + } + protected: cmGlobalVisualStudio14Generator(cmake* cm, const std::string& name, std::string const& platformInGeneratorName); bool InitializeWindows(cmMakefile* mf) override; bool InitializeWindowsStore(cmMakefile* mf) override; + bool InitializeAndroid(cmMakefile* mf) override; bool SelectWindowsStoreToolset(std::string& toolset) const override; // These aren't virtual because we need to check if the selected version diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index 605dc8b..e2e045c 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -100,6 +100,24 @@ static const char* VSVersionToToolset( return ""; } +static const char* VSVersionToAndroidToolset( + cmGlobalVisualStudioGenerator::VSVersion v) +{ + switch (v) { + case cmGlobalVisualStudioGenerator::VS9: + case cmGlobalVisualStudioGenerator::VS10: + case cmGlobalVisualStudioGenerator::VS11: + case cmGlobalVisualStudioGenerator::VS12: + return ""; + case cmGlobalVisualStudioGenerator::VS14: + return "Clang_3_8"; + case cmGlobalVisualStudioGenerator::VS15: + case cmGlobalVisualStudioGenerator::VS16: + return "Clang_5_0"; + } + return ""; +} + static const char vs15generatorName[] = "Visual Studio 15 2017"; // Map generator name without year to name with year. @@ -284,6 +302,7 @@ cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator( this->Version = version; this->ExpressEdition = false; this->DefaultPlatformToolset = VSVersionToToolset(this->Version); + this->DefaultAndroidToolset = VSVersionToAndroidToolset(this->Version); this->DefaultCLFlagTableName = VSVersionToToolset(this->Version); this->DefaultCSharpFlagTableName = VSVersionToToolset(this->Version); this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version); @@ -408,6 +427,25 @@ bool cmGlobalVisualStudioVersionedGenerator::IsStdOutEncodingSupported() const vsInstanceVersion > vsInstanceVersion16_7_P2); } +const char* +cmGlobalVisualStudioVersionedGenerator::GetAndroidApplicationTypeRevision() + const +{ + switch (this->Version) { + case cmGlobalVisualStudioGenerator::VS9: + case cmGlobalVisualStudioGenerator::VS10: + case cmGlobalVisualStudioGenerator::VS11: + case cmGlobalVisualStudioGenerator::VS12: + return ""; + case cmGlobalVisualStudioGenerator::VS14: + return "2.0"; + case cmGlobalVisualStudioGenerator::VS15: + case cmGlobalVisualStudioGenerator::VS16: + return "3.0"; + } + return ""; +} + std::string cmGlobalVisualStudioVersionedGenerator::GetAuxiliaryToolset() const { const char* version = this->GetPlatformToolsetVersion(); diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h index cbd3ba7..d5b8337 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.h +++ b/Source/cmGlobalVisualStudioVersionedGenerator.h @@ -36,6 +36,8 @@ public: bool IsStdOutEncodingSupported() const override; + const char* GetAndroidApplicationTypeRevision() const override; + protected: cmGlobalVisualStudioVersionedGenerator( VSVersion version, cmake* cm, const std::string& name, diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 31bb7be..e977891 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -234,13 +234,14 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( { this->Makefile->GetConfigurations(this->Configurations); this->NsightTegra = gg->IsNsightTegra(); + this->Android = gg->TargetsAndroid(); for (int i = 0; i < 4; ++i) { this->NsightTegraVersion[i] = 0; } sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u", &this->NsightTegraVersion[0], &this->NsightTegraVersion[1], &this->NsightTegraVersion[2], &this->NsightTegraVersion[3]); - this->MSTools = !this->NsightTegra; + this->MSTools = !this->NsightTegra && !this->Android; this->Managed = false; this->TargetCompileAsWinRT = false; this->IsMissingFiles = false; @@ -333,6 +334,13 @@ void cmVisualStudio10TargetGenerator::Generate() this->ProjectType = csproj; this->Managed = true; } + + if (this->Android && + this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE && + !this->GeneratorTarget->Target->IsAndroidGuiExecutable()) { + this->GlobalGenerator->AddAndroidExecutableWarning(this->Name); + } + // Tell the global generator the name of the project file this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME", this->Name); @@ -427,7 +435,7 @@ void cmVisualStudio10TargetGenerator::Generate() e1.Attribute("Label", "Globals"); e1.Element("ProjectGuid", "{" + this->GUID + "}"); - if (this->MSTools && + if ((this->MSTools || this->Android) && this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) { this->WriteApplicationTypeSettings(e1); this->VerifyNecessaryFiles(); @@ -469,7 +477,11 @@ void cmVisualStudio10TargetGenerator::Generate() cmProp vsGlobalKeyword = this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD"); if (!vsGlobalKeyword) { - e1.Element("Keyword", "Win32Proj"); + if (this->GlobalGenerator->TargetsAndroid()) { + e1.Element("Keyword", "Android"); + } else { + e1.Element("Keyword", "Win32Proj"); + } } else { e1.Element("Keyword", *vsGlobalKeyword); } @@ -1137,6 +1149,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) !this->GeneratorTarget->Target->IsAndroidGuiExecutable()) { // Android executables are .so too. configType = "DynamicLibrary"; + } else if (this->Android) { + configType = "DynamicLibrary"; } else { configType = "Application"; } @@ -1166,6 +1180,8 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0) } } else if (this->NsightTegra) { this->WriteNsightTegraConfigurationValues(e1, c); + } else if (this->Android) { + this->WriteAndroidConfigurationValues(e1, c); } } } @@ -1324,6 +1340,24 @@ void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues( } } +void cmVisualStudio10TargetGenerator::WriteAndroidConfigurationValues( + Elem& e1, std::string const&) +{ + cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator; + if (cmProp projectToolsetOverride = + this->GeneratorTarget->GetProperty("VS_PLATFORM_TOOLSET")) { + e1.Element("PlatformToolset", *projectToolsetOverride); + } else if (const char* toolset = gg->GetPlatformToolset()) { + e1.Element("PlatformToolset", toolset); + } + if (cmProp stlType = + this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) { + if (*stlType != "none") { + e1.Element("UseOfStl", *stlType); + } + } +} + void cmVisualStudio10TargetGenerator::WriteCustomCommands(Elem& e0) { this->CSharpCustomCommandNames.clear(); @@ -2909,7 +2943,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( } } - if (this->MSTools) { + if (this->Android) { + e2.Element("ObjectFileName", "$(IntDir)%(filename).o"); + } else if (this->MSTools) { cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*"); const char* toolset = this->GlobalGenerator->GetPlatformToolset(); if (toolset && clangToolset.find(toolset)) { @@ -4347,6 +4383,7 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1) bool isAppContainer = false; bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone(); bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore(); + bool const isAndroid = this->GlobalGenerator->TargetsAndroid(); std::string const& rev = this->GlobalGenerator->GetApplicationTypeRevision(); if (isWindowsPhone || isWindowsStore) { e1.Element("ApplicationType", @@ -4384,13 +4421,19 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1) this->Name + "_$(Configuration)_$(Platform).xap"); } } + } else if (isAndroid) { + e1.Element("ApplicationType", "Android"); + e1.Element("ApplicationTypeRevision", + gg->GetAndroidApplicationTypeRevision()); } if (isAppContainer) { e1.Element("AppContainerApplication", "true"); - } else if (this->Platform == "ARM64") { - e1.Element("WindowsSDKDesktopARM64Support", "true"); - } else if (this->Platform == "ARM") { - e1.Element("WindowsSDKDesktopARMSupport", "true"); + } else if (!isAndroid) { + if (this->Platform == "ARM64") { + e1.Element("WindowsSDKDesktopARM64Support", "true"); + } else if (this->Platform == "ARM") { + e1.Element("WindowsSDKDesktopARMSupport", "true"); + } } std::string const& targetPlatformVersion = gg->GetWindowsTargetPlatformVersion(); diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 7c71de3..c54057a 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -70,6 +70,7 @@ private: void WriteExtraSource(Elem& e1, cmSourceFile const* sf); void WriteNsightTegraConfigurationValues(Elem& e1, std::string const& config); + void WriteAndroidConfigurationValues(Elem& e1, std::string const& config); void WriteSource(Elem& e2, cmSourceFile const* sf); void WriteExcludeFromBuild(Elem& e2, std::vector const& exclude_configs); @@ -215,6 +216,7 @@ private: bool MSTools; bool Managed; bool NsightTegra; + bool Android; unsigned int NsightTegraVersion[4]; bool TargetCompileAsWinRT; std::set IPOEnabledConfigurations; diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index b771ff5..8c871c3 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -206,6 +206,26 @@ if(BUILD_TESTING) set(${reg} 0) endif() endforeach() + if(COMMAND cmake_host_system_information) + set(info_vs15 "VS_15_DIR") + set(info_vs16 "VS_16_DIR") + set(vs_versions) + if(WIN32) + if(NOT CMAKE_VERSION VERSION_LESS 3.14) + set(vs_versions vs15 vs16) + elseif(NOT CMAKE_VERSION VERSION_LESS 3.8) + set(vs_versions vs15) + endif() + endif() + foreach(info ${vs_versions}) + cmake_host_system_information(RESULT found QUERY "${info_${info}}") + if(found) + set(${info} 1) + else() + set(${info} 0) + endif() + endforeach() + endif() endif() #--------------------------------------------------------------------------- @@ -2316,32 +2336,41 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH endforeach() endif() + macro(add_test_VSAndroid name generator platform) + add_test(NAME "VSAndroid.${name}.${platform}" COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/VSAndroid" + "${CMake_BINARY_DIR}/Tests/VSAndroid/${name}/${platform}" + --build-generator "${generator}" + --build-project VSAndroid + --build-config $ + --build-options -DCMAKE_SYSTEM_NAME=Android "-A${platform}" + ) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSAndroid/${name}") + endmacro() if(tegra AND NOT "${CMake_SOURCE_DIR};${CMake_BINARY_DIR}" MATCHES " ") - macro(add_test_VSNsightTegra name generator) - add_test(NAME VSNsightTegra.${name} COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/VSNsightTegra" - "${CMake_BINARY_DIR}/Tests/VSNsightTegra/${name}" - --build-generator "${generator}" - --build-project VSNsightTegra - --build-config $ - --build-options -DCMAKE_SYSTEM_NAME=Android - ) - list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSNsightTegra/${name}") - endmacro() if(vs10) - add_test_VSNsightTegra(vs10 "Visual Studio 10 2010") + add_test_VSAndroid(vs10 "Visual Studio 10 2010" "Tegra-Android") endif() if(vs11) - add_test_VSNsightTegra(vs11 "Visual Studio 11 2012") + add_test_VSAndroid(vs11 "Visual Studio 11 2012" "Tegra-Android") endif() if(vs12) - add_test_VSNsightTegra(vs12 "Visual Studio 12 2013") + add_test_VSAndroid(vs12 "Visual Studio 12 2013" "Tegra-Android") endif() if(vs14) - add_test_VSNsightTegra(vs14 "Visual Studio 14 2015") + add_test_VSAndroid(vs14 "Visual Studio 14 2015" "Tegra-Android") endif() endif() + if(vs14 AND CMake_TEST_ANDROID_VS14) + add_test_VSAndroid(vs14 "Visual Studio 14 2015" "ARM") + endif() + if(vs15 AND CMake_TEST_ANDROID_VS15) + add_test_VSAndroid(vs15 "Visual Studio 15 2017" "ARM") + endif() + if(vs16 AND CMake_TEST_ANDROID_VS16) + add_test_VSAndroid(vs16 "Visual Studio 16 2019" "ARM") + endif() if (APPLE) if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") diff --git a/Tests/RunCMake/Android/RunCMakeTest.cmake b/Tests/RunCMake/Android/RunCMakeTest.cmake index 234525a..81dd090 100644 --- a/Tests/RunCMake/Android/RunCMakeTest.cmake +++ b/Tests/RunCMake/Android/RunCMakeTest.cmake @@ -33,12 +33,18 @@ function(run_Android case) endforeach() endfunction() +set(RunCMake_GENERATOR_PLATFORM_OLD "${RunCMake_GENERATOR_PLATFORM}") + +if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(RunCMake_GENERATOR_PLATFORM "ARM") +endif() set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSROOT=${CMAKE_CURRENT_SOURCE_DIR} ) run_cmake(BadSYSROOT) unset(RunCMake_TEST_OPTIONS) +set(RunCMake_GENERATOR_PLATFORM "${RunCMake_GENERATOR_PLATFORM_OLD}") foreach(ndk IN LISTS TEST_ANDROID_NDK) # Load available toolchain versions and abis. @@ -82,6 +88,9 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) if(_versions MATCHES "clang") set(_versions "clang" ${_versions}) endif() + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(_versions "clang") + endif() list(REMOVE_DUPLICATES _versions) list(SORT _versions) set(_versions ";${_versions}") @@ -89,44 +98,58 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) list(REMOVE_DUPLICATES _abis_${vers}) endforeach() + set(ndk_arg -DCMAKE_ANDROID_NDK=${ndk}) + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(ndk_arg) + endif() + # Test failure cases. message(STATUS "ndk='${ndk}'") + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(RunCMake_GENERATOR_PLATFORM "ARM") + endif() set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_ARCH_ABI=badabi ) run_cmake(ndk-badabi) + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(RunCMake_GENERATOR_PLATFORM "x86") + endif() set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_ARM_MODE=0 ) run_cmake(ndk-badarm) + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(RunCMake_GENERATOR_PLATFORM "ARM") + endif() if("armeabi" IN_LIST _abis_) set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_ARM_NEON=0 ) run_cmake(ndk-badneon) endif() set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=badver ) run_cmake(ndk-badver) set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=1.0 ) run_cmake(ndk-badvernum) set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Android - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_STL_TYPE=badstl ) run_cmake(ndk-badstl) @@ -143,6 +166,7 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) run_cmake(ndk-sysroot-armeabi) unset(RunCMake_TEST_OPTIONS) endif() + set(RunCMake_GENERATOR_PLATFORM "${RunCMake_GENERATOR_PLATFORM_OLD}") # Find available STLs. set(stl_types @@ -169,11 +193,18 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) armeabi-v6 armeabi-v7a arm64-v8a - mips - mips64 x86 x86_64 ) + if(NOT RunCMake_GENERATOR MATCHES "Visual Studio") + list(APPEND abi_names mips mips64) + endif() + set(abi_to_arch_armeabi ARM) + set(abi_to_arch_armeabi-v6 ARM) + set(abi_to_arch_armeabi-v7a ARM) + set(abi_to_arch_arm64-v8a ARM64) + set(abi_to_arch_x86 x86) + set(abi_to_arch_x86_64 x64) # Test all combinations. foreach(vers IN LISTS _versions) @@ -193,7 +224,7 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) endif() message(STATUS "ndk='${ndk}' vers='${vers}' stl='${stl}'${config_status}") set(RunCMake_TEST_OPTIONS - -DCMAKE_ANDROID_NDK=${ndk} + ${ndk_arg} -DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=${vers} -DCMAKE_ANDROID_STL_TYPE=${stl} "${build_type_arg}" @@ -205,6 +236,9 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) endif() # Run the tests for this combination. + if(RunCMake_GENERATOR MATCHES "Visual Studio") + set(RunCMake_GENERATOR_PLATFORM "${abi_to_arch_${abi}}") + endif() if("${abi}" STREQUAL "armeabi") run_Android(ndk-armeabi-thumb) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi -DCMAKE_ANDROID_ARM_MODE=0 run_Android(ndk-armeabi-arm -DCMAKE_ANDROID_ARM_MODE=1) # default: -DCMAKE_ANDROID_ARCH_ABI=armeabi @@ -214,6 +248,7 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK) run_Android(ndk-${abi}-neon -DCMAKE_ANDROID_ARCH_ABI=${abi} -DCMAKE_ANDROID_ARM_NEON=1) endif() endif() + set(RunCMake_GENERATOR_PLATFORM "${RunCMake_GENERATOR_PLATFORM_OLD}") endforeach() unset(RunCMake_TEST_OPTIONS) endforeach() diff --git a/Tests/RunCMake/Android/ndk-arm64-v8a-stderr.txt b/Tests/RunCMake/Android/ndk-arm64-v8a-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-arm64-v8a-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-armeabi-arm-stderr.txt b/Tests/RunCMake/Android/ndk-armeabi-arm-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-armeabi-arm-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-armeabi-thumb-stderr.txt b/Tests/RunCMake/Android/ndk-armeabi-thumb-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-armeabi-thumb-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-armeabi-v7a-neon-stderr.txt b/Tests/RunCMake/Android/ndk-armeabi-v7a-neon-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-armeabi-v7a-neon-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-armeabi-v7a-stderr.txt b/Tests/RunCMake/Android/ndk-armeabi-v7a-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-armeabi-v7a-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-x86-stderr.txt b/Tests/RunCMake/Android/ndk-x86-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-x86-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/Android/ndk-x86_64-stderr.txt b/Tests/RunCMake/Android/ndk-x86_64-stderr.txt new file mode 100644 index 0000000..a3b3634 --- /dev/null +++ b/Tests/RunCMake/Android/ndk-x86_64-stderr.txt @@ -0,0 +1,7 @@ +^(CMake Warning: + You are using Visual Studio tools for Android, which does not support + standalone executables\. However, the following executable targets do not + have the ANDROID_GUI property set, and thus will not be built as expected\. + They will be built as shared libraries with executable filenames: + + android_c, android_cxx, android_sysinc_c, android_sysinc_cxx)?$ diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 6c634b5..192895b 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -683,8 +683,8 @@ add_RunCMake_test(AutoExportDll add_RunCMake_test(AndroidMK) if(CMake_TEST_ANDROID_NDK OR CMake_TEST_ANDROID_STANDALONE_TOOLCHAIN) - if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja") - message(FATAL_ERROR "Android tests supported only by Makefile and Ninja generators") + if(NOT "${CMAKE_GENERATOR}" MATCHES "Make|Ninja|Visual Studio 1[456]") + message(FATAL_ERROR "Android tests supported only by Makefile, Ninja, and Visual Studio >= 14 generators") endif() foreach(v TEST_ANDROID_NDK TEST_ANDROID_STANDALONE_TOOLCHAIN) if(CMake_${v}) diff --git a/Tests/VSAndroid/AndroidManifest.xml b/Tests/VSAndroid/AndroidManifest.xml new file mode 100644 index 0000000..951e8f3 --- /dev/null +++ b/Tests/VSAndroid/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/Tests/VSAndroid/CMakeLists.txt b/Tests/VSAndroid/CMakeLists.txt new file mode 100644 index 0000000..73b1e07 --- /dev/null +++ b/Tests/VSAndroid/CMakeLists.txt @@ -0,0 +1,57 @@ +cmake_minimum_required(VERSION 3.3) +project(VSAndroid C CXX) + +set(CMAKE_ANDROID_ARCH armv7-a) +set(CMAKE_ANDROID_STL_TYPE stlport_shared) +set(CMAKE_ANDROID_API_MIN 9) +set(CMAKE_ANDROID_API 15) +set(CMAKE_ANDROID_GUI 1) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") + +set(FIRST_C_FILES + jni/first.c + jni/first.h + ) + +source_group(jni FILES ${FIRST_C_FILES}) +add_library(twolib-first ${FIRST_C_FILES}) + +set(SECOND_C_FILES + jni/second.c + ) +set(SECOND_JAVA_FILES + src/com/example/twolibs/TwoLibs.java + ) +set(SECOND_RES_FILES + res/values/strings.xml + ) +set(SECOND_ANDROID_FILES + AndroidManifest.xml + ) + +source_group(jni FILES ${SECOND_C_FILES}) +source_group(res\\values FILES ${SECOND_RES_FILES}) +source_group(src\\com\\example\\twolibs FILES ${SECOND_JAVA_FILES}) +add_executable(twolib-second + ${SECOND_C_FILES} + ${SECOND_JAVA_FILES} + ${SECOND_RES_FILES} + ${SECOND_ANDROID_FILES} + ) +target_include_directories(twolib-second PUBLIC jni) +target_link_libraries(twolib-second twolib-first) +target_link_libraries(twolib-second m) # test linking to library by name + +set_property(TARGET twolib-second PROPERTY C_STANDARD 11) +set_target_properties(twolib-second PROPERTIES ANDROID_SKIP_ANT_STEP 1) +set_target_properties(twolib-second PROPERTIES ANDROID_PROGUARD 1) +set_target_properties(twolib-second PROPERTIES ANDROID_PROGUARD_CONFIG_PATH proguard-android.txt) +set_target_properties(twolib-second PROPERTIES ANDROID_SECURE_PROPS_PATH /definitely/insecure) + +set_property(TARGET twolib-second PROPERTY ANDROID_NATIVE_LIB_DIRECTORIES $) +set_property(TARGET twolib-second PROPERTY ANDROID_NATIVE_LIB_DEPENDENCIES $) + +set_property(TARGET twolib-second PROPERTY ANDROID_JAR_DIRECTORIES $) diff --git a/Tests/VSAndroid/build.xml b/Tests/VSAndroid/build.xml new file mode 100644 index 0000000..17a2cc0 --- /dev/null +++ b/Tests/VSAndroid/build.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Tests/VSAndroid/jni/first.c b/Tests/VSAndroid/jni/first.c new file mode 100644 index 0000000..b9dee27 --- /dev/null +++ b/Tests/VSAndroid/jni/first.c @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + * + */ +#include "first.h" + +int first(int x, int y) +{ + return x + y; +} diff --git a/Tests/VSAndroid/jni/first.h b/Tests/VSAndroid/jni/first.h new file mode 100644 index 0000000..9dfd8b8 --- /dev/null +++ b/Tests/VSAndroid/jni/first.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + * + */ +#ifndef FIRST_H +#define FIRST_H + +extern int first(int x, int y); + +#endif /* FIRST_H */ diff --git a/Tests/VSAndroid/jni/second.c b/Tests/VSAndroid/jni/second.c new file mode 100644 index 0000000..30bdc17 --- /dev/null +++ b/Tests/VSAndroid/jni/second.c @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + * + */ +#include + +#include "first.h" + +jint Java_com_example_twolibs_TwoLibs_add(JNIEnv* env, jobject this, jint x, + jint y) +{ + return first(x, y); +} diff --git a/Tests/VSAndroid/proguard-android.txt b/Tests/VSAndroid/proguard-android.txt new file mode 100644 index 0000000..fe73bae --- /dev/null +++ b/Tests/VSAndroid/proguard-android.txt @@ -0,0 +1,57 @@ +# This is a configuration file for ProGuard. +# http://proguard.sourceforge.net/index.html#manual/usage.html + +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-verbose + +# Optimization is turned off by default. Dex does not like code run +# through the ProGuard optimize and preverify steps (and performs some +# of these optimizations on its own). +-dontoptimize +-dontpreverify +# Note that if you want to enable optimization, you cannot just +# include optimization flags in your own project configuration file; +# instead you will need to point to the +# "proguard-android-optimize.txt" file instead of this one from your +# project.properties file. + +-keepattributes *Annotation* +-keep public class com.google.vending.licensing.ILicensingService +-keep public class com.android.vending.licensing.ILicensingService + +# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native +-keepclasseswithmembernames class * { + native ; +} + +# keep setters in Views so that animations can still work. +# see http://proguard.sourceforge.net/manual/examples.html#beans +-keepclassmembers public class * extends android.view.View { + void set*(***); + *** get*(); +} + +# We want to keep methods in Activity that could be used in the XML attribute onClick +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} + +-keepclassmembers class **.R$* { + public static ; +} + +# The support library contains references to newer platform versions. +# Don't warn about those in case this app is linking against an older +# platform version. We know about them, and they are safe. +-dontwarn android.support.** diff --git a/Tests/VSAndroid/res/values/strings.xml b/Tests/VSAndroid/res/values/strings.xml new file mode 100644 index 0000000..858cdb4 --- /dev/null +++ b/Tests/VSAndroid/res/values/strings.xml @@ -0,0 +1,4 @@ + + + TwoLibs + diff --git a/Tests/VSAndroid/src/com/example/twolibs/TwoLibs.java b/Tests/VSAndroid/src/com/example/twolibs/TwoLibs.java new file mode 100644 index 0000000..ef9da01 --- /dev/null +++ b/Tests/VSAndroid/src/com/example/twolibs/TwoLibs.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * 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. + */ +package com.example.twolibs; + +import android.app.Activity; +import android.widget.TextView; +import android.os.Bundle; + +public class TwoLibs extends Activity +{ + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + + TextView tv = new TextView(this); + int x = 1000; + int y = 42; + + // here, we dynamically load the library at runtime + // before calling the native method. + // + System.loadLibrary("twolib-second"); + + int z = add(x, y); + + tv.setText( "The sum of " + x + " and " + y + " is " + z ); + setContentView(tv); + } + + public native int add(int x, int y); +} diff --git a/Tests/VSNsightTegra/AndroidManifest.xml b/Tests/VSNsightTegra/AndroidManifest.xml deleted file mode 100644 index 951e8f3..0000000 --- a/Tests/VSNsightTegra/AndroidManifest.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - diff --git a/Tests/VSNsightTegra/CMakeLists.txt b/Tests/VSNsightTegra/CMakeLists.txt deleted file mode 100644 index 6d74f2f..0000000 --- a/Tests/VSNsightTegra/CMakeLists.txt +++ /dev/null @@ -1,57 +0,0 @@ -cmake_minimum_required(VERSION 3.3) -project(VSNsightTegra C CXX) - -set(CMAKE_ANDROID_ARCH armv7-a) -set(CMAKE_ANDROID_STL_TYPE stlport_shared) -set(CMAKE_ANDROID_API_MIN 9) -set(CMAKE_ANDROID_API 15) -set(CMAKE_ANDROID_GUI 1) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") - -set(FIRST_C_FILES - jni/first.c - jni/first.h - ) - -source_group(jni FILES ${FIRST_C_FILES}) -add_library(twolib-first ${FIRST_C_FILES}) - -set(SECOND_C_FILES - jni/second.c - ) -set(SECOND_JAVA_FILES - src/com/example/twolibs/TwoLibs.java - ) -set(SECOND_RES_FILES - res/values/strings.xml - ) -set(SECOND_ANDROID_FILES - AndroidManifest.xml - ) - -source_group(jni FILES ${SECOND_C_FILES}) -source_group(res\\values FILES ${SECOND_RES_FILES}) -source_group(src\\com\\example\\twolibs FILES ${SECOND_JAVA_FILES}) -add_executable(twolib-second - ${SECOND_C_FILES} - ${SECOND_JAVA_FILES} - ${SECOND_RES_FILES} - ${SECOND_ANDROID_FILES} - ) -target_include_directories(twolib-second PUBLIC jni) -target_link_libraries(twolib-second twolib-first) -target_link_libraries(twolib-second m) # test linking to library by name - -set_property(TARGET twolib-second PROPERTY C_STANDARD 11) -set_target_properties(twolib-second PROPERTIES ANDROID_SKIP_ANT_STEP 1) -set_target_properties(twolib-second PROPERTIES ANDROID_PROGUARD 1) -set_target_properties(twolib-second PROPERTIES ANDROID_PROGUARD_CONFIG_PATH proguard-android.txt) -set_target_properties(twolib-second PROPERTIES ANDROID_SECURE_PROPS_PATH /definitely/insecure) - -set_property(TARGET twolib-second PROPERTY ANDROID_NATIVE_LIB_DIRECTORIES $) -set_property(TARGET twolib-second PROPERTY ANDROID_NATIVE_LIB_DEPENDENCIES $) - -set_property(TARGET twolib-second PROPERTY ANDROID_JAR_DIRECTORIES $) diff --git a/Tests/VSNsightTegra/build.xml b/Tests/VSNsightTegra/build.xml deleted file mode 100644 index 17a2cc0..0000000 --- a/Tests/VSNsightTegra/build.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Tests/VSNsightTegra/jni/first.c b/Tests/VSNsightTegra/jni/first.c deleted file mode 100644 index b9dee27..0000000 --- a/Tests/VSNsightTegra/jni/first.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - * - */ -#include "first.h" - -int first(int x, int y) -{ - return x + y; -} diff --git a/Tests/VSNsightTegra/jni/first.h b/Tests/VSNsightTegra/jni/first.h deleted file mode 100644 index 9dfd8b8..0000000 --- a/Tests/VSNsightTegra/jni/first.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - * - */ -#ifndef FIRST_H -#define FIRST_H - -extern int first(int x, int y); - -#endif /* FIRST_H */ diff --git a/Tests/VSNsightTegra/jni/second.c b/Tests/VSNsightTegra/jni/second.c deleted file mode 100644 index 30bdc17..0000000 --- a/Tests/VSNsightTegra/jni/second.c +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - * - */ -#include - -#include "first.h" - -jint Java_com_example_twolibs_TwoLibs_add(JNIEnv* env, jobject this, jint x, - jint y) -{ - return first(x, y); -} diff --git a/Tests/VSNsightTegra/proguard-android.txt b/Tests/VSNsightTegra/proguard-android.txt deleted file mode 100644 index fe73bae..0000000 --- a/Tests/VSNsightTegra/proguard-android.txt +++ /dev/null @@ -1,57 +0,0 @@ -# This is a configuration file for ProGuard. -# http://proguard.sourceforge.net/index.html#manual/usage.html - --dontusemixedcaseclassnames --dontskipnonpubliclibraryclasses --verbose - -# Optimization is turned off by default. Dex does not like code run -# through the ProGuard optimize and preverify steps (and performs some -# of these optimizations on its own). --dontoptimize --dontpreverify -# Note that if you want to enable optimization, you cannot just -# include optimization flags in your own project configuration file; -# instead you will need to point to the -# "proguard-android-optimize.txt" file instead of this one from your -# project.properties file. - --keepattributes *Annotation* --keep public class com.google.vending.licensing.ILicensingService --keep public class com.android.vending.licensing.ILicensingService - -# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native --keepclasseswithmembernames class * { - native ; -} - -# keep setters in Views so that animations can still work. -# see http://proguard.sourceforge.net/manual/examples.html#beans --keepclassmembers public class * extends android.view.View { - void set*(***); - *** get*(); -} - -# We want to keep methods in Activity that could be used in the XML attribute onClick --keepclassmembers class * extends android.app.Activity { - public void *(android.view.View); -} - -# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - --keep class * implements android.os.Parcelable { - public static final android.os.Parcelable$Creator *; -} - --keepclassmembers class **.R$* { - public static ; -} - -# The support library contains references to newer platform versions. -# Don't warn about those in case this app is linking against an older -# platform version. We know about them, and they are safe. --dontwarn android.support.** diff --git a/Tests/VSNsightTegra/res/values/strings.xml b/Tests/VSNsightTegra/res/values/strings.xml deleted file mode 100644 index 858cdb4..0000000 --- a/Tests/VSNsightTegra/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - TwoLibs - diff --git a/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java b/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java deleted file mode 100644 index ef9da01..0000000 --- a/Tests/VSNsightTegra/src/com/example/twolibs/TwoLibs.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * 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. - */ -package com.example.twolibs; - -import android.app.Activity; -import android.widget.TextView; -import android.os.Bundle; - -public class TwoLibs extends Activity -{ - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - TextView tv = new TextView(this); - int x = 1000; - int y = 42; - - // here, we dynamically load the library at runtime - // before calling the native method. - // - System.loadLibrary("twolib-second"); - - int z = add(x, y); - - tv.setText( "The sum of " + x + " and " + y + " is " + z ); - setContentView(tv); - } - - public native int add(int x, int y); -} -- cgit v0.12