How do you change the cmake generator in Eclipse? - eclipse

For some reason it forces -G Ninja when I try to build within eclipse. I would prefer Eclipse just not specify the -G option to cmake, but I can't figure out how to configure Eclipse to do that.
For exampe, this in my console window:
Building in: /home/bgass/eclipse-workspace/scomlib/build/default
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /home/bgass/eclipse-workspace/scomlib
CMake Error: Error: generator : Ninja
Does not match the generator used previously: Unix Makefiles
Either remove the CMakeCache.txt file or choose a different binary directory.
cmake --build . -- -v
GNU Make 4.2.1
Built for x86_64-redhat-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Build complete (0 errors, 0 warnings): /home/bgass/eclipse-workspace/scomlib/build/default
In a terminal it works just fine without the generator specified.
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON /home/bgass/eclipse-workspace/scomlib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bgass/eclipse-workspace/scomlib/build/default

I always execute cmake outside eclipse and open the generated eclipse project in Eclipse.
use -G "Eclipse CDT4 - Unix Makefiles" to specify Eclipse as the generator.
Following are the full set of Eclipse generators.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Type in cmake --help to see what generators are supported by your specific cmake version.

Related

Creating Eclipse CDT using CMake on Windows

I am trying to create a simple helloworld Eclipse CDT project using the CMake GUI. The CMake file looks like this:
cmake_minimum_required(VERSION "3.11.1")
project("HelloWorld")
add_executable("HelloWorldMain" "Main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "Main.cpp" DESTINATION src)
The only c/c++ compiler I have is MSVC so I set that as the CMAKE_CXX_COMPILER but I get an error when configuring as shown here:
I know this file exists, but how do I get it to find it?
I ended up not using the GUI. Instead I used the VS x64 Native Tools Command Prompt then ran the cmake command:
cmake -G "Eclipse CDT4 - NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j8 ../

Use Makefile + Eclipse + Mac + g++ + mpic++

I have installed gcc 5.3.0(g++) and compiled mpich(mpic++) using that.
I already have my own Makefile, when i make from command line everything perfectly.
I also imported the project to eclipse PTP (Mars) and set the build option to make and set build folder to my source folder. Added my mpic++ and g++ paths to eclipse path environment variable.
When i build from eclipse, it finds and executes my make command, it even finds out my mpic++ but internally its using clang but not gcc
When i check mpic++ version on command line, i get
MacBook-Pro:mpi$ mpic++ --version
g++ (GCC) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And i added the same command to my make file so that i can check whats happening on eclipse, I get this
( mpic++ --version; )
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
So i am not sure what i missed here. How do i change my eclipse to use gcc instead of clang?
Thanks in advance.

How to choose a specific MinGW installation for eclipse CDT

I am using 32-bit eclipse CDT Kelper to manage a piece of code, which I could compile on command line but not with eclipse if I use any up-to-date c++11 feature. CDT tells me that "-std=c++11" is unrecognized.
After turning on the verbose option in project properties\settings\tool settings, I found that eclipse CDT somehow chooses an older version of MinGW that comes with Haskell platform 2013.2:
Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.2 (GCC)
COLLECT_GCC_OPTIONS='-O0' '-g3' '-Wall' '-c' '-fmessage-length=0' '-v' '-o' 'src\vaomp_bnb.o' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/haskell platform/2013.2.0.0/mingw/bin/../libexec/gcc/mingw32/4.5.2/cc1plus.exe -quiet -v -iprefix c:\haskell platform\2013.2.0.0\mingw\bin\../lib/gcc/mingw32/4.5.2/ -dD ..\src\vaomp_bnb.cpp -quiet -dumpbase vaomp_bnb.cpp -mtune=i386 -march=i386 -auxbase-strip src\vaomp_bnb.o -g3 -O0 -Wall -version -fmessage-length=0 -o C:\DOCUME~1\ting\LOCALS~1\Temp\ccWNoh7I.s
GNU C++ (GCC) version 4.5.2 (mingw32)
I searched SO, and there is a similar question a half year ago here. But the answer there was about setting environment variables and didn't solve the problem.
In my case, CDT can find a MinGW GCC, but found the wrong one. I have installed tdm-gcc 64 bit with gcc-4.8.1, and Haskell platform. The tdm-gcc has priority and
gcc --version
on both DOS and MSYS shows
gcc.exe (tdm64-2) 4.8.1
I don't know what heuristic does CDT use to find toolchains. My question is, how can I tell CDT to use the gcc in a specific location, e.g. c:/MinGW?
Note, I can't uninstall the Haskell platform version of gcc as I will need HP.
Thanks,
I figured it out. It seems that Eclipse CDT does not take tdm-gcc MinGW 64-bit because eclipse itself is 32-bit. So it picked up the only 32-bit MinGW it can find, which is the old version from HP.
To verify this, I installed java 1.7 64-bit, and downloaded 64-bit version of Eclipse CDT (Kelper). Now, CDT automatically selects the TDM-GCC 64 version of MinGW gcc.
For those in a similar situation, one additional issue is that the 64-bit CDT - MinGW64 combination combination does not build projects. No binary/executable files are generated even for a newly created HelloWorld c++ project (even though compilation is OK). In my case, I changed the build tool in the project properties..\tool chain. from CDT internal builder to either of the other two options (one is Gnu's and another is a long name), and then the project can be successfully made to generate exe files.

cmake doesn't recognize CMAKE_ECLIPSE_VERSION setting

I'm trying to generate an eclipse .project and .cproject from an existing cmake file. Running cmake from the project root I tried adding to the root CMakeLists.txt
set(CMAKE_ECLIPSE_VERSION=4.2) which apparently might do nothing as it is a local variable, not the global env variable, if i understand correctly.
Trying to add the flag to the commandline like this:
cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_VERSION=4.2 .
Produces the following warning. So how does one let cmake know the eclipse version?
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
I checked the .project file and it seems to be using cdt 4. Pretty old.
kesten
I had the same problem and after looking at CMake's code I noticed that the actual variable used to get the Eclipse's version is named _ECLIPSE_VERSION (starting with underscore) and not CMAKE_ECLIPSE_VERSION. Here's what the code looks like:
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.2 .
That worked for me!
EDIT: Older versions of CMake don't recognise Eclipse 4.2 (which uses CDT 8.1) but does recognize 3.7 (which uses CDT 8.0). I used -D_ECLIPSE_VERSION=3.7 and Juno picked up well the project configuration (previously I had unresolved inclusions due to incompatibility of the CDT4 files generated by default). As pointed out by m3tikn0b, newer versions of CMake do recognize until Eclipse Kepler 4.3.
There is a bug in CMake. See 0014422: CMAKE_ECLIPSE_VERSION is not taken into account. THe issue tracker says it will be corrected in cmake 2.8.13.
same problem here. After search i found the following solution:
previously tried:
cmake -G"Eclipse CDT4 - Unix Makefiles" -D_ECLIPSE_VERSION=4.2 ../src
and it doesn't work. Then i tried:
cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_VERSION=4.2 ../src
This worked for me.. I hope it helps.

cygwin gcc 4.7+ in Eclipse CDT updating from 3.4

I've followed the steps on the Cygwin wiki for updating my version of gcc. Now I have two installations of gcc in Cygwin: 3.4 in /bin and 4.7 in /usr/local/bin. Now, in Eclipse the only way to use it seems to be changing the invocation command from g++ to C:/cygwin/usr/local/bin/g++, and this has to be done for all projects. Is there any way to make Eclipse CDT use this by default? I have changed the Path environment variable, and typing g++ --version in a command line gives 4.7, but building a project in Eclipse with --version still gives 3.4