VS: Add variables to set SDK directories in vcxproj files

Create `CMAKE_VS_SDK_*_DIRECTORIES` variables to tell the VS generator
how to populate fields in `.vcxproj` files that specify SDK directories.

Fixes: #17908
This commit is contained in:
Bastien Schatt
2018-04-15 22:14:52 +02:00
committed by Brad King
parent 4984d8433e
commit 6ec3e880e7
13 changed files with 200 additions and 0 deletions

View File

@@ -369,6 +369,13 @@ Variables that Control the Build
/variable/CMAKE_VISIBILITY_INLINES_HIDDEN
/variable/CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD
/variable/CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD
/variable/CMAKE_VS_SDK_EXCLUDE_DIRECTORIES
/variable/CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES
/variable/CMAKE_VS_SDK_INCLUDE_DIRECTORIES
/variable/CMAKE_VS_SDK_LIBRARY_DIRECTORIES
/variable/CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES
/variable/CMAKE_VS_SDK_REFERENCE_DIRECTORIES
/variable/CMAKE_VS_SDK_SOURCE_DIRECTORIES
/variable/CMAKE_WIN32_EXECUTABLE
/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute

View File

@@ -0,0 +1,15 @@
vs-sdk-dirs
-----------
* ``CMAKE_VS_SDK_*_DIRECTORIES`` variables were defined to tell
:ref:`Visual Studio Generators` for VS 2010 and above how to populate
fields in ``.vcxproj`` files that specify SDK directories. The
variables are:
- :variable:`CMAKE_VS_SDK_EXCLUDE_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_INCLUDE_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_LIBRARY_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_REFERENCE_DIRECTORIES`
- :variable:`CMAKE_VS_SDK_SOURCE_DIRECTORIES`

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_EXCLUDE_DIRECTORIES
--------------------------------
This variable allows to override Visual Studio default Exclude Directories.

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES
-----------------------------------
This variable allows to override Visual Studio default Executable Directories.

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_INCLUDE_DIRECTORIES
--------------------------------
This variable allows to override Visual Studio default Include Directories.

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_LIBRARY_DIRECTORIES
--------------------------------
This variable allows to override Visual Studio default Library Directories.

View File

@@ -0,0 +1,5 @@
CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES
--------------------------------------
This variable allows to override Visual Studio default Library WinRT
Directories.

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_REFERENCE_DIRECTORIES
----------------------------------
This variable allows to override Visual Studio default Reference Directories.

View File

@@ -0,0 +1,4 @@
CMAKE_VS_SDK_SOURCE_DIRECTORIES
-------------------------------
This variable allows to override Visual Studio default Source Directories.

View File

