I'm attempting to get the header names of all the #include declarations in my robot.cpp, i.e., if I have an example.cpp with two declarations:
example.cpp
#include "MyLib.h"
#include <iosream>
//some code
I want to see in my output something like this:
INCLUDE_NAME MyLib.h
INCLUDE_NAME iosream
I have these robot.cpp and CMakeLists.txt files (they are simplified):
CMakeLists.txt
...
file(STRINGS ${SRC_FILE} SRC_CONTENT) #copy the file content
foreach(SRC_LINE ${SRC_CONTENT})
if("${SRC_LINE }" MATCHES "^ *#include *[<\"](.*)[>\"]")
message("INCLUDE_NAME ${CMAKE_MATCH_1}")
...
robot.cpp
#include "ArduinoRobot.h"
#include "EasyTransfer2.h"
void RobotControl::pointTo(int angle){
int target=angle;
uint8_t speed=80;
target=target%360;
if(target<0){
target+=360;
}
int direction=angle;
while(1){
if(direction>0){
motorsWrite(speed,-speed);//right
delay(10);
}else{
motorsWrite(-speed,speed);//left
delay(10);
}
int currentAngle=compassRead();
int diff=target-currentAngle;
if(diff<-180)
diff += 360;
else if(diff> 180)
diff -= 360;
direction=-diff;
if(abs(diff)<5){
motorsWrite(0,0);
return;
}
}
}
Then, if I execute in a console my CMakeList.txt, I get this output:
...
INCLUDE_NAME ArduinoRobot.h"#include "EasyTransfer2.h"void RobotControl::pointTo(int angle){ int target=angle; uint8_t speed=80; target=target%360; if(target<0){ target+=360; } int direction=angle; while(1){ if(direction>0){ motorsWrite(speed,-speed);//right delay(10); }else{ motorsWrite(-speed,speed);//left delay(10); } int currentAngle=compassRead(); int diff=target-currentAngle; if(diff<-180) diff += 360; else if(diff
...
However, if I change all the symbols > to <, the result is ok, and I get the following output:
...
INCLUDE_NAME ArduinoRobot.h
INCLUDE_NAME EasyTransfer2.h
...
I guess it is because the regex, but I don't know how fix it.
Does anyone?