Merge topic 'vs-nsight-tegra-generator'

df84281d Help: Add notes for topic 'vs-nsight-tegra-generator'
69e198dc VS: Generate Nsight Tegra project revision number
5365c9ac VS: Map Nsight Tegra file types in .vcxproj files
178f56a5 VS: Fix Tegra-Android platform linking of libraries by name
7115702f Tests: Add test for VS Nsight Tegra generator support
a6289499 VS: Generate ANDROID_GUI executables as app packages
c12e4699 Add 'ANDROID_API' target property to set Android Target API
9a4df52a Add 'ANDROID_GUI' target property to mark Android applications
16569abf cmTarget: Track internally whether platform is Android
ef0fd4f0 VS: Teach vcxproj generation about the Tegra-Android platform
d09b60f5 VS: Detect compiler id of Nsight Tegra-Android toolchains
2f071466 VS: Teach VS >= 10 to recognize CMAKE_SYSTEM_NAME 'Android'
This commit is contained in:
Brad King 2014-09-30 08:46:27 -04:00 committed by CMake Topic Stage
commit 34d035e70e
27 changed files with 567 additions and 11 deletions

View File

@ -79,6 +79,8 @@ Properties on Targets
:maxdepth: 1
/prop_tgt/ALIASED_TARGET
/prop_tgt/ANDROID_API
/prop_tgt/ANDROID_GUI
/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY_CONFIG
/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY
/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG

View File

@ -74,6 +74,7 @@ Variables that Provide Information
/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
/variable/CMAKE_VS_MSBUILD_COMMAND
/variable/CMAKE_VS_MSDEV_COMMAND
/variable/CMAKE_VS_NsightTegra_VERSION
/variable/CMAKE_VS_PLATFORM_NAME
/variable/CMAKE_VS_PLATFORM_TOOLSET
/variable/CMAKE_XCODE_PLATFORM_TOOLSET
@ -203,6 +204,8 @@ Variables that Control the Build
.. toctree::
:maxdepth: 1
/variable/CMAKE_ANDROID_API
/variable/CMAKE_ANDROID_GUI
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY
/variable/CMAKE_AUTOMOC_MOC_OPTIONS
/variable/CMAKE_AUTOMOC

View File

@ -0,0 +1,7 @@
ANDROID_API
-----------
Set the Android Target API version (e.g. ``15``). The version number
must be a positive decimal integer. This property is initialized by
the value of the :variable:`CMAKE_ANDROID_API` variable if it is set
when a target is created.

View File

@ -0,0 +1,9 @@
ANDROID_GUI
-----------
Build an executable as an application package on Android.
When this property is set to true the executable when built for Android
will be created as an application package. This property is initialized
by the value of the :variable:`CMAKE_ANDROID_GUI` variable if it is set
when a target is created.

View File

@ -0,0 +1,8 @@
vs-nsight-tegra-generator
-------------------------
* Generators for Visual Studio 10 (2010) and above learned to generate
projects for NVIDIA Nsight Tegra Visual Studio Edition. One may set
the :variable:`CMAKE_SYSTEM_NAME` variable to ``Android`` on the
:manual:`cmake(1)` command-line or in a :variable:`CMAKE_TOOLCHAIN_FILE`
to activate this platform.

View File

@ -0,0 +1,5 @@
CMAKE_ANDROID_API
-----------------
Default value for the :prop_tgt:`ANDROID_API` target property.
See that target property for additional information.

View File

@ -0,0 +1,5 @@
CMAKE_ANDROID_GUI
-----------------
Default value for the :prop_tgt:`ANDROID_GUI` target property of
executables. See that target property for additional information.

View File

@ -0,0 +1,7 @@
CMAKE_VS_NsightTegra_VERSION
----------------------------
When using a Visual Studio generator with the
:variable:`CMAKE_SYSTEM_NAME` variable set to ``Android``,
this variable contains the version number of the
installed NVIDIA Nsight Tegra Visual Studio Edition.

View File