@@ -2235,6 +2235,55 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
*this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
<< "</IntDir>\n";
if (const char* sdkExecutableDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
this->WritePlatformConfigTag("ExecutablePath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkExecutableDirectories)
<< "</ExecutablePath>\n";
}
if (const char* sdkIncludeDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
this->WritePlatformConfigTag("IncludePath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkIncludeDirectories)
<< "</IncludePath>\n";
}
if (const char* sdkReferenceDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
this->WritePlatformConfigTag("ReferencePath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkReferenceDirectories)
<< "</ReferencePath>\n";
}
if (const char* sdkLibraryDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
this->WritePlatformConfigTag("LibraryPath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkLibraryDirectories)
<< "</LibraryPath>\n";
}
if (const char* sdkLibraryWDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
this->WritePlatformConfigTag("LibraryWPath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkLibraryWDirectories)
<< "</LibraryWPath>\n";
}
if (const char* sdkSourceDirectories =
this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
this->WritePlatformConfigTag("SourcePath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkSourceDirectories)
<< "</SourcePath>\n";
}
if (const char* sdkExcludeDirectories = this->Makefile->GetDefinition(
"CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
this->WritePlatformConfigTag("ExcludePath", config, 2);
*this->BuildFileStream << cmVS10EscapeXML(sdkExcludeDirectories)
<< "</ExcludePath>\n";
}
if (const char* workingDir = this->GeneratorTarget->GetProperty(
"VS_DEBUGGER_WORKING_DIRECTORY")) {
this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory", config,

View File

@@ -7,3 +7,4 @@ run_cmake(VsDebuggerCommand)
run_cmake(VsCSharpCustomTags)
run_cmake(VsCSharpReferenceProps)
run_cmake(VsCSharpWithoutSources)
run_cmake(VsSdkDirectories)

View File

@@ -0,0 +1,88 @@
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
return()
endif()
set(ExecutablePathSet FALSE)
set(IncludePathSet FALSE)
set(ReferencePathSet FALSE)
set(LibraryPathSet FALSE)
set(LibraryWPathSet FALSE)
set(SourcePathSet FALSE)
set(ExcludePathSet FALSE)
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "^ *<ExecutablePath[^>]*>([^<>]+)</ExecutablePath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_ExecutablePath_x86);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has executable path set")
set(ExecutablePathSet TRUE)
endif()
elseif(line MATCHES "^ *<IncludePath[^>]*>([^<>]+)</IncludePath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_IncludePath);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has include path set")
set(IncludePathSet TRUE)
endif()
elseif(line MATCHES "^ *<ReferencePath[^>]*>([^<>]+)</ReferencePath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_ReferencesPath_x86);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has reference path set")
set(ReferencePathSet TRUE)
endif()
elseif(line MATCHES "^ *<LibraryPath[^>]*>([^<>]+)</LibraryPath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_LibraryPath_x86);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has library path set")
set(LibraryPathSet TRUE)
endif()
elseif(line MATCHES "^ *<LibraryWPath[^>]*>([^<>]+)</LibraryWPath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(WindowsSDK_MetadataPath);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has library WinRT path set")
set(LibraryWPathSet TRUE)
endif()
elseif(line MATCHES "^ *<SourcePath[^>]*>([^<>]+)</SourcePath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_SourcePath);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has source path set")
set(SourcePathSet TRUE)
endif()
elseif(line MATCHES "^ *<ExcludePath[^>]*>([^<>]+)</ExcludePath>$")
if("${CMAKE_MATCH_1}" STREQUAL "$(VC_IncludePath);C:\\Program Files\\Custom-SDK\\;")
message(STATUS "foo.vcxproj has exclude path set")
set(ExcludePathSet TRUE)
endif()
endif()
endforeach()
if(NOT ExecutablePathSet)
set(RunCMake_TEST_FAILED "ExecutablePath not found or not set correctly.")
return()
endif()
if(NOT IncludePathSet)
set(RunCMake_TEST_FAILED "IncludePath not found or not set correctly.")
return()
endif()
if(NOT ReferencePathSet)
set(RunCMake_TEST_FAILED "ReferencePath not found or not set correctly.")
return()
endif()
if(NOT LibraryPathSet)
set(RunCMake_TEST_FAILED "LibraryPath not found or not set correctly.")
return()
endif()
if(NOT LibraryWPathSet)
set(RunCMake_TEST_FAILED "LibraryWPath not found or not set correctly.")
return()
endif()
if(NOT SourcePathSet)
set(RunCMake_TEST_FAILED "SourcePath not found or not set correctly.")
return()
endif()
if(NOT ExcludePathSet)
set(RunCMake_TEST_FAILED "ExcludePath not found or not set correctly.")
return()
endif()

View File

@@ -0,0 +1,11 @@
enable_language(CXX)
set(CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES "$(VC_ExecutablePath_x86);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_INCLUDE_DIRECTORIES "$(VC_IncludePath);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_REFERENCE_DIRECTORIES "$(VC_ReferencesPath_x86);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_LIBRARY_DIRECTORIES "$(VC_LibraryPath_x86);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES "$(WindowsSDK_MetadataPath);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_SOURCE_DIRECTORIES "$(VC_SourcePath);C:\\Program Files\\Custom-SDK\\;")
set(CMAKE_VS_SDK_EXCLUDE_DIRECTORIES "$(VC_IncludePath);C:\\Program Files\\Custom-SDK\\;")
add_library(foo foo.cpp)