Introduce make_cmake_cmd() helper function
MODIFY
include/vcpkglib.h
include/vcpkglib.h
@@ -17,4 +17,18 @@ namespace vcpkg
};
std::vector<StatusParagraph_and_associated_files> get_installed_files(const vcpkg_paths& paths, const StatusParagraphs& status_db);
+
+
+ struct CMakeVariable
+ {
+ CMakeVariable(const std::wstring& varname, const wchar_t* varvalue);
+ CMakeVariable(const std::wstring& varname, const std::string& varvalue);
+ CMakeVariable(const std::wstring& varname, const std::wstring& varvalue);
+ CMakeVariable(const std::wstring& varname, const fs::path& path);
+
+ std::wstring s;
+ };
+
+ std::wstring make_cmake_cmd(const fs::path& cmake_exe, const fs::path& cmake_script, const std::vector<CMakeVariable>& pass_variables);
+
} // namespace vcpkg

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
#include "vcpkg_Files.h"
#include "Paragraphs.h"
#include "metrics.h"
+#include "vcpkg_Strings.h"
namespace vcpkg
{
@@ -200,4 +201,15 @@ namespace vcpkg
return installed_files;
}
+
+ CMakeVariable::CMakeVariable(const std::wstring& varname, const wchar_t* varvalue) : s(Strings::wformat(LR"("-D%s=%s")", varname, varvalue)) { }
+ CMakeVariable::CMakeVariable(const std::wstring& varname, const std::string& varvalue) : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str()) { }
+ CMakeVariable::CMakeVariable(const std::wstring& varname, const std::wstring& varvalue) : CMakeVariable(varname, varvalue.c_str()) {}
+ CMakeVariable::CMakeVariable(const std::wstring& varname, const fs::path& path) : CMakeVariable(varname, path.generic_wstring()) {}
+
+ std::wstring make_cmake_cmd(const fs::path& cmake_exe, const fs::path& cmake_script, const std::vector<CMakeVariable>& pass_variables)
+ {
+ std::wstring cmd_cmake_pass_variables = Strings::wjoin(L" ", pass_variables, [](auto&& v) { return v.s; });
+ return Strings::wformat(LR"("%s" %s -P "%s")", cmake_exe.native(), cmd_cmake_pass_variables, cmake_script.generic_wstring());
+ }
}

Introduce make_cmake_cmd() helper function