I cloned a git repository from github (a project called plumed) and in order to install it I used to execute the following commands from the terminal:
> ./configure --enable-debug
> make -j 4
> make install
After that checking that everything was ok I used to execute the command
> which plumed
> /usr/local/plumed
How can I do the same from Eclipse?
Building from eclipse looks like to execute the command "make all" that returns errors.
Here is what I do, hope it helps.
I make a build directory, cd into that and run configure from there. That will produce a Makefile in the build directory. Then I create a Makefile project in eclipse. Open the Makefile. Then, on the right hand side, in the Outline window you can select the make targets you want to use (all, clean, install, uninstall ...).
You can make several build directories for different configurations (build-debug, build-release etc...).
In fact I have a script for each build type that sets various build flags and calls configure with the relevant flags:
#!/bin/bash
top_dir=$(pwd)
PREFIX=${PREFIX:-$HOME/dev}
LIBDIR=$PREFIX/lib
WITH="$WITH --with-mysql=yes"
WITH="$WITH --with-speller=yes"
export PKG_CONFIG_PATH="$LIBDIR/pkgconfig"
export CXXFLAGS="-g3 -O0 -D DEBUG"
rm -fr $top_dir/build-debug
mkdir -p $top_dir/build-debug
cd $top_dir/build-debug
$top_dir/configure $WITH --prefix=$PREFIX
In eclipse I always make the --prefix point to install within the $HOME folders so you don't need root privilege to install everything.
Related
I have to merge cmake's makes and makes in our build systems. The build systems are supposed to be able to work with both options make and cmake. The problem is that cmake's make exports do not contain all variables and settings, which need to be set as make in our build systems. Basically, we use three complicated build systems for cross platform development and I do not like setting everything on many places, because then it is hard to maintain the system like that.
E g. makefiles from many coders in all build system contains include common file like:
include $(PROJECT_CONF_DIR)/common/something.mk
How to solute it by cmake? I do not like modifying coders' CMakeLists.txt (max. one row solution for them) and I also do not like modifying cmake exports into make files.
Basically, I need to put somewhere in cmake command or cmake's export (the best) some link which will lead to include all 'garbage' expecting by our build tool chains.
Make sure that CMakeLists.txt can contain many cmake subprojects and libraries.
e.g. Our build system from makefiles contains something like:
directories-default:
mkdir -p $(BUILD_DIR)
mkdir -p $(OBJ_DIR)
I need to implement it somehow in cmake include.
To be able to run make directories-default after configuration, you have to create a target. You can make a target that will call a custom command, which would run the shell commands you need.
add_custom_target(directories-default COMMAND mkdir -p "dir1" COMMAND mkdir -p "dir2")
The syntax above will result in a target that is always considered out of date, ie every time you run make directories-default (or make all), the commands will be executed. If you don't want to re-run the command every time you can use a custom command:
add_custom_command(OUTPUT "dir3" "dir4" COMMAND mkdir -p "dir3" COMMAND mkdir -p "dir4")
add_custom_target(directories-default2 DEPENDS "dir3" "dir4")
Here make directories-default2 will only run the commands the first time you run it. You can also create a dependency chain of commands using the DEPENDS argument in add_custom_command.
I don't have much knowledge about cmake. I installed a package libfreenect2 following the instructions on their github page. The instructions were as follows-
Clone the repository. And follow the cmake step:
cd ..
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
make
make install
However, after installing I realised the program/package that required libfreenect2 as a dependency required me to use:
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -DENABLE_CXX11=ON
You may have noticed, it required me to use an extra flag -DENABLE_CXX11=ON. How can I fix this? How can I set ENABLE_CXX11=ON after the whole make process has been completed? By the way what does -D do? (are these -DXXX things called options or flag)
In case your answer is to repeat the whole process again then kindly guide me through the step by step process of deleting the correct files. I don't want to delete other dependencies.
Here are some other stackoverflow answers relating to cmake-
set cmake option(), cmake option to include a directory, What does cmake do
SOLUTION - I used the accepted solution to enable the flag. Even though it worked for my problem (libfreenect2) still it will be amazing if someone could provide an answer which doesn't involve reinstalling.
My warm suggestion would be to repeat the process with that option ON.
First you should delete what was previously generated.
The sequence of commands to follow is the following:
rm -rf build
rm -rf $HOME/freenect2
just to be entirely sure you start from a "clean state".
I don't see the need to do rm -rf $HOME/freenect2 as that files/dir will be overwritten by the new install, but shouldn't hurt.
You can also try the suggestion in the SO post mentioned in one of the comments.
Then repeat the process from the root dir of libfreenect2:
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -DENABLE_CXX11=ON
make
make install
Alternatively, if you're entirely sure that you will build libfreenect2 always with that option ENABLE_CXX11=ON, you could explicitely set it ON once and for all in the CMakeLists.txt of libfreenect2, specifically changing the line:
OPTION(ENABLE_CXX11 "Enable C++11 support" OFF)
into
OPTION(ENABLE_CXX11 "Enable C++11 support" ON)
In this last case, you will just need to do
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
make
make install
of course after you've cleaned as explained at the beginning.
About -D for CMake, it allows you to pass options. Directly from the documentation:
-D <var>:<type>=<value>
Create a cmake cache entry.
When cmake is first run in an empty build tree, it creates a
CMakeCache.txt file and populates it with customizable settings for
the project. This option may be used to specify a setting that takes
priority over the project’s default value. The option may be repeated
for as many cache entries as desired.
So if there's some project default options that one wants to change/overwrite than it can be done with this.
... Sorry, this has to be a duplicate, but I'm just running across answers for people who are making their own projects and can change the build system setup.
Can I always compile a program in a separate build directory, or must it be supported by the program's build system?
For vim, you compile using: "./configure && make && sudo make install". If I'm in vim.hg.build and run "../vim.hg/configure .....", I get :
../vim.hg/configure: line 6: cd: src: No such file or directory
For git, you compile using: "make configure && ./configure && make && sudo make install". I was hoping being in git.git.build and running "make --directory=../git.git configure" would work, but that leaves the configure file in ../git.git. Well, maybe just configure left behind isn't so bad, so I then tried "../git.git/configure" which successfully created config.status, config.log, and config.mak.autogen in the build directory. But running make gives:
make: *** No targets specified and no makefile found. Stop.
... Yes, the only Makefile is in git.git itself.
I even tried symlinking the entire directory by running:
for fl in `ls -a ../vim.hg`; do
echo "$fl"
ln -s ../vim.hg/$fl $fl
done
... But, vim's configure and make only modify existing files and subdirectories, so even though I can build this way, the build directory is left with nothing more than symlinks -- no actual separation.
Go cmake!
Out-of-tree building is a feature of Autotools that requires both Autoconf and Automake.
Vim and Git both only use Autoconf and not Automake, so they can't take advantage of that feature.
As a more general answer to your question: simple Autotools projects should work with out-of-tree builds automatically. When using certain advanced features, a bit of care must be taken to ensure that out-of-tree builds continue to work. Sometimes projects don't do this.
(Running make distcheck will test out-of-tree building, so it's a good idea to run it at least once before making a release.)
I just want to know what do I need to write in the Makefile.am to create a directory called build in the same directory where Makefile.am is.
Think about your question carefully: Do you really want to create build in the same directory as Makefile.am, or in the current working directory when configure is called? These are not always the same thing: the GNU build system is meant to support out-of-tree builds (with a potentially read-only $srcdir), so the end user should expect the following to work:
$ tar xf autofoo-1.2.tar.gz
$ mkdir autofoo-build
$ cd autofoo-build
$ ../autofoo-1.2/configure
$ make
$ sudo make install
Now, the easiest way I have found to create a directory is not to use Makefile.am at all, but instead to make config.status do it (which is the shell script that does all of the template substitutions at the end of configure, turning Makefile.in into Makefile, config.h.in into config.h and so on). In configure.ac, put the following:
AC_CONFIG_COMMANDS([mkdir], [$MKDIR_P build])
You would need to write:
build:
test -d ${srcdir}/build || mkdir ${srcdir}/build
but you really do not want to do that. The source directory should be considered read-only. If you simply want to create a directory named build in the build directory, just do
build:
test -d build || mkdir build
I'm using Eclipse CDT on Linux to build a c++ executable and several static libraries which the executable depends on.
Everything is good - Eclipse generates the makefiles for both Debug and Release as expected.
However, I want to compile this code also on a computer without Eclipse installed, so I thought to write a simple makefile which calls the Eclipse makefile.
So I started with something like:
all:
cd Lib1/Release && make all
cd Lib2/Release && make all
...
cd Exec/Release && make all
This works for Release only, as you see...
How can I change the makefile so I can use the selected user's configuration ?
Thank you very much.
With this in your makefile you can invoke 'make debug' or 'make release' to build all the projects in the required mode :
config:
cd Lib1/$(CONFIG) && make all
...
cd LibN/$(CONFIG) && make all
cd Exec/$(CONFIG) && make all
debug:
make config CONFIG=Debug
release:
make config CONFIG=Release
.PHONY: debug release config