@ -142,7 +142,17 @@ Id flags: ${testflags}
set(id_platform ${CMAKE_VS_PLATFORM_NAME})
set(id_lang "${lang}")
set(id_cl cl.exe)
if(lang STREQUAL Fortran)
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
set(v NsightTegra)
set(ext vcxproj)
if(lang STREQUAL CXX)
set(id_gcc g++)
set(id_clang clang++)
else()
set(id_gcc gcc)
set(id_clang clang)
endif()
elseif(lang STREQUAL Fortran)
set(v Intel)
set(ext vfproj)
set(id_cl ifort.exe)
@ -161,9 +171,13 @@ Id flags: ${testflags}
set(id_platform ia64)
endif()
if(CMAKE_VS_PLATFORM_TOOLSET)
set(id_toolset "<PlatformToolset>${CMAKE_VS_PLATFORM_TOOLSET}</PlatformToolset>")
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "Intel")
set(id_cl icl.exe)
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
set(id_toolset "<NdkToolchainVersion>${CMAKE_VS_PLATFORM_TOOLSET}</NdkToolchainVersion>")
else()
set(id_toolset "<PlatformToolset>${CMAKE_VS_PLATFORM_TOOLSET}</PlatformToolset>")
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "Intel")
set(id_cl icl.exe)
endif()
endif()
else()
set(id_toolset "")

View File

@ -35,7 +35,8 @@ if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"
OR "${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "MSVC"
OR "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"
OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC"
OR "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
OR ("${CMAKE_GENERATOR}" MATCHES "Visual Studio"
AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="NsightTegraProject">
<NsightTegraProjectRevisionNumber>6</NsightTegraProjectRevisionNumber>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|@id_platform@">
<Configuration>Debug</Configuration>
<Platform>@id_platform@</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
<RootNamespace>CompilerId@id_lang@</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
@id_toolset@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">.\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'">
<ClCompile>
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
</Link>
<PostBuildEvent>
<Command>
if "$(ToolchainName)"=="gcc" (
for %%i in ($(ToolchainPrebuiltRoot)\bin\*@id_gcc@.exe) do (
@echo CMAKE_@id_lang@_COMPILER=%%i
goto :done
)
)
if "$(ToolchainName)"=="clang" (
for %%i in ($(ToolchainPrebuiltRoot)\bin\*@id_clang@.exe) do (
@echo CMAKE_@id_lang@_COMPILER=%%i
goto :done
)
)
:done
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="@id_src@" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@ -7,3 +7,9 @@ set(CMAKE_PLATFORM_NO_VERSIONED_SONAME 1)
# Android reportedly ignores RPATH, and we cannot predict the install
# location anyway.
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")
# Nsight Tegra Visual Studio Edition takes care of
# prefixing library names with '-l'.
if(CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android")
set(CMAKE_LINK_LIBRARY_FLAG "")
endif()

View File

@ -198,6 +198,31 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
return false;
}
}
else if(this->SystemName == "Android")
{
if(this->DefaultPlatformName != "Win32")
{
cmOStringStream e;
e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR "
<< "specifies a platform too: '" << this->GetName() << "'";
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
return false;
}
std::string v = this->GetInstalledNsightTegraVersion();
if(v.empty())
{
mf->IssueMessage(cmake::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.c_str());
}
return true;
}
@ -587,3 +612,25 @@ bool cmGlobalVisualStudio10Generator::UseFolderProperty()
{
return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty();
}
//----------------------------------------------------------------------------
bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
{
return !this->NsightTegraVersion.empty();
}
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio10Generator::GetNsightTegraVersion() const
{
return this->NsightTegraVersion;
}
//----------------------------------------------------------------------------
std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
{
std::string version;
cmSystemTools::ReadRegistryValue(
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;"
"Version", version, cmSystemTools::KeyWOW64_32);
return version;
}

View File

@ -59,6 +59,10 @@ public:
/** Is the installed VS an Express edition? */
bool IsExpressEdition() const { return this->ExpressEdition; }
/** Generating for Nsight Tegra VS plugin? */
bool IsNsightTegra() const;
std::string GetNsightTegraVersion() const;
/** The toolset name for the target platform. */
const char* GetPlatformToolset() const;
@ -106,6 +110,8 @@ public:
virtual void FindMakeProgram(cmMakefile*);
static std::string GetInstalledNsightTegraVersion();
protected:
virtual void Generate();
virtual bool InitializeSystem(cmMakefile* mf);
@ -124,6 +130,7 @@ protected:
std::string DefaultPlatformToolset;
std::string SystemName;
std::string SystemVersion;
std::string NsightTegraVersion;
bool SystemIsWindowsCE;
bool SystemIsWindowsPhone;
bool SystemIsWindowsStore;

