summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorKyle Edwards <kyle.edwards@kitware.com>2020-06-12 15:11:04 -0400
committerBrad King <brad.king@kitware.com>2020-06-24 08:41:09 -0400
commit6051a49c78a36b82e77a62e09f0ba5a5b5d14532 (patch)
treeee9c31b9a8f5530bd0fa4a0c76ded239325f3c45 /Modules
parentbbcaf9689ea76d8deba13870dfc63f0654348b5a (diff)
downloadcmake-6051a49c78a36b82e77a62e09f0ba5a5b5d14532.tar.gz
Visual Studio: Add Android support
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake29
-rw-r--r--Modules/CompilerId/VS-10.vcxproj.in4
-rw-r--r--Modules/Platform/Android-Clang.cmake3
-rw-r--r--Modules/Platform/Android-Determine.cmake61
-rw-r--r--Modules/Platform/Android-Initialize.cmake2
-rw-r--r--Modules/Platform/Android/VCXProjInspect.vcxproj.in38
6 files changed, 128 insertions, 9 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index df48fa574f..ebfd5a48f6 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 "<ApplicationType>Windows Phone</ApplicationType>")
elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
+ set(id_keyword "Win32Proj")
set(id_system "<ApplicationType>Windows Store</ApplicationType>")
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
+ set(id_keyword "Android")
+ set(id_system "<ApplicationType>Android</ApplicationType>")
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 "<ApplicationTypeRevision>2.0</ApplicationTypeRevision>")
+ elseif(CMAKE_GENERATOR MATCHES "Visual Studio 1[56]")
+ set(id_system_version "<ApplicationTypeRevision>3.0</ApplicationTypeRevision>")
+ else()
+ set(id_system_version "")
+ endif()
+ elseif(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)")
set(id_system_version "<ApplicationTypeRevision>${CMAKE_MATCH_1}</ApplicationTypeRevision>")
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 "<WindowsTargetPlatformVersion>${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}</WindowsTargetPlatformVersion>")
endif()
@@ -333,9 +352,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
string(APPEND id_CustomGlobals "<${CMAKE_MATCH_1}>${CMAKE_MATCH_2}</${CMAKE_MATCH_1}>\n ")
endif()
endforeach()
- if(id_platform STREQUAL ARM64)
+ if(id_keyword STREQUAL "Android")
+ set(id_WindowsSDKDesktopARMSupport "")
+ elseif(id_platform STREQUAL "ARM64")
set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>")
- elseif(id_platform STREQUAL ARM)
+ elseif(id_platform STREQUAL "ARM")
set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>")
else()
set(id_WindowsSDKDesktopARMSupport "")
diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in
index b48a3323f9..3598fc7e20 100644
--- a/Modules/CompilerId/VS-10.vcxproj.in
+++ b/Modules/CompilerId/VS-10.vcxproj.in
@@ -9,7 +9,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{CAE07175-D007-4FC3-BFE8-47B392814159}</ProjectGuid>
<RootNamespace>CompilerId@id_lang@</RootNamespace>
- <Keyword>Win32Proj</Keyword>
+ <Keyword>@id_keyword@</Keyword>
@id_system@
@id_system_version@
@id_WindowsTargetPlatformVersion@
@@ -24,7 +24,7 @@
@id_PreferredToolArchitecture@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@id_platform@'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
+ <ConfigurationType>@id_config_type@</ConfigurationType>
@id_toolset@
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake
index 759448b8ec..160eadae01 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 2225897fab..11a050425a 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 b90dd7a569..5019c28bdc 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 0000000000..6919d2cd85
--- /dev/null
+++ b/Modules/Platform/Android/VCXProjInspect.vcxproj.in
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|@vcx_platform@">
+ <Configuration>Debug</Configuration>
+ <Platform>@vcx_platform@</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{14D44772-ECF7-47BD-9E29-BC62FAF940A5}</ProjectGuid>
+ <RootNamespace>VCXProjInspect</RootNamespace>
+ <Keyword>Android</Keyword>
+ <ApplicationType>Android</ApplicationType>
+ <ApplicationTypeRevision>@vcx_revision@</ApplicationTypeRevision>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|@vcx_platform@'">
+ <PostBuildEvent>
+ <Command>%40echo CMAKE_SYSROOT=$(@vcx_sysroot_var@)</Command>
+ </PostBuildEvent>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>