If you use one of the EDE projects that supports it, the operation can be found in the menu.
Step 1. Open the file in the project directory. Step 2. Select the menu item "Project-> Project Settings-> Add Target"
He will ask if you want to add the current file to this target.
You can also do:
M-x ede-new-target RET
EDE . Emacs Linux ede-cpp-root, .