code_twain/sln/sdk/include/vs_tool/vs_tool.h

395 lines
38 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// function: simple parsing vcxproj files
//
// author: Gongbing
//
// date: 2020-12-09
//
//
#pragma once
#ifndef _INCLUDED_REF_
#define _INCLUDED_REF_
#include "../ref/ref.h"
#endif
namespace vs_tools
{
enum vs_proj_type
{
VSPT_UNKNOWN = 0,
VSPT_VALID_BEGIN,
VSPT_EXE,
VSPT_DLL,
VSPT_LIB,
VSPT_VALID_END,
};
enum vs_version
{
VS_VER_UNKNOWN = 0,
VS_VER_2008 = 900,
VS_VER_2013 = 1200,
VS_VER_2017 = 1400,
VS_VER_2019 = 1600,
};
enum multi_val_oper // multi-values like "str1;str2;str3;...;strn" operations ...
{
MULTI_VAL_OPER_REPLACE = 0, // replace whole target values with new value
MULTI_VAL_OPER_ADD, // insert new value if it was not existing in the target values
MULTI_VAL_OPER_DEL, // delete new value from the target values
};
__declspec(novtable) struct IVsProj : public ref_util::IRef
{
// function: load from an existing .vcxproj file
//
// parameter: prj_file - full path .vcxproj file
//
// return: error code, 0 is success
COM_API_DECLARE(long, load_from_vcxproj(const wchar_t* prj_file));
// function: load from a local directory
//
// parameter: path_dir - full path directory
//
// recurse - whether add child directories
//
// type - file type, such as "*.cpp". all files will added if it was NULL or '*'
//
// return: how many files added in. all files use global settings
//
// NOTE: this API will create the .vcxproj at the directory 'path_dir' with the folder name
COM_API_DECLARE(long, load_from_directory(const wchar_t* path_dir, bool recurse = true, const wchar_t* type = L"*"));
// function: load from a build.gn file
//
// parameter: build_gn_path - full path of the 'build.gn' file, file name must be 'build.gn'
//
// cb - to query value when a variable is unknown, see cxx_code::ILogicAction::set_callback
//
// data - see cxx_code::ILogicAction::set_callback
//
// len - see cxx_code::ILogicAction::set_callback
//
// total - see cxx_code::ILogicAction::set_callback
//
// flag - see cxx_code::ILogicAction::set_callback
//
// param - the same as 'param' you passed here
//
// param - user defined parameter for 'cb'
//
// prj_name - the project name to be generated, use the folder name the 'build.gn' in if it was NULL
//
// addition_paths - other paths to search the source files, if not given, only search files at the same directory as 'build.gn' in.
//
// return: error code, 0 is success
COM_API_DECLARE(long, load_from_build_gn(const wchar_t* build_gn_path, INTER_MODULE_CALLBACK_VAR(cb), void* param, const wchar_t* prj_name = NULL, const wchar_t* addition_paths = NULL));
COM_API_DECLARE(void, clear(void));
//// 1: attributes methods ...
// function: add a configuration like 'Debug', 'Release', ...
//
// NOTE: 'Debug' and 'Release' configurations are default when creating a new object
COM_API_DECLARE(void, add_configuration(const wchar_t* conf_name));
COM_API_DECLARE(void, remove_configuration(const wchar_t* conf_name));
// function: add a platform like 'Win32'
//
// NOTE: 'Win32' is default when creating a new object
COM_API_DECLARE(void, add_platform(const wchar_t* platform));
COM_API_DECLARE(void, remove_platform(const wchar_t* platform));
COM_API_DECLARE(void, set_project_name(const wchar_t* name)); // name ONLY, not include extension
COM_API_DECLARE(const wchar_t*, get_project_name(void)); // use the return value immediately and NEED-NOT free it
COM_API_DECLARE(void, set_project_version(vs_version ver));
COM_API_DECLARE(vs_version, get_project_version(void));
// function: set project type
//
// parameter: type - project type
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_type(vs_proj_type type, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(vs_proj_type, get_project_type(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set project char-set
//
// parameter: charset - char-set, such as 'Unicode'
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_charset(const wchar_t* charset, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_project_charset(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: set project inter-medium directory
//
// parameter: dir - full path, set to be "$(Configuration)\\$(ProjectName)\\" if it was NULL
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_intermedium_dir(const wchar_t* dir, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_project_intermedium_dir(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: set project warning level
//
// parameter: level - warning level
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_warning_level(int level = 3, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(int, get_project_warning_level(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set project optimize level
//
// parameter: optimize - optimize level, default 'Disabled' for 'Debug' and 'MaxSpeed' for 'Release'
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_optimize(const wchar_t* optimize, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_project_optimize(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: set project preprocessors
//
// parameter: pre - user custom preprocessors
//
// method - see the comment in multi_val_oper
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_preprocessors(const wchar_t* pre, multi_val_oper method = MULTI_VAL_OPER_REPLACE, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_project_preprocessors(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: set project sub system
//
// parameter: sys - system name, like 'Windows' or 'Console' ...
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_project_sub_system(const wchar_t* sys = L"Windows", const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_project_sub_system(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: add module define file (*.def)
//
// parameter: file - full path file name, clear all module definition files if it was NULL
//
// method - see the comment in multi_val_oper
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_module_define_file(const wchar_t* file, multi_val_oper method = MULTI_VAL_OPER_REPLACE, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_module_define_file(const wchar_t* cfg = NULL, const wchar_t* plat = NULL)); // use the return value immediately and NEED-NOT free it
// function: set build events
//
// parameter: build_events - pre-build events, divided by ';', NULL or empty to clear events
//
// pre_build - true to set pre-build events, false to set post-build events
//
// method - see the comment in multi_val_oper
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_build_event(const wchar_t* build_events, bool pre_build, multi_val_oper method = MULTI_VAL_OPER_REPLACE, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_build_event(bool pre_build, const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
// function: set whether to generation debug information
//
// parameter: gen - whether to generation debug information
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_generation_debug_information(bool gen, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_generation_debug_information(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set whether linking incremental
//
// parameter: inc - whether incremental
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_link_incremental(bool inc, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_link_incremental(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set whether use pre-compiled header
//
// parameter: use - whether use
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_use_pre_compiled_header(bool use, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_use_pre_compiled_header(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set whether compatible for winXP
//
// parameter: compatible - whether compatible
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: error code, 0 is success,
// ERROR_FILE_NOT_FOUND - no platform named 'plat', add it first;
// ERROR_NOT_FOUND - no configuration named 'cfg', add it first.
COM_API_DECLARE(long, set_compatible_for_xp(bool compatible, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_compatible_for_xp(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
//// 2: project file operations ...
// function: add a file into this project
//
// parameter: path_file - full path name
//
// filter - location or directory in project tree-view, NULL is not to change if file was existing
//
// return: true if added new item, false if it was already in project
COM_API_DECLARE(bool, add_file(const wchar_t* path_file, const wchar_t* filter = NULL));
COM_API_DECLARE(bool, remove_file(const wchar_t* path_file)); // remove all files if path_file was NULL !!!
COM_API_DECLARE(long, get_file_count(void));
// function: add a folder and all files in it
//
// parameter: path_dir - full path directory
//
// recurse - whether add child directories
//
// type - file type, such as "*.cpp". all files will added if it was NULL or '*'
//
// return: how many files added in. all files use global settings
COM_API_DECLARE(long, add_folder(const wchar_t* path_dir, bool recurse = true, const wchar_t* type = L"*"));
COM_API_DECLARE(long, remove_folder(const wchar_t* path_dir)); // this remove all files which belongs the folder
// function: set file whether use pre-compiled header
//
// parameter: path_file - full path name, NULL for global settings
//
// use - whether use
//
// method - see the comment in multi_val_oper
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: true commonly, false if the file was not existing
COM_API_DECLARE(bool, set_file_use_pch(const wchar_t* path_file, bool use, multi_val_oper method = MULTI_VAL_OPER_REPLACE, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_file_use_pch(const wchar_t* path_file, const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set file whether exclude from building
//
// parameter: path_file - full path name
//
// exclude - whether exclude
//
// method - see the comment in multi_val_oper
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: true commonly, false if the file was not existing
COM_API_DECLARE(bool, set_file_exclude_from_build(const wchar_t* path_file, bool exclude, multi_val_oper method = MULTI_VAL_OPER_REPLACE, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(bool, is_file_exclude_from_build(const wchar_t* path_file, const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32"));
// function: set file custom compiling command
//
// parameter: path_file - full path name
//
// cmd - custom command string, NULL or empty to clear
//
// cfg - set type of given configuration, effects on all configurations if it was NULL
//
// plat - set type of given platform, effects on all platforms if it was NULL
//
// return: true commonly, false if the file was not existing
COM_API_DECLARE(bool, set_file_custom_compile_command(const wchar_t* path_file, const wchar_t* cmd, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(const wchar_t*, get_file_custom_compile_command(const wchar_t* path_file, const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it
COM_API_DECLARE(void, add_include_dir(const wchar_t* dir, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(void, remove_include_dir(const wchar_t* dir, const wchar_t* cfg = NULL, const wchar_t* plat = NULL)); // remove all including dirs if 'dir' was NULL
COM_API_DECLARE(const wchar_t*, get_include_dirs(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it. return like "path1;path2;path3;...;"
COM_API_DECLARE(void, add_library_dir(const wchar_t* dir, const wchar_t* cfg = NULL, const wchar_t* plat = NULL));
COM_API_DECLARE(void, remove_library_dir(const wchar_t* dir, const wchar_t* cfg = NULL, const wchar_t* plat = NULL)); // remove all library dirs if 'dir' was NULL
COM_API_DECLARE(const wchar_t*, get_library_dirs(const wchar_t* cfg = L"Debug", const wchar_t* plat = L"Win32")); // use the return value immediately and NEED-NOT free it. return like "path1;path2;path3;...;"
//// 3: project operations ...
// function: save the project to local .vcxproj file
//
// parameter: dir - full path directory, can be different from the path when you create this
//
// name - the project file name(without extension), set as the same as project name if it was NULL
//
// copy_file - whether copy the source files to 'dir'. when is true, the root directory of the source files is ./dir/src/, and project files (.vcxproj) are in ./dir/vcxproj/
// NOTE: this parameter will be omitted if 'dir' was NULL
//
// return: whether success
COM_API_DECLARE(bool, save_to(const wchar_t* dir = NULL, const wchar_t* name = NULL, bool copy_file = false));
};
PORT_API(IVsProj*) create_empty_project(void);
};