Pass selected file to Make target in Eclipse - c++

At the company I'm currently working for, several IDEs are being used (they develop firmware for different embedded platforms).
All their C projects use a Makefile, so we decided to also add rules to their default Makefile to run static code analysis tools.
One of the IDEs they use is Eclipse.
Here we have added additional targets to the Make Target view, that triggers the lint target from the Makefile, for example.
Since we use multiple IDEs we can tell the tools called by the Makefile to generate specific output for the IDE being used.
For Eclipse we do this by adjusting the Build Command and adding something like IDE_ENV=eclipse to the end.
This works just fine.
Recently one of the engineers mentioned that it would be really helpful if he could run the tools, as defined in the Makefile, for a single file.
So, I updated the Makefile and it now accepts a variable SOURCE_FILE with the path of the file that needs to be checked.
In Eclipse I tried adding SOURCE_FILE=${selected_resource_loc} and just SOURCE_FILE=${resource_loc}, but these variable do not seem to work when running a Make Target.
I also tried to use $(selected_resource_loc) and $(resource_loc) directly in the Makefile, but without any luck.
Can somebody tell me how I can pass the current selected file to Make when running a target from the Make Target view?

Some Eclipse special variables can be not recognized in a build configuration. Instead of running build procedure try to use External Tools Configuration.
Similar problem was described here: Custom command for Eclipse on current file .

Related

CMake specifying Native Build System Options in CMakeLists.txt(managed C++ Project)

i got stuck with a problem which has to do with a managed c++ Project.
Currently we have a working Build and we are about to use CMake to generate our Solution Files in the future.
In our solution we have some Managed C++ Project and C# Projects. I tried to generate/build the Managed C++ Projects and it works. But there is one key thing that is different which atually breaks the build.
In our working build the managed C++ Project has the Xml Tag <TargetFrameworkVersion> but when I use CMake to configure/generate the Project I end up having <TargetFramework> and this breaks the build ( I confirmed by manually changing the Tag).
I got stuck with this Problem for 2 days and the following things I already tried:
I tried setting VS_DOTNET_TARGET_FRAMEWORK_VERSION which actually is deprecated but makes sense because of the name. I ended up having in the Project file.
I also tried the newer Variables DOTNET_TARGET_FRAMEWORK, DOTNET_TARGET_FRAMEWORK_VERSION but I ended up again with in the Project file.
I thought to myself I could change the Project file after I configure/generate but thats pretty hacky (but works)
There is a second solution which actually works but is not what I really want. I can tell cmake.exe to pass some options to the native MsBuild tool to build the managed C++ target. This works but I would prefer to some how tell the CMakeLists.txt to do this or even better have the right Xml tag when generating the Proect files because we don't want to use the command line when building our projects.
The approach looks like this (Target Name is NotifierLib and .NET Framework Version is 4.7.2)
cmake --build . --target NotifierLib -- /p:TargetFrameworkVersion=v4.7.2
Did anyone came across this exact issue? Or maybe has an idea how to solve this via CMakeLists.txt?
Thanks in advance.
I finally came to a pretty Solution which was there initially.
This post helped my to get on the right Track:
How can cmake add custom entry in a project's vcxproj PropertyGroup?
Basically I don't need to iterate over the .xml File myself to edit the Tag.
I can tell CMake to set it for me as a global option with:
set_target_properties(NotifierLib PROPERTIES VS_GLOBAL_TargetFrameworkVersion "v4.7.2")
This way the initial <TargetFramework> Tag is still in the .xml File but it does not bother because it is not being used.

Eclipse IDE C/C++ automatic include paths from custom build script

I have a custom python script to build my projects in order to keep dependency simple, I would like to use Eclipse as a C++ IDE but keeping my build script.
To maintain autocompletion and intellisense (with docs etc...) I would like to tell Eclipse the (non standard) headers and defines added during dependency resolution in my script.
I've found that ".cproject" file contains such information, is it safe to alter it from the build scripts or is there any way to integrate my script in Eclipse itself?
Example:
# TestGame.json
{
"name": "TestGame",
"extend": "BASE",
"actions": ["COMPILE", "LINK"],
"CC": [
"G++11"
],
"dep": {
"builds": ["DFResourcer", "DFSDL"],
"libs": ["SDL2", "SDL2main"]
}
}
My build scripts will compile modified files and link them with all the needed files and will find "/home/cpp-projects/DFSDL/include", other paths that must be included and the need for --std=c++11, I want a way to tell Eclipse (not manually) to search for headers also there for autocompletion etc...
I've found that ".cproject" file contains such information, is it safe to alter it from the build scripts
It's doable, but not recommended, because the file format is undocumented and not guaranteed to be stable across Eclipse versions.
is there any way to integrate my script in Eclipse itself?
You could write an Eclipse plugin that runs your script and communicates with it or consumes output it produces. However, that seems like a heavyweight solution.
I would suggest the following simple solution:
Eclipse has a build output parser. I've written about how to use it in other answers, like this one. Basically, it's designed to parse the output of a make invocation, parse any line that looks like a compiler command, and configure include paths based on the -I arguments in that command.
You can make use of this even though you're using a custom build script rather than make: just get your script to output the compiler commands it invokes (if you want, you can make this conditional on a flag like --verbose), and configure Eclipse to invoke your build script rather than make (passing in the flag if you used one) when building your project.

Xcode support for C++