View File

@ -257,6 +257,7 @@ cmTarget::cmTarget()
#endif
this->HaveInstallRule = false;
this->DLLPlatform = false;
this->IsAndroid = false;
this->IsApple = false;
this->IsImportedTarget = false;
this->BuildInterfaceIncludesAppended = false;
@ -312,12 +313,18 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->Makefile->IsOn("CYGWIN") ||
this->Makefile->IsOn("MINGW"));
// Check whether we are targeting an Android platform.
this->IsAndroid =
strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
"Android") == 0;
// Check whether we are targeting an Apple platform.
this->IsApple = this->Makefile->IsOn("APPLE");
// Setup default property values.
if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
{
this->SetPropertyDefault("ANDROID_API", 0);
this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
this->SetPropertyDefault("INSTALL_RPATH", "");
this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
@ -440,6 +447,10 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
}
if(this->TargetTypeValue == cmTarget::EXECUTABLE)
{
this->SetPropertyDefault("ANDROID_GUI", 0);
}
if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
|| this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
{
@ -3493,7 +3504,10 @@ const char* cmTarget::GetSuffixVariableInternal(bool implib) const
case cmTarget::EXECUTABLE:
return (implib
? "CMAKE_IMPORT_LIBRARY_SUFFIX"
: "CMAKE_EXECUTABLE_SUFFIX");
// Android GUI application packages store the native
// binary as a shared library.
: (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
"CMAKE_SHARED_LIBRARY_SUFFIX" : "CMAKE_EXECUTABLE_SUFFIX"));
default:
break;
}
@ -3517,7 +3531,12 @@ const char* cmTarget::GetPrefixVariableInternal(bool implib) const
? "CMAKE_IMPORT_LIBRARY_PREFIX"
: "CMAKE_SHARED_MODULE_PREFIX");
case cmTarget::EXECUTABLE:
return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
return (implib
? "CMAKE_IMPORT_LIBRARY_PREFIX"
// Android GUI application packages store the native
// binary as a shared library.
: (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")?
"CMAKE_SHARED_LIBRARY_PREFIX" : ""));
default:
break;
}

View File

@ -755,6 +755,7 @@ private:
mutable cmPropertyMap Properties;
LinkLibraryVectorType OriginalLinkLibraries;
bool DLLPlatform;
bool IsAndroid;
bool IsApple;
bool IsImportedTarget;
mutable bool DebugIncludesDone;

View File

