Browse Source

Corrected order of found executables in CMakeLists.txt files

merge-requests/365/head
eidheim 9 years ago
parent
commit
2f26df69c5
  1. 14
      src/cmake.cc
  2. 4
      tests/cmake_build_test.cc

14
src/cmake.cc

@ -359,28 +359,26 @@ std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > CMak
if(!parsed) if(!parsed)
parse(); parse();
std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > functions; std::vector<std::pair<boost::filesystem::path, std::vector<std::string> > > functions;
size_t file_c=0; for(size_t c=files.size()-1;c!=static_cast<size_t>(-1);--c) {
for(auto &file: files) {
size_t pos=0; size_t pos=0;
while(pos<file.size()) { while(pos<files[c].size()) {
auto start_line=pos; auto start_line=pos;
auto end_line=file.find('\n', start_line); auto end_line=files[c].find('\n', start_line);
if(end_line==std::string::npos) if(end_line==std::string::npos)
end_line=file.size(); end_line=files[c].size();
if(end_line>start_line) { if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line); auto line=files[c].substr(start_line, end_line-start_line);
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, function_regex)) { if(std::regex_match(line, sm, function_regex)) {
auto data=sm[1].str(); auto data=sm[1].str();
while(data.size()>0 && data.back()==' ') while(data.size()>0 && data.back()==' ')
data.pop_back(); data.pop_back();
auto parameters=get_function_parameters(data); auto parameters=get_function_parameters(data);
functions.emplace(functions.begin(), paths[file_c], parameters); functions.emplace_back(paths[c], parameters);
} }
} }
pos=end_line+1; pos=end_line+1;
} }
file_c++;
} }
return functions; return functions;
} }

4
tests/cmake_build_test.cc

@ -32,9 +32,9 @@ int main() {
auto functions_parameters=cmake.get_functions_parameters("project"); auto functions_parameters=cmake.get_functions_parameters("project");
g_assert(functions_parameters.at(0).second.at(0)=="juci"); g_assert(functions_parameters.at(0).second.at(0)=="juci");
g_assert(cmake.get_executable(project_path/"build", tests_path)==project_path/"build"/"tests"/"git_test"); g_assert(cmake.get_executable(project_path/"build", tests_path)==project_path/"build"/"tests"/"process_test");
g_assert(cmake.get_executable(project_path/"build", tests_path/"cmake_build_test.cc")==project_path/"build"/"tests"/"cmake_build_test"); g_assert(cmake.get_executable(project_path/"build", tests_path/"cmake_build_test.cc")==project_path/"build"/"tests"/"cmake_build_test");
g_assert(cmake.get_executable(project_path/"build", tests_path/"non_existing_file.cc")==project_path/"build"/"tests"/"git_test"); g_assert(cmake.get_executable(project_path/"build", tests_path/"non_existing_file.cc")==project_path/"build"/"tests"/"process_test");
} }
auto build=Project::Build::create(tests_path); auto build=Project::Build::create(tests_path);

Loading…
Cancel
Save