I try to use Xcode (v.7.3.1) for my C++ project (build system - make), but the experience is quite poor (and it was always like that since old versions like v4 when I started using it) - code completion doesn't work, color syntaxing works oddly (no coloring sometimes, or partially colored code), no "jump-to-definition" functionality, can't switch b/w header/source files with shortcuts. Basically, it's just a text editor where I have to use "Find" and Cmd+Shift+O all the time.
Is this intentional and Xcode will never get any proper support for C++ projects with external build system (make) or am I misconfiguring my project? How can I re-index files in the project? How can I make code completion work?
Thanks,
I believe there is a way to use Xcode with makefiles by adding an external build target, file->new->target->External Build System.
This is an older tutorial but the steps may be worth looking through: http://web.ist.utl.pt/jose.alberto.coelho/mac/MakefilesXcode.pdf
I've never had a problem with the syntax highlighting, but I remember the refactoring support being limited for C++ in some ways.
So, I ended up using this workaround: even though, I use external build system, I create Console Application project in Xcode and choose C++ language in settings. Then, I simply add my source files to the project (just drag folders from the Finder window) and then manually create project targets of type External Build System as I need. I don't use default target and don't use generated main.cpp file at all.
My files get indexed with no problems. I'm also able to debug code as I used to.
I still think Xcode developers should review indexing process for the projects with external build system...
Thanks for all the insights though!

How to compile WindRiver/Eclipse C++ projects from the command line?

I'm currently running a variant of Eclipse known as WindRiver, which is designed for embedded systems programming using C++ (specifically, I'm part of my high school's FIRST Robotics team).
I'm able to successfully compile and build the project from within Eclipse (Project > Build Project) but I'm looking for ways to automate this process by compiling by using the command line.
The project already contains a makefile and everything, so ideally I want to be able to just run that without making any manual changes. I pastebin'd the makefile in case its relevant.
Does anybody know where I can find more information on compiling C++ programs from the command line for either Eclipse or WindRiver or on running makefiles on Windows? I tried looking at "How to run a makefile in Windows?" but following the first answer didn't work (it gave a syntax error for the makefile).
I'm currently using a Windows 8 laptop. As best as I can tell, the current varient of WindRiver I'm using is based on Eclipse version 3.3.1.
You will need a make utility, I believe your WindRiver / Eclipse setup would come with "gnumake" (probably called either make or gmake). You'd nee dto set up the command line path to lead to the compiler and the make executable. Unfortunately, this is not a great answer, as I can't give you exact links to the make and compiler locations (it would of course also depend on where you installed things). I just thought I'd lead you somewhat on the right path, since the question has been up for a little while and no one jumped at it.
Thanks to Mat Petersson's answer, I was able to identify everything I needed and create a batch file that could compile the file for me:
#echo off
setlocal
set PATH=%PATH%;C:\WindRiver\gnu\3.4.4-vxworks-6.3\x86-win32\bin;C:\WindRiver\utilities-1.0\x86-win32\bin;C:\WindRiver\setup\x86-win32\bin
set WIND_BASE=C:\WindRiver\vxworks-6.3
cd My_Project\PPC603gnu
make --no-print-directory BUILD_SPEC=PPC603gnu DEBUG_MODE=1 TRACE=1

Import existing C++ project into Xcode IDE

I am trying to open an existing C++ open-source library in Xcode to publish it with my own modification/additions. The library is Tesseract-OCR, which does not include a .xcodeproj file.
Since Xcode can function as an IDE, is it possible to open a bunch of files as a single project in Xcode? Is there an easy way to produce an Xcode project?
There are several ways you could do it, depending on the level of IDE integration you want. There's no direct way of importing a Makefile-based project into Xcode. You can create a project that builds via the Makefile, but you wouldn't get many of the benefits of using an IDE, since the editor features such as word completion rely on Xcode being able to parse the files in the project. You will be able to use the debugger though. To do this, create a new project and add a custom target with a script build phase that just calls down to Makefile.
If however the project you're building compiles very easily, ie without requiring a lot of macros to be set up, include paths, etc, then it may be simple to just create an empty project and merely add all source files to it. I've used this method extensively for building boost libraries. If this is a configure && make type project then you will probably have to run the configure step first, and ensure any top level config.h files are included in the project.
If the project has a complex makefile then it is likely to be an involved task to create a useful Xcode project
I realise you asked explicitly for Xcode, but in case you were actually trying to solve the problem of "I have existing C++ code which builds and runs fine from the command line, and I'd like to code and debug it in an IDE, what should I do?" my firm recommendation would be to avoid Xcode and go for Eclipse.
The reason is that as far as I can tell, Xcode has no way of ingesting the command line build environment and effectively requires you to recreate the make process inside Xcode from scratch. Fine for tiny projects, but anything with more than a few source files and it quickly becomes painful. Whereas in Eclipse everything is built around Makefiles. So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. This of course could be because I'm an Xcode noob, but my 2c.
To create an Xcode project from an existing cmake project, you can run cmake -G Xcode. It produces some folders and files apart from the project file, so it might be better to create a folder for it first. For example:
mkdir -p build/xcode
cd build/xcode
cmake -G Xcode ../..
Xcode is a useable IDE for library creation.
Of course a good first step is to see if the one source code will build on its own with configure scripts that are included.
If not, it becomes a question of how many libraries you need to link in.
There are resources online (or at least there used to be) for using Xcode (or perhaps it's forerunner Product builder) for porting Unix projects to Mac.
Good tutorial at: http://www.macresearch.org/tutorial-introducing-xcode-30-organizer
Another good reference is Darwin Ports.
As for doing this on your own. You can build c++ based libraries in XCode. People do that every day. You can even use one of the Xcode templates to get you started.
However, library dev requires more experience with Xcode then say a simple Cocoa "Hello World" app.
The remaining questions will be assuring that the source code's dependencies are already built into the Mac's SDK. (Don't hold your breath for linking to MFC)
It's a general question... So it's a general answer.
In Xcode8,there is "Xcode->file->add files to...",then choose your files.If you want to add several files at a time,press "Cmd" when you are choosing.