cmake4eclipse and -D options - eclipse

I have a CMake project (native Linux) which I imported into Eclipse using cmake4eclipse.
The build process includes downloading some sample data which is rarely needed in production use. Currently this step fails (causing the whole build to fail), which is why I would like to skip it in the build.
The build chain supports skipping tis step. Running CMake from the command line, I would simply do -DSAMPLE_DATA=n.
With cmake4eclipse, where would I specify this option? I have tried adding it in Project > Properties > C/C++ Build > CMake, but it takes no effect.

In Project > Properties > C/C++ Build > CMake, on the Symbols tab, add a new variable. For -DSAMPLE_DATA=n, add SAMPLE_DATA, type STRING, value n.
After that, on the General tab, check “Force cmake to run with each build” and build once. For subsequent builds you can clear the check mark again—you just need to run this once so Eclipse/CMake will pick up the new configuration.

add it on the CMake|Symols tab in the project proerties.

Related

Need some help importing & rebuilding a Github java project

I am attempting to make a little tweak in the source of a GitHub java project and to rebuild it back into resulting .jar file to run.
On the project's URL, README says Download the source and build with gradle.
Downloaded using Clone or download button, extracted
Installed Eclipse 2019-12, then > File > Import > Gradle > Existing Gradle Project..., which gave me
Opened the .java file in the editor to make any tweaks
Now I need some help understanding how can I test and rebuild so I end up with '.jar' file to run? (The GitHub project's already built original .jar files are here)
Would appreciate to learn what further steps to take towards that.
Can you try using gradle wrapper (https://docs.gradle.org/current/userguide/gradle_wrapper.html#sec:adding_wrapper), this may resolve the build issues.
Here's how I finally got it working in Eclipse (Windows), thanks to help by emmanuel-chebbi (See detailed discussion in comments below the question)
Created a Windows environment variable JAVA_TOOL_OPTIONS value -Dfile.encoding=UTF8 ( See this )
The file Commons.java in the project also needed to be changed to UTF-8 NOBOM (just UTF-8 not good for Windows!) So did that ( See this )
Imported the project and overridden Gradle 3.0 to be the default ( File > Import > Existing Gradle Project > select dir > next > override > specific gradle version 3.0 > next > finish )
Any code changes as desired, if any (beyond this question's scope)
Ran default Gradle Tasks ( Gradle Tasks Tab > right-click project > Run Default Gradle Tasks )
Two JARs generated in \distrib folder
By the way, meanwhile I have also been trying to get a non-GUI IDE based solution with Gradle 3.0 command line to work, thanks to suraj-muraleedharan, and will update here if I get anywhere with it. (It's good for me to know there's a direct way than GUI IDE, but at this point, I just want to keep it simple for my limitations' sake — so accepting this as answer since it was posted as an Eclipse question anyway.)
Thank you both for your kind help and patience!

CMake Eclipse project, make targets not available

I use CMake as a build manager for a C++ project. All my sources are in a src subdirectory, and I created a sibling build directory. Following the directions from https://cmake.org/Wiki/Eclipse_CDT4_Generator, the build commands I use are:
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src
This creates the .project and .cproject files used to import an existing project in Eclipse. In the IDE, everything seems to work perfectly, except that the make target does not work.
When I click on a build target, the CDT build console opens, but nothing occurs. Also when I click on Project / Clean in the Eclipse dropdown menus, nothing occurs. I checked the commands invoked by the targets, and they are of the form /usr/bin/make -j8, which should work.
Can anyone help me get the make target work ?
An automatic update to CDT just occurred and everything works now. So check for updates I guess.
Hope this is followed to create target....
The docs for eclipse says:
Your project name should be different from your executable name and different from your build folder name. Otherwise, Eclipse will NOT pick up your executable as you build them. Since my build folder name is certi_build, a CMakeLists.txt file like below should work (notice the difference in project name and executable name)
PROJECT(AwesomeProject)
ADD_EXECUTABLE(AwesomeProjectMain
main.cpp
util.h
util.cpp
)

Force Eclipse CDT makefile to clean file before compiling

I'm using Eclipse + CDT for a project.
I'm using the "generate Makefiles automatically" option from my build settings.
I have in one file the date and some values that must be actualized every time the project is compiled. But since I don't change every time this file the compiler doesn't refresh it.
Is there any option so I can have a Phony target?
if I could just add some lines to the makefile will work
rm -f *.o target
but this will be removed the next time I update my project.
I found that in the settings >> c/c++ build >> behaviour there is an opportunity to write some clean variables. Could this help? I tried to write the file name but this does not work.
You can give CDT a pre-build command. For me (3.6.2 on Linux):
Project → Properties
C/C++ Build category
Settings sub-category
Build Steps tab
Pre-build steps pane
Enter a command to delete the object file in question (rm f.o, or somesuch)
You can user make clean on Pre-build steps
I added the following to the Pre-build steps and it seems to work great:
del ${CWD}\addtional_dir\file.o

Eclipse adding your own build command

I am new to eclipse and wanted to do the following:
Use my custom build commands with eclipse. Until now I only saw make all. I use a shell script for building my project; how can I use that in an Eclipse environment?
When I create a new project with the existing source code, it doesn't add the files, without building the code and if code fails to build (because I generally don't have make all).
How do I resolve this issue?
You can add a custom builder in the "Builders" category of the project properties.
project->properties->builders->new
there you can also deactivate the default eclipse builders..
hope that helped
In addition to what smeg4brains said and assuming that you are using the CDT plugin you can go to:
project -> properties -> C/C++ Build
Uncheck Use default build command on the Builder Settings tab and replace make with e.g. scons.
On the Behaviour tab you can then specify the target to call for the Build and Clean phase.
To resolve your second issue open the Project menu and uncheck Build automatically.
This will prevent Eclipse from building the project when it thinks it is necessary.
If you want to add other your own commands then the easiest way is to write Ant file for your project so by clicking once you can execute all your commands.To see how to write Ant file click here
I was able to do something similar to have protoc run on my .proto files. I did it by adding a "Make Target" to the project.
A lot of stuff in Eclipse you can get around using Ant, which are XML scripts, and there is also a ANT project builder which uses those. If you don't like to mess with frankly quite touchy GUI options, just write a build.xml and use ANT build as the project builder.

Build several CDT C++ projects from commandline

What is the best solution to build several CDT C++ projects from the command line? The projects have references and so it is not possible to just build single projects.
This feature has been added in CDT 6 (Final build due June 15th 2009). You can download the final release candidate from builds page: download.eclipse.org/tools/cdt/builds/6.0.0/.
Using a release of Eclipse 3.5 + CDT 6, you can import, build and clean-build projects and the workspace using the following options sent to Eclipse at the command line:
eclipse -nosplash
-application org.eclipse.cdt.managedbuilder.core.headlessbuild
-import {[uri:/]/path/to/project}
-build {project_name | all}
-cleanBuild {projec_name | all}
On Windows, use eclipsec.exe instead of eclipse.exe to have build output written to stdout/stderr and so that the call blocks until completion.
The '-application' switch instructs Eclipse to run the CDT headless builder rather than starting the workbench. The other switches can be used individually or together. This means you can checkout a project using a shell script of your own, '-import' it into a workspace, and '-build' it using the Managedbuilder's headless builder.
Use the '-data' switch to specify the workspace to use, which can be an empty temporary directory, see the runtime documentation for other switches supported by the platform runtime:
help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
See bug 186847 comment 24 and onwards for more detail on the committed functionality.
Pre CDT 6 you could use the JDT's AptBuilder (included with classic Eclipse, for example).
This lets you build an already configured workspace. So you: checkout your source, configure a workspace which points to the checked-out projects. Your automated build scripts can then update the checkouts and run the AptBuilder without needing to start the GUI.
If you created a Make project under CDT you can just use your favorite shell and execute make in all the projects dirs.
Headless build with the manage builder is currently not supported, see bug 186847 - CDT internal builder does not support automated command line builds.
If you use the unmanaged (make) builder, then you already have Makefiles that you can use from the command line.
We do this in our existing build.
Put a makefile in all your external references and your toplevel project.
In your "all" rule, have it run:
make -C ./externalref1
make -C ./externalref2
etc
we actually define the external dependencies in a variable:
EXT_DEP = externalref1 externalref2
then use the subst (substitute) command to kick off all the sub-makes using the correct call.