Maintaining multiple builds for different compiler versions - c++

I am developing a C++ library and I use a Makefile to compile and create a build. I wish to maintain multiple builds for different gcc compiler versions. What is the best way to do this?

If you are ready to go with autotools, autoconf/automake let you do this through out of tree builds. You can configure as many build you want if you separate each build into its own directory (not the source directory).
Configuring compiler and compiler options is usually a simple matter of bash command line.
mkdir mingw-build
cd mingw-build
CXX=mingw32-g++ ../myproject/configure ...
cd ..
mkdir native-build
cd native-build
CXX=g++ ../myproject/configure ...
cd ..

Related

Automate CMake build using C++ script

I would like to automate the build of CMake using an MSVC C++ script instead of using CMake-gui to generate the build or CMake terminal or using the CMake integrated on MSVC 2017 by right click on the CMakeLists.txt to build it manually. Assume we have a project (name it: initialize) that includes the CMakeLists.txt and initialize.cpp, so my question is how I can convert these commands into a C++ code, assume build_initialize.cpp:
mkdir build
cd build/
cmake ..
So, the requirement of this tiny C++ code is to
Set the path to this project
Create build folder
Run CMake
At the end if I execute build_initialize.exe, the job is just to build the initialize.cpp using CMake. The goal is to test if the build is success or not as a test case within another project that has several test cases.
You may ask, why I didnot include it to the top CMakelists.txt, and then build it from the beginning using CMake. If I am going to do that, I will get an executable file. As a result, by running the ctest of CMake, the initialize.exe will require a pace of hardware. This is not the goal. My goal is just to build it. If I run build_initialize.exe, just repeat the build using CMake without initialize.exe execution.
Sorry, it could be very simple, but I lack the good experience either in C++ or CMake. Two days have been lost without success.
Thanks to all of you for the comments. The answer has been given by #Fred. To run cmake from C++ script, simply the system() can be used such as: System(cmake -S path_to_src -B path_to_bld).
Useful link: https://faq.cprogramming.com/cgi-bin/smartfaq.cgi?id=1043284392&answer=1044654269

How can I use mlpack in Cython?

I downloaded the source files, but I don't know how to combine it with Cython. Is there a Cython wrapper for mlpack?
mlpack's build infrastructure will automatically generate Cython bindings; all you need to do is the usual build instructions:
mkdir build && cd build
cmake ../
make && sudo make install
Just make sure that when you configure with CMake, the necessary dependencies are available (the output from CMake will tell you).
You can also see http://www.mlpack.org/docs/mlpack-git/doxygen/build.html for more details.

How can I keep CMake build artifacts when switching branches?

I have been working on LLVM, which uses CMake as a build system. I can create an out-of-source build as follows:
mkdir build
cd build
cmake ..
make
This works reasonably well when I am working on one branch, since Make can reuse build artifacts.
However, when I switch branches, a CMakeLists.txt file may have changed. To be sure I am running the corresponding binary of my current source-code, I run:
rm -rf build
mkdir build
cd build
cmake ..
make
This is inefficient, because I loose all build artifacts. Ideally, CMake would only rebuild what has changed.
How can I achieve incremental builds using CMake whilst switching branches and also be guaranteed build correctness?
This is how I use it and I am happy with it (for simplicity assume that I have 1 CMakeLists.txt) in entire repo:
/
/src
/src/repo1 (on branch1)
/build
/build/repo1_branch1
/build/repo1_branch2
so when I want to generate cmake files from branch1
cd /src/repo1
git checkout branch1
cd /build/repo1_branch1
cmake /src/repo1
for the other branch I'd simple replace two middle lines...
In addition you can make more folders for Release and Debug configurations etc.
I realize that this way is not ideal but it's clear consistent and could be automatized. So script would get repo name (root folder name), branch name, create a folder in fixed location with name repo_name+branch_name (like /build, or ok /home/user/builds) go there and run cmake.

Quick help in rebuilding an automake project

I got the source code of a project (which I can't reach the author any more), that uses automake. I'm not familiar with system and all I want to do is rebuild the project.
I have the following files in the project:
Makefile.am
Makefile.in
Makefile
I've modified the Makefile.am file to fit the paths on my system, but how should I run it regenerate the Makefile.
Note: I'm not currently interested in learning automake, just recompiling this project.
to bootstrap an autoconf build-system, you might use
$ autoreconf -fiv
which will call automake, aclocal, autoheaders as needed, and generate the configure script. after that ou can do the usual
$ ./configure && make && make install
as proposed by milos_ladni
but you will definitely need configure.ac (or configure.in if it's an older project), else the project is simply missing some core parts.
if those are missing, you could go and try to modify Makefile directly (good luck), but it might be easier to just recreate a configure.ac from scratch (and hope that the project doesn't have too many dependencies)
$ ./configure --prefix=some_directory
$ make
$ make install
http://inti.sourceforge.net/tutorial/libinti/autotoolsproject.html#AP05

Can't run Makefile.am, what should I do?

I got a C project to compile and run in Linux. It is a very big project with many subdirectories. Inside the parent directory there are files Makefile.am and Makefile.in.
I tried running make -f Makefile.am, and got the following error:
make: Nothing to be done for `Makefile.am'.
What does it mean? How do I accomplish my task?
These files are used with the Autotools suite. Makefile.am files are compiled to Makefiles using automake.
Have a look to see if there is a configure script in the directory. If there is, then type:
./configure
If not, then run:
autoreconf
in the directory, which should create the configure script (you will need to have the Autotools suite installed to run this).
After that, you should have a configure script that you can run.
After the configure is complete, you should have a normal Makefile in the directory, and will be able to run
make
What has been left out:
Makefile.am are transformed to Makefile.in using automake.
Makefile.in are transformed to Makefile by running configure.
Neither of these (Makefile.{am,in}) are supposed to be used with make -f.
If the tarball already ships with configure, just run that and make. If it does not, run ./autogen.sh or bootstrap(*). If that does not exist, use autoreconf instead.
(*) autogen/bootstrap: A convenience script added by developers that should just call autoreconf. Unfortunately there are some people that eschew autoreconf and unnecessarily call all the lowlevel commands themselves.
To supplement what has already been said:
Search for a script called configure in the project directory. If it is there, building the project will be:
./configure
make
and optionally, to install:
sudo make install
or su -c "make install"
Even if there is no configure script. there might be one autogen.sh. Run this script to generate the configure script and do as above.
Makefile.am is probably to be used with automake.
try:
automake
you might also just want to try
make -f Makefile.in
Since this is the product of running automake