@ -180,7 +180,16 @@ cmVisualStudio10TargetGenerator(cmTarget* target,
this->GlobalGenerator->CreateGUID(this->Name.c_str());
this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
this->Platform = gg->GetPlatformName();
this->MSTools = true;
this->NsightTegra = gg->IsNsightTegra();
for(int i =
sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u",
&this->NsightTegraVersion[0], &this->NsightTegraVersion[1],
&this->NsightTegraVersion[2], &this->NsightTegraVersion[3]);
i < 4; ++i)
{
this->NsightTegraVersion[i] = 0;
}
this->MSTools = !this->NsightTegra;
this->TargetCompileAsWinRT = false;
this->BuildFileStream = 0;
this->IsMissingFiles = false;
@ -312,6 +321,30 @@ void cmVisualStudio10TargetGenerator::Generate()
"xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n");
this->WriteString(project_defaults.c_str(),0);
if(this->NsightTegra)
{
this->WriteString("<PropertyGroup Label=\"NsightTegraProject\">\n", 1);
if(this->NsightTegraVersion[0] >= 2)
{
// Nsight Tegra 2.0 uses project revision 8.
this->WriteString("<NsightTegraProjectRevisionNumber>"
"8"
"</NsightTegraProjectRevisionNumber>\n", 2);
// Tell newer versions to upgrade silently when loading.
this->WriteString("<NsightTegraUpgradeOnceWithoutPrompt>"
"true"
"</NsightTegraUpgradeOnceWithoutPrompt>\n", 2);
}
else
{
// Require Nsight Tegra 1.6 for JCompile support.
this->WriteString("<NsightTegraProjectRevisionNumber>"
"7"
"</NsightTegraProjectRevisionNumber>\n", 2);
}
this->WriteString("</PropertyGroup>\n", 1);
}
this->WriteProjectConfigurations();
this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
this->WriteString("<ProjectGUID>", 2);
@ -605,11 +638,28 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
configType += "StaticLibrary";
break;
case cmTarget::EXECUTABLE:
configType += "Application";
if(this->NsightTegra &&
!this->Target->GetPropertyAsBool("ANDROID_GUI"))
{
// Android executables are .so too.
configType += "DynamicLibrary";
}
else
{
configType += "Application";
}
break;
case cmTarget::UTILITY:
case cmTarget::GLOBAL_TARGET:
configType += "Utility";
if(this->NsightTegra)
{
// Tegra-Android platform does not understand "Utility".
configType += "StaticLibrary";
}
else
{
configType += "Utility";
}
break;
case cmTarget::UNKNOWN_LIBRARY:
case cmTarget::INTERFACE_LIBRARY:
@ -622,6 +672,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
{
this->WriteMSToolConfigurationValues(*i);
}
else if(this->NsightTegra)
{
this->WriteNsightTegraConfigurationValues(*i);
}
this->WriteString("</PropertyGroup>\n", 1);
}
@ -683,6 +737,25 @@ void cmVisualStudio10TargetGenerator
}
}
//----------------------------------------------------------------------------
void cmVisualStudio10TargetGenerator
::WriteNsightTegraConfigurationValues(std::string const&)
{
cmGlobalVisualStudio10Generator* gg =
static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
const char* toolset = gg->GetPlatformToolset();
std::string ntv = "<NdkToolchainVersion>";
ntv += toolset? toolset : "Default";
ntv += "</NdkToolchainVersion>\n";
this->WriteString(ntv.c_str(), 2);
if(const char* api = this->Target->GetProperty("ANDROID_API"))
{
this->WriteString("<AndroidTargetAPI>", 2);
(*this->BuildFileStream ) <<
"android-" << cmVS10EscapeXML(api) << "</AndroidTargetAPI>\n";
}
}
void cmVisualStudio10TargetGenerator::WriteCustomCommands()
{
this->SourcesVisited.clear();
@ -1150,6 +1223,28 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
{
tool = "XML";
}
if(this->NsightTegra)
{
// Nsight Tegra needs specific file types to check up-to-dateness.
std::string name =
cmSystemTools::LowerCase(sf->GetLocation().GetName());
if(name == "androidmanifest.xml" ||
name == "build.xml" ||
name == "proguard.cfg" ||
name == "proguard-project.txt" ||
ext == "properties")
{
tool = "AndroidBuild";
}
else if(ext == "java")
{
tool = "JCompile";
}
else if(ext == "asm" || ext == "s")
{
tool = "ClCompile";
}
}
std::string deployContent;
if(this->GlobalGenerator->TargetsWindowsPhone() ||
@ -1974,6 +2069,50 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
}
}
//----------------------------------------------------------------------------
void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
std::string const&)
{
// Look through the sources for AndroidManifest.xml and use
// its location as the root source directory.
std::string rootDir = this->Makefile->GetCurrentDirectory();
{
std::vector<cmSourceFile const*> extraSources;
this->GeneratorTarget->GetExtraSources(extraSources, "");
for(std::vector<cmSourceFile const*>::const_iterator si =
extraSources.begin(); si != extraSources.end(); ++si)
{
if("androidmanifest.xml" == cmSystemTools::LowerCase(
(*si)->GetLocation().GetName()))
{
rootDir = (*si)->GetLocation().GetDirectory();
break;
}
}
}
// Tell MSBuild to launch Ant.
{
std::string antBuildPath = rootDir;
this->WriteString("<AntBuild>\n", 2);
this->WriteString("<AntBuildPath>", 3);
this->ConvertToWindowsSlash(antBuildPath);
(*this->BuildFileStream) <<
cmVS10EscapeXML(antBuildPath) << "</AntBuildPath>\n";
}
{
std::string manifest_xml = rootDir + "/AndroidManifest.xml";
this->ConvertToWindowsSlash(manifest_xml);
this->WriteString("<AndroidManifestLocation>", 3);
(*this->BuildFileStream) <<
cmVS10EscapeXML(manifest_xml) << "</AndroidManifestLocation>\n";
}
this->WriteString("</AntBuild>\n", 2);
}
//----------------------------------------------------------------------------
bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
{
@ -2198,6 +2337,10 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config)
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
}
}
else if(this->NsightTegra)
{
linkOptions.AddFlag("SoName", targetNameSO.c_str());
}
linkOptions.Parse(flags.c_str());
@ -2347,6 +2490,12 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
this->WriteLinkOptions(*i);
// output lib flags <Lib></Lib>
this->WriteLibOptions(*i);
if(this->NsightTegra &&
this->Target->GetType() == cmTarget::EXECUTABLE &&
this->Target->GetPropertyAsBool("ANDROID_GUI"))
{
this->WriteAntBuildOptions(*i);
}
this->WriteString("</ItemDefinitionGroup>\n", 1);
}
}

