I know this can be done using a makefile, alas I am not using a makefile, but rather Eclipse's "managed" C++ project. :( In any case, this is what I'm trying to accomplish:
I have a C++ project in Eclipse. I have a number of XML files in this project that specify information about source files that are auto-generated. When the XML files change, I would like a custom tool executed to convert them. The challenges are:
These resources need to be built prior to compiling the project since they specify source and header files used in the compilation.
They should be built only when the XML file is modified (header files are generated, so this is to avoid needless recompilation because a file timestamp changed).
I'd like it included as part of the build process of this project, not a separate project.
I see moving to CMake in the future, but for the time being I am trying to make do.
You can add a pre-build command in Project Properties -> C/C++ Build -> Settings -> Build Steps. This command will be executed before each build.
I'm not aware of a built-in way to get the command to run only when the XML file is modified. If you want that, then instead of making the pre-build command the XML-converting command itself, you can make it a "make" command with a makefile with a single rule whose prerequisite is the XML file and which calls the XML-converting command.
Related
I have a C++ project for which I need to run a custom build tool on some header files to generate code that is required when compiling this project. In general my configuration works. I trigger a build, VS/MSBuild detects whether the output files are up-to-date and runs the custom build tool only if necessary.
However, a problem arises if the build is run in combination with another configuration of the same project. Both configurations depend on the output files of the custom build tool. So if run sequentially only one configuration should trigger the custom build tool to run. For which ever configuration a build is triggered second the output files of the custom build tool are already present and up-to-date. So there is no need to build them again. Unfortunately this is exactly what is happening. Since the custom build tool takes quite some time to run, this increases build times dramatically.
Another interesting aspect is, that once both configuration have run, I can trigger any of them again and the custom build tool is not invoked.
What I would have expected from the documentation is that the custom build tool is triggered:
If any of the files specified as Outputs is missing
If the file for which I specified the custom build tool was modified later than any of the existing files specified as Outputs
If any of the files I specified as Additional Dependencies were modified later than any of the existing files specified as Outputs
But all of this independent from the configuration for which the build was triggered.
Does anyone have an idea on why this might happen? I checked that the settings for the custom build tool are identical for both configurations. The output files are generated into the same folder for both configurations.
The documentation you're referring to is basically correct but it omits to say that everything in there is basically per project configuration/platform because it uses tracker.exe which depends on .tlog files which by default go into the intermediate directory. So as you figured out, making all configurations use the same location for the tlog files should keep the tracker happy and only invoke the custom build tool when needed, independent of configuration/platform. I'm not sure I'd recommend any of this though, sharing temporary object files might cause you problems later.
Another way to deal with this is adding a seperate project with just one configuration, say 'Custom', and do the custom build there. Than make your current project(s) depend on that project and in the solution's Configuration Manager adjust all entries so each configuration you have now builds the 'Custom' configuration for the new project.
We debug our binary using an IAR workspace (.eww) that wasn't used to build the binary - it was done using make from the command line. The make files were generated by a build system (exactly how is lost in the mists of time).
Is there a way to add the sources to the .eww after the make i.e. automatically traverse the source file directory structure and add the same sources that make uses? There are multiple copies of some of the sources in the structure due to some sloppy copy & pasting i.e. same file, 2 copies, possibly identical, different directories.
Project files (.ewp) are simply xml files. Source files are listed as
<file><name>path\to\source.c</name></file>
in <project> node.
You could create a script (Python for example) which searches for files or make gives them as parameters. Script could then filter out duplicates and update IAR project file accordingly.
But if you are using IAR compiler to build and workbench to debug, then maybe ditch make file completely and create project file from ground up, so you could build and debug directly from the IDE?
I have a project in IAR Workbench that requires a custom build step to build an intermediate file; this file is put together from a set of other files with a common extension (i.e. there is an intermediate linking step for the input files in a domain specific language).
It appears to me that the "Custom Tool" can only process a single input file at a time; is this true, or is there a checkmark that needs to be set so all files matching the extension list are passed in a single run?
There is no support for having custom build steps which can consume more than one source file at a time. The custom build step works like a compiler, and not like a linker.
Put the files with a common extension into their own group folder. The right-click the group folder and select options, custom build, override inherited settings.
Then you can use a "make" program to generate the intermediate file from all the secondary source files by putting those filenames into a file that make executes.
yes, the make will be run for every file, but since the intermediate file will be newer than all the secondary source files after the first iteration, it won't do much when called for each of the remaining secondary source files.
Not perfect, but should work. Downside is managing the file listing all the input files to create the intermediate file you need.
In newer workbench versions (I checked EWARM 7.60 and newer) the custom build step accepts a list of files for both the input and output of the tool. These file lists are both added to the internal dependency tree.
The file extension for the custom build step does not necessarily need to match the "real" generated files. You can also use a "fake" file (e.g. dummy.step) to run an external tool with a external batch file, which then provides all necessary files at once to the tool.
The disadvantage of this approach is, that you need to manage the list of files manually and twice (within the external batch file for the tool and within the build step configuration for the correct dependency tree).
In my scenario I have a C++ project in CDT Eclipse. This projects however is rather a collection of individual (helper) programs than one complex application. Consequently I want to be able to build and run them individually.
My project structure is very simple and looks like:
src/app1.cpp
src/app2.cpp
src/...
Note that I do not have common header files or libraries. However I want to be able to add programs to this project just by creating e.g. src/appx.cpp
Ideally I want to have shortcuts for
"Build currently opened .cpp"
"Run binary of currently opened .cpp"
Any suggestions on how to achieve this behaviour, if possible without additional plugins?
The straightforward way to succeed what you aim is to create a Makefile project with CDT and add a new target rule for each of your applications inside your Makefile. You can even use SCons or other build systems with a CDT Makefile project and obtain the same effect.
You can also trick the managed build to create executables instead of object files. Remove -c option from Other flags of C++ compiler settings inside project properties. This will produce a separate application file for each of your source files.
Application files which are created inside the build directory will have the object file extension and they will not be executable. To solve this, you can add a post build script in your project directory such as:
postbuild.sh for Linux:
chmod +x *.o
rename -v 's/\.o$//' *.o
or postbuild.bat for Windows:
rename *.o *.exe
After adding ../postbuild.sh or ../postbuild.bat as a post build command in your build settings, you applications will be ready to run. Right click on any of these executable files and choose Debug As or Run As and a new Run configuration will be created.
Also you will have to stop the linker of the managed build to prevent errors. This can be achieved with changing the linker command to true (Linux) or true.exe (Windows, msys).
I have a tool that generates most (but not all) files that need to be compiled in Visual Studio. The tool reads a configuration file and generates c++ files afterwards. This list can differ from one call to another when the configuration is altered.
I am wondering whether it would be possible to adapt the compiling process to my needs, which would be :
Launch the tool (not needed if configuration file has been modified)
Retrieve new list of C++ files to be compiled (ideally isolated in a folder inside the project)
Compile C++ files
EDIT: Having to close Visual Studio for this process to work is a no-go for me. The idea would be to have cpp files dynamically added as the first step of the compilation process.
Use a pre-build step to run your tool.
Also, create a file containing the list of includes and sources
This file name should be fixed (so that you don't have to change project properties or the vcproj file) -- add it to the project. E.g:
Project Properties > Command Line > Additional Options > #headerListingFile
You are not trying to integrate lex/yacc output with VS, are you?
Would CMake help? It's an automated project manager that generates Makefiles and VS projects for projects you define. Just add a source file, re-run CMake and you're done.
I think what you should do is create a custom makefile and use that for builds.
Please see this page for more information.