|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><EFBFBD>ƺ<EFBFBD>
|
|
|
|
|
* ʱ<EFBFBD>䣺2019-12-04
|
|
|
|
|
* @param cate_dir
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
void getFiles(const string &path, vector<std::string> &files) {
|
|
|
|
|
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
intptr_t hFile = 0;
|
|
|
|
|
//<2F>ļ<EFBFBD><C4BC><EFBFBD>Ϣ<EFBFBD><CFA2>_finddata_t<5F><74>Ҫio.hͷ<68>ļ<EFBFBD>
|
|
|
|
|
struct _finddata_t fileinfo;
|
|
|
|
|
std::string p;
|
|
|
|
|
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) {
|
|
|
|
|
do {
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼,<2C><><EFBFBD><EFBFBD>֮
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
if ((fileinfo.attrib & _A_SUBDIR)) {
|
|
|
|
|
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
|
|
|
|
|
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
|
|
|
|
|
} else {
|
|
|
|
|
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
|
|
|
|
|
}
|
|
|
|
|
} while (_findnext(hFile, &fileinfo) == 0);
|
|
|
|
|
_findclose(hFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int startsWith(string s, string sub) {
|
|
|
|
|
return s.find(sub) == 0 ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int endsWith(string s, string sub) {
|
|
|
|
|
return s.rfind(sub) == (s.length() - sub.length()) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD>滻ָ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><EFBFBD>ƺ<EFBFBD>
|
|
|
|
|
* ʱ<EFBFBD>䣺2019-11-21
|
|
|
|
|
* @param str
|
|
|
|
|
* @param old_value
|
|
|
|
|
* @param new_value
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
string &replace_all(string &str, const string &old_value, const string &new_value) {
|
|
|
|
|
while (true) {
|
|
|
|
|
string::size_type pos(0);
|
|
|
|
|
if ((pos = str.find(old_value)) != string::npos)
|
|
|
|
|
str.replace(pos, old_value.length(), new_value);
|
|
|
|
|
else break;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>зָ<EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD>ߺ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><EFBFBD>ƺ<EFBFBD>
|
|
|
|
|
* ʱ<EFBFBD>䣺2019-12-04
|
|
|
|
|
* @param s
|
|
|
|
|
* @param sv
|
|
|
|
|
* @param flag
|
|
|
|
|
*/
|
|
|
|
|
void split(const string &s, vector<string> &sv, const char flag = ' ') {
|
|
|
|
|
sv.clear();
|
|
|
|
|
istringstream iss(s);
|
|
|
|
|
string temp;
|
|
|
|
|
|
|
|
|
|
while (getline(iss, temp, flag)) {
|
|
|
|
|
sv.push_back(temp);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰexeִ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>Ŀ¼
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><EFBFBD>ƺ<EFBFBD>
|
|
|
|
|
* ʱ<EFBFBD>䣺2019-12-04
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
string getCurrentParentPath() {
|
|
|
|
|
//<2F><>ǰĿ¼
|
|
|
|
|
char currentPath[256];
|
|
|
|
|
_getcwd(currentPath, sizeof(currentPath));
|
|
|
|
|
vector<string> pathVector;
|
|
|
|
|
split(string(currentPath), pathVector, '\\');
|
|
|
|
|
string parentPath = "";
|
|
|
|
|
for (int i = 0; i < pathVector.size() - 1; i++) {
|
|
|
|
|
parentPath += pathVector[i] + "\\";
|
|
|
|
|
}
|
|
|
|
|
//ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķָ<C4B7><D6B8><EFBFBD>
|
|
|
|
|
parentPath = parentPath.substr(0, parentPath.size() - 1);
|
|
|
|
|
return parentPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string inFile = "../../CMakeLists.config";
|
|
|
|
|
string configFile = "../CMakeLists.txt";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>ǰĿ¼<C4BF><C2BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
|
|
|
|
|
string path = getCurrentParentPath();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ģ<EFBFBD>
|
|
|
|
|
locale loc = locale::global(locale(locale(), "", LC_CTYPE));
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
ifstream in;
|
|
|
|
|
in.open(inFile);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
|
|
|
|
ofstream out;
|
|
|
|
|
out.open(configFile);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
string line;
|
|
|
|
|
while (getline(in, line)) {
|
|
|
|
|
string str = line;
|
|
|
|
|
out << str << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>CPP<50>ļ<EFBFBD>
|
|
|
|
|
vector<string> filenames;//<2F><><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|
|
|
|
getFiles(path, filenames);
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (auto file : filenames) {
|
|
|
|
|
if (endsWith(file, ".cpp") && !endsWith(file, "CMakeCXXCompilerId.cpp")) {
|
|
|
|
|
string key = replace_all(file, path, "").substr(1);
|
|
|
|
|
key = replace_all(key, "\\", "/");
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
vector<string> sv;
|
|
|
|
|
split(key, sv, '/');
|
|
|
|
|
string fName;
|
|
|
|
|
if (sv.size() > 1)fName = sv[1]; else fName = sv[0];
|
|
|
|
|
fName = replace_all(fName, ".cpp", "");
|
|
|
|
|
out << "add_executable(" + fName + " " + key + ")" << endl;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
|
|
|
|
|
out.close();
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
|
|
cout << "<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ijɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.cpp<70>ļ<EFBFBD><C4BC><EFBFBD>" << count << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|