View File

@ -59,6 +59,7 @@ private:
void WriteMSToolConfigurationValues(std::string const& config);
void WriteHeaderSource(cmSourceFile const* sf);
void WriteExtraSource(cmSourceFile const* sf);
void WriteNsightTegraConfigurationValues(std::string const& config);
void WriteSource(std::string const& tool, cmSourceFile const* sf,
const char* end = 0);
void WriteSources(std::string const& tool,
@ -96,6 +97,7 @@ private:
void WriteLinkOptions(std::string const& config);
void WriteMidlOptions(std::string const& config,
std::vector<std::string> const & includes);
void WriteAntBuildOptions(std::string const& config);
void OutputLinkIncremental(std::string const& configName);
void WriteCustomRule(cmSourceFile const* source,
cmCustomCommand const & command);
@ -139,6 +141,8 @@ private:
std::string GUID;
std::string Name;
bool MSTools;
bool NsightTegra;
int NsightTegraVersion[4];
bool TargetCompileAsWinRT;
cmGlobalVisualStudio10Generator* GlobalGenerator;
cmGeneratedFileStream* BuildFileStream;

View File

@ -1781,13 +1781,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
if(WIN32)
set(reg_vs10 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0;InstallDir]")
set(reg_vs11 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\11.0;InstallDir]")
set(reg_vs12 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\12.0;InstallDir]")
set(reg_ws80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.0;InstallationFolder]")
set(reg_ws81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v8.1;InstallationFolder]")
set(reg_wp80 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.0;InstallationFolder]")
set(reg_wp81 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\WindowsPhone\\v8.1;InstallationFolder]")
foreach(reg vs11 vs12 ws80 ws81 wp80 wp81)
set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
foreach(reg vs10 vs11 vs12 ws80 ws81 wp80 wp81 tegra)
get_filename_component(r "${reg_${reg}}" ABSOLUTE)
if(IS_DIRECTORY "${r}")
set(${reg} 1)
@ -1833,6 +1835,30 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
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 $<CONFIGURATION>
--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")
endif()
if(vs11)
add_test_VSNsightTegra(vs11 "Visual Studio 11 2012")
endif()
if(vs12)
add_test_VSNsightTegra(vs12 "Visual Studio 12 2013")
endif()
endif()
if (APPLE)
if (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(BundleTestInstallDir

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.twolibs"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:label="@string/app_name">
<activity android:name=".TwoLibs"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.0)
project(VSNsightTegra C CXX)
set(CMAKE_ANDROID_API 15)
set(CMAKE_ANDROID_GUI 1)
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

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="TwoLibs" default="help">
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -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;
}

View File

@ -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 */

View File

@ -0,0 +1,27 @@
/*
* 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"
#include <jni.h>
jint
Java_com_example_twolibs_TwoLibs_add( JNIEnv* env,
jobject this,
jint x,
jint y )
{
return first(x, y);
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TwoLibs</string>
</resources>

View File

@ -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);
}