-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmake.cpp
More file actions
71 lines (64 loc) · 1.73 KB
/
cmake.cpp
File metadata and controls
71 lines (64 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <regex>
#include <vector>
#if __GNUC__ <= 5
#error your compiler cannot support C++17 standard. we need at least GCC 6
#elif (__GNUC__ > 5) && (__GNUC__ < 11)
#include <experimental/filesystem>
#else
#include <filesystem>
#endif
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
#if (__GNUC__ > 6) && (__GNUC__ < 11)
namespace filesystem = experimental::filesystem;
#endif
//remove space with cpp API
string removeSpace(string str) {
str.erase(remove(str.begin(), str.end(), ' '), str.end());
//res.assign(res.begin(), res.end());
return str;
}
//remove space with regex
string removeSpace2(string str) {
string p = "\x20";
regex express(p);
regex_replace(str, express, '\0');
return str;
}
int main(int argc, char* argv[]) {
if(argc != 2) {
cerr << "please offer path of project directory (only)" << endl;
return 1;
}
filesystem::path CmakeRootPath = argv[1];
if(!filesystem::exists(CmakeRootPath)) {
cerr << "offer a correct path, and make sure it is a directory" << endl;
return 2;
}
if(!filesystem::is_directory(CmakeRootPath)) {
cerr << "please offer a path of directory, not a file" << endl;
return 2;
}
string Cmakefile = (string)CmakeRootPath + (string)"/CMakeLists.txt";
if(!filesystem::exists(Cmakefile)) {
cerr << "the path you have offerd doesn't contain CMakeLists.txt in top directory." << endl;
return 2;
}
ifstream fin(Cmakefile, ios::in);
char line[1024] = {0};
while(fin.getline(line, sizeof(line))) {
string linestr = removeSpace(line);
if(linestr.empty()) {
continue;
}
if(linestr.at(0) == '#') {
continue;
}
string p = "find_package(";
}
fin.clear();
fin.close();
return 0;
}