summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-12-08 13:03:04 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-12-08 13:03:20 (GMT)
commit986fce1fa7c1ec53871eeda5bcabdedab5427bd1 (patch)
tree61406b7982e0d20ef1b97731e311fb4c6df692f1
parent239beca1e3743ec693643869621cd0e41ed10a16 (diff)
parent5ce0f03cce95fc78af766ca3e54bbab392cbb0d5 (diff)
downloadCMake-986fce1fa7c1ec53871eeda5bcabdedab5427bd1.zip
CMake-986fce1fa7c1ec53871eeda5bcabdedab5427bd1.tar.gz
CMake-986fce1fa7c1ec53871eeda5bcabdedab5427bd1.tar.bz2
Merge topic 'vs-version-var'
5ce0f03cce VS: Add a variable to report the Visual Studio version build number 55529c5e93 Help: Factor out VS Build Number components document fragment Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8000
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/release/dev/vs-version-var.rst6
-rw-r--r--Help/variable/CMAKE_GENERATOR_INSTANCE.rst21
-rw-r--r--Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER.rst14
-rw-r--r--Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt18
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.cxx10
-rw-r--r--Source/cmGlobalVisualStudioVersionedGenerator.h1
-rw-r--r--Tests/RunCMake/GeneratorInstance/DefaultInstance-stdout.txt1
-rw-r--r--Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake2
9 files changed, 57 insertions, 17 deletions
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 2a1e017..23d8256 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -131,6 +131,7 @@ Variables that Provide Information
/variable/CMAKE_VS_TARGET_FRAMEWORK_IDENTIFIER
/variable/CMAKE_VS_TARGET_FRAMEWORK_TARGETS_VERSION
/variable/CMAKE_VS_TARGET_FRAMEWORK_VERSION
+ /variable/CMAKE_VS_VERSION_BUILD_NUMBER
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM
/variable/CMAKE_XCODE_BUILD_SYSTEM
diff --git a/Help/release/dev/vs-version-var.rst b/Help/release/dev/vs-version-var.rst
new file mode 100644
index 0000000..09daab7
--- /dev/null
+++ b/Help/release/dev/vs-version-var.rst
@@ -0,0 +1,6 @@
+vs-version-var
+--------------
+
+* A :variable:`CMAKE_VS_VERSION_BUILD_NUMBER` variable is now set by
+ :ref:`Visual Studio Generators` for VS 2017 and above to report the
+ four-component Visual Studio version number.
diff --git a/Help/variable/CMAKE_GENERATOR_INSTANCE.rst b/Help/variable/CMAKE_GENERATOR_INSTANCE.rst
index 6bfabe0..4317622 100644
--- a/Help/variable/CMAKE_GENERATOR_INSTANCE.rst
+++ b/Help/variable/CMAKE_GENERATOR_INSTANCE.rst
@@ -43,24 +43,8 @@ Supported pairs are:
.. versionadded:: 3.23
Specify the 4-component VS Build Version, a.k.a. Build Number.
- The components are:
- ``<major>.<minor>``
-
- The VS major and minor version numbers.
- These are the same as the release version numbers.
-
- ``<date>``
-
- A build date in the format ``MMMDD``, where ``MMM`` is a month index
- since an epoch used by Microsoft, and ``DD`` is a day in that month.
-
- ``<build>``
-
- A build index on the day represented by ``<date>``.
-
- The build number is reported by ``vswhere`` as ``installationVersion``.
- For example, VS 16.11.10 has build number ``16.11.32126.315``.
+ .. include:: CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt
.. versionadded:: 3.23
@@ -75,3 +59,6 @@ to hold the value persistently. If an environment variable of the form
is set and points to the ``Common7/Tools`` directory within one of the
VS instances, that instance will be used. Otherwise, if more than one
VS instance is installed we do not define which one is chosen by default.
+
+The VS version build number of the selected VS instance is provided in
+the :variable:`CMAKE_VS_VERSION_BUILD_NUMBER` variable.
diff --git a/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER.rst b/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER.rst
new file mode 100644
index 0000000..f86ed7c
--- /dev/null
+++ b/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER.rst
@@ -0,0 +1,14 @@
+CMAKE_VS_VERSION_BUILD_NUMBER
+-----------------------------
+
+.. versionadded:: 3.26
+
+Visual Studio version.
+
+:ref:`Visual Studio Generators` for VS 2017 and above set this
+variable to the Visual Studio version build number in the format
+``<major>.<minor>.<date>.<build>``.
+
+.. include:: CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt
+
+See also the :variable:`CMAKE_GENERATOR_INSTANCE` variable.
diff --git a/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt b/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt
new file mode 100644
index 0000000..6bdede7
--- /dev/null
+++ b/Help/variable/CMAKE_VS_VERSION_BUILD_NUMBER_COMPONENTS.txt
@@ -0,0 +1,18 @@
+The components are:
+
+``<major>.<minor>``
+
+ The VS major and minor version numbers.
+ These are the same as the release version numbers.
+
+``<date>``
+
+ A build date in the format ``MMMDD``, where ``MMM`` is a month index
+ since an epoch used by Microsoft, and ``DD`` is a day in that month.
+
+``<build>``
+
+ A build index on the day represented by ``<date>``.
+
+The build number is reported by ``vswhere`` as ``installationVersion``.
+For example, VS 16.11.10 has build number ``16.11.32126.315``.
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
index 59f1dc2..415eb7c 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx
@@ -521,6 +521,7 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
{
if (this->LastGeneratorInstanceString &&
i == *(this->LastGeneratorInstanceString)) {
+ this->SetVSVersionVar(mf);
return true;
}
@@ -592,6 +593,8 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance(
cmStateEnums::INTERNAL);
}
+ this->SetVSVersionVar(mf);
+
// The selected instance may have a different MSBuild than previously found.
this->MSBuildCommandInitialized = false;
@@ -672,6 +675,13 @@ bool cmGlobalVisualStudioVersionedGenerator::ParseGeneratorInstance(
return true;
}
+void cmGlobalVisualStudioVersionedGenerator::SetVSVersionVar(cmMakefile* mf)
+{
+ if (cm::optional<std::string> vsVer = this->GetVSInstanceVersion()) {
+ mf->AddDefinition("CMAKE_VS_VERSION_BUILD_NUMBER", *vsVer);
+ }
+}
+
bool cmGlobalVisualStudioVersionedGenerator::ProcessGeneratorInstanceField(
std::string const& key, std::string const& value)
{
diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.h b/Source/cmGlobalVisualStudioVersionedGenerator.h
index 4c69aeb..45aca74 100644
--- a/Source/cmGlobalVisualStudioVersionedGenerator.h
+++ b/Source/cmGlobalVisualStudioVersionedGenerator.h
@@ -93,6 +93,7 @@ private:
mutable cmVSSetupAPIHelper vsSetupAPIHelper;
bool ParseGeneratorInstance(std::string const& is, cmMakefile* mf);
+ void SetVSVersionVar(cmMakefile* mf);
std::string GeneratorInstance;
std::string GeneratorInstanceVersion;
diff --git a/Tests/RunCMake/GeneratorInstance/DefaultInstance-stdout.txt b/Tests/RunCMake/GeneratorInstance/DefaultInstance-stdout.txt
new file mode 100644
index 0000000..078d96e
--- /dev/null
+++ b/Tests/RunCMake/GeneratorInstance/DefaultInstance-stdout.txt
@@ -0,0 +1 @@
+-- CMAKE_VS_VERSION_BUILD_NUMBER='[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
diff --git a/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake b/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake
index 9761f0c..5c5ec56 100644
--- a/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake
+++ b/Tests/RunCMake/GeneratorInstance/DefaultInstance.cmake
@@ -12,3 +12,5 @@ elseif(NOT IS_DIRECTORY "${CMAKE_GENERATOR_INSTANCE}")
"which is not an existing directory.")
endif()
file(WRITE "${CMAKE_BINARY_DIR}/instance.txt" "${CMAKE_GENERATOR_INSTANCE}")
+
+message(STATUS "CMAKE_VS_VERSION_BUILD_NUMBER='${CMAKE_VS_VERSION_BUILD_NUMBER}'")