Skip to content

Commit 6b3a829

Browse files
committed
feat(Vcvars): Support FunctionsOnly component to skip discovery logic
Add support for the `FunctionsOnly` component to the Vcvars package. When specified via: find_package(Vcvars REQUIRED COMPONENTS FunctionsOnly) the module will only define the helper functions: - Vcvars_GetVisualStudioPaths - Vcvars_ConvertMsvcVersionToVsVersion It will skip all logic related to: - auto-detecting the latest installed MSVC version - locating the appropriate vcvars batch file - generating a wrapper launcher This is useful in contexts like script mode (e.g., `cmake -P`) where only the helper logic is needed, and not full environment setup. To ensure consistency and avoid ambiguous usage, the module requires that `FunctionsOnly` be passed exactly (case-sensitive and standalone). Any mixed or misspelled components will trigger a fatal error. Documentation was updated accordingly.
1 parent 76f384d commit 6b3a829

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

FindVcvars.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ This module also defines the following functions
9696
``<output_var>``
9797
The name of the variable to be set with the Visual Studio version.
9898
99+
This module also supports the following COMPONENTS:
100+
101+
* ``FunctionsOnly``: Only defines the helper functions
102+
(e.g., ``Vcvars_GetVisualStudioPaths``, ``Vcvars_ConvertMsvcVersionToVsVersion``)
103+
without attempting to discover or set ``Vcvars_BATCH_FILE`` or ``Vcvars_LAUNCHER``.
104+
99105
#]=======================================================================]
100106

101107
cmake_minimum_required(VERSION 3.20.6...3.22.6 FATAL_ERROR)
@@ -115,6 +121,16 @@ set(_Vcvars_SUPPORTED_MSVC_VERSIONS
115121
1400 # VS 2005
116122
)
117123

124+
# process component arguments
125+
if(Vcvars_FIND_COMPONENTS)
126+
if("FunctionsOnly" IN_LIST Vcvars_FIND_COMPONENTS)
127+
set(_Vcvars_FUNCTIONS_ONLY TRUE)
128+
endif()
129+
if(_Vcvars_FUNCTIONS_ONLY AND NOT Vcvars_FIND_COMPONENTS STREQUAL "FunctionsOnly")
130+
message(FATAL_ERROR "FindVcvars: Only supported COMPONENTS argument is 'FunctionsOnly'.")
131+
endif()
132+
endif()
133+
118134
function(_vcvars_message)
119135
if(NOT Vcvars_FIND_QUIETLY)
120136
message(${ARGN})
@@ -213,6 +229,11 @@ function(Vcvars_GetVisualStudioPaths msvc_version msvc_arch output_var)
213229
set(${output_var} ${_vs_installer_paths} PARENT_SCOPE)
214230
endfunction()
215231

232+
if(_Vcvars_FUNCTIONS_ONLY)
233+
set(Vcvars_FOUND TRUE)
234+
return()
235+
endif()
236+
216237
# default
217238
if(NOT DEFINED Vcvars_MSVC_ARCH)
218239
if(NOT DEFINED CMAKE_SIZEOF_VOID_P)

0 commit comments

Comments
 (0)