Cleanest way for automated dependency management in c++ [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Related question: C++ Build Systems - What to use?
I am struggling to find a nice build / dependency management tool for my c++ project, with the following desired features:
able to specify a dependency by name, version
dependencies' "include" directories are automatically included during compilation of my application
the dependencies are automatically downloaded, built, and linked to my application
transitive dependencies also have the above two behaviours
ability to specify test-scope dependencies
tests are automatically built and run, potentially with a memory leak check tool (e.g. valgrind)
potentially run a coverage tool, e.g. gcov
cross platform supported
I have used Maven, with the [nar-maven-plugin], and sometimes the [cmake-maven plugin]. However, this means I have to craft a [pom.xml per dependency]. This method isn't particularly nice, as at times, a [nasty pom.xml] has to be crafted to get things to work. Also, it doesn't support running valgrind (no support built in yet).
I have attempted using CMake as I've seen many projects use it, but I find that a lot of time is spent on "writing a build/dependency management system" instead of "using it". Yes it's true I can write many functions that go:
function(RequireSomeLib artifact)
# ExternalProject_Add(SomeLib ... etc.)
# find SomeLib package
# add include dirs(artifact SomeLib_INCLUDE_DIRS)
# if SomeLib is not just a header library, also link its built library to the artifact
# for each of SomeLib's dependencies, do this same "call" (transitive dependencies' libraries must also be linked when building an executable)
endfunction()
for each dependency. Tedious, but currently the cleanest way I see going forward.
With the premise that CMake is used by libraries that my project depends on, is there a better method to solving this problem?
I have not seen or tried SCons, AutoTools, or QMake (yet).
In Java, the "retrieve dependencies, build, test, and publish" issue is much simpler ._.

All build systems for C++ will need you to code in dependencies and package detection. Every one of them has been created out of frustration with previous technologies, with the stated intent to remove the need for boilerplate code, and to create a complete, cross-platform, automated, easy to use solution, but at the end of the day, you will end up writing code besides your code for your package to be built.
If you look hard enough, you will find debates among advocates of each build system. I found one of such a couple years ago. Their arguments were so weak that I ended up abandoning the search.
I am a user of CMake for one simple reason: it was the first I could find some years ago that allowed me to spawn different build directories. I'm sure all modern build systems have implemented this idea already, but I stuck with CMake just because I became used to it. Honestly I have found very few sensible advantages over bare bones Makefile. I had to write boilerplate code for my CMakeFiles.txt, even though it was a C++ project without dependencies.
Some time later I decided to try out some different IDEs; I had the good fortune that Qt Creator runs on CMake projects; there is the other reason I stayed on CMake.
My advice to you is to visit each build system's webpage; check out their currently implemented features (not TODOs), comparisons to other systems, IDE support, and the complexity of the code you have to write for them. I am pretty sure you will not find a build system satisfying all of the requirements you have, so you will have to test them thoroughly to see which one works best for you.

Related

What is Cmake? what is its role in the building process? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I really don't understand what "Cmake" is, I know the building process which is consist of:
Preprocessor
Compiler
Assembler
Linker
but where is "Cmake" in this process? what is its role and why do we need it?
I read that, it helps in compiler dependencies, but I don't get it.
please help me to know more about it and thanks in advance.
Cmake is a build system configuration generator. To understand what that is, you must first learn what a build system is (such as make, msbuild).
It's challenging to combine the tools that you've listed for a large project to produce multiple variations of multiple executables and or libraries. The complete build process may consist of a large number of differing commands that must be invoked in the correct order, and may each have a large number of options that must be passed to the tool. This is what a build system automates. It invokes those build tools with appropriate options as described in the configuration that you write for it. They also provide convenient features such as incremental re-compilation (checking whether a translation unit has already been compiled previously, avoiding re-compilation when the source hasn't been changed).
But there is a problem: There are many build systems each of which have their own configuration format, and those build systems are often specific to particular system. In order to compile a project on multiple differing systems (such as windows, linux, osx), you would have to write and maintain configuration for each. This is what a build system generator solves: You write a single configuration, and cmake configures your system specific build system, and you invoke that build system through cmake.
CMake is a cross-platform build tool. The idea is to let you define how to build a C++ project at a higher level of abstraction than however you build on one particular platform.
The issue is that although C++, the language, is independent of platform, how you build on any particular platform is not. Say you are implementing an application and would like to support Windows, Linux, and MacOS. If you do not use CMake or something like it this means that you will have to separately maintain a Visual Studio solution file on Windows, a MAKE file on Linux (say), and an Xcode project file on the Mac -- and this assumes that your application has no third party dependencies. If it does have third party dependencies then handling those in a cross-platform manner is a whole other can of worms. You might use per-platform scripts to manage dependencies, for example.
The idea of CMake and similar tools is to solve this problem. You define how to build your project and find its dependencies once and use the CMake definition across platforms.
Like many build tools, it creates output objects based on input artifacts (e.g. by running a compiler).
It only rebuilds an output object if...
if one of the input has been modified since last time the output object was built
if the build recipe for the output object has changed
This can be done with a classical Makefile also, but writing a Makefile that lists all dependencies for building an output object (including header files for instance) is not trivial.

How to organize large project in several GIT repositories? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a C++ project cat that depends on libzzz library. The libzzz has its own git repository and now I am going to create a repository for the cat project.
How to organize a CMake build scripts for the cat?
option 1: CMake scripts of cat consider libzzz built and installed in the system and cat project provide FindLibZZZ.cmake script that search libzzz in /usr/include/libzzz + /usr/lib/libzzz. But how to deal with non-linux platforms? I presonally don't like this option.
option 2: add some kind of link or dependency in GIT repository cat that would automatically checkout libzzz sources from its origin into some cat subdirectory. So cat's CMakeLists.txt consider libzzz is placed in some cat's subdirectory. How to do that?
If libzzz is also a CMake project, then I'd suggest an alternative approach (let's call it option 3). Rather than relying on libzzz being already available on your system (which can make integrating into CI systems, etc. harder), you may want to consider building it as part of your overall project as well. Instead of trying to add it to cat via git submodules (valid, but has its own downsides, e.g. see here), you can make a top level build (aka superbuild) control the building of both libzzz and cat.
Bringing in external projects into a superbuild is often done using CMake's ExternalProject module. This allows you to download and build a project in one operation. Unfortunately, it does so at build time and provides no CMake targets for you to link against, so you end up having to manually work out the name and location of the library you want to link against from it, etc. Yes, you can robustly predict these for your build, but you have to manually handle all the platform differences. This is what CMake is supposed to take care of for us!
Instead of using ExternalProject in the normal way, you can, however, coax it to perform the download at CMake time. This then makes the external project's source code available immediately and you can call add_subdirectory to bring it directly into the main build. This in turn means any CMake targets defined by that no-longer-external build will also be visible, so you can simply link against those targets. In your particular example, the libzzz build would presumably define a zzz CMake target or similar and in your cat build, you would just add a call like:
target_link_libraries(cat PUBLIC zzz)
No need to manually work out any library names or locations, since CMake now does it for you. The trick to all this is getting ExternalProject to execute at CMake time rather than build time. The method is fully explained here, using GoogleTest as the example. The technique essentially involves using external_process to invoke a small script via CMake's script mode to call ExternalProject_Add immediately. That article includes a link to a fully generalised implementation you should be able to use to perform the downloading of libzzz in your particular case.
I believe that Option 1 is best if you ever plan to distribute the project to others (which it sounds like you do, if you are considering non-linux platforms). If you don’t plan to distribute cat to the wider world, then by all means go with Option 2, which is likely to be slightly easier to implement. However, suppose I want to use cat, and you go with option 2. In that case, there could be several problems:
If I already have libzzz because it’s also used by the dog project, then you are downloading and building something I already have. This is, at the very least, a waste of time.
If libzzz releases a critical security update, then I need to re-download your project also. If I’m lucky, you updated the cat repository to use the new version of libzzz. If I’m unlucky, then you have not noticed the new security update yet, you are in the middle of maintaining a different part of the repository, or you are dead and cat is completely unmaintained. If I’m really unlucky, I don’t notice that cat now needs to update because libzzz released a new version, and I am subject to the security problems.
Your cat project becomes popular. Now package maintainers everywhere need to find out how to compile cat with the existing libzzz from their repository.
I know I’ve seen an article from somebody who actually was a package maintainer arguing for Option 1, but I can’t seem to find it again. If I do, I’ll update this answer with the link.

What is the best way to build C/C++ program in open source community? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
We have a very old and big project which is mainly written by C (and a small piece of C++), and it can be built in both Linux and Windows. Currently, we write all the Makefiles in this project manually which I think is not good.
Now we want to make this project fully open source. However, before that, we want to enhance the way to build this project. So I'd like to know what is the best/popular way in open source community to build such project? I know a bit about autoconf/antomake which seems existing there for quit a long time, just wondering if any new and better way to build C/C++ project come up?
Thanks!
The most "open source" way would be to retool the compiler chain to use autotools.
Basically it permits compilation on one of a number of "unknown" systems by detecting the need libraries and their locations and then writing the makefiles to match the platform.
For C and C++ it is a very good match.
If you want to "push the envelope" Apache's Maven can also compile C and C++ with the NAR plugin. Personally, I really like Apache's Maven; however, if you are not versed with it, NAR plus "learning maven" will be quite a challenge. Meanwhile, everyone who's installed from source on a Linux box quickly becomes familiar with auotmake's "configure; make; make install" routine, so using Maven to do this is really a bit "outside the box".
There is also CMake; however, the benefits of CMake don't really strike me as overwhelmingly different from the more mature autotools tool chain. That said, CMake is a pretty nice setup, which becomes more complex (and matches the automake environment more and more) as it has to support the issues that a mature tool-chain like automake support.
All in all, I'd say stick with autoconf/autotools/automake. There are plenty of examples, and while you might have to leverage the M4 macro language, every part of the build system is readable, and can be leveraged to create your own custom extensions.

How to run console-based target for a library project? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am attempting to create/build/run a second target for a library project in xcode. The library is being consumed by another project in the workspace, and I have:
Created the second target, a console app
Confirmed that the generated main.cpp file is included in the
console target
Cleaned and rebuilt, confirming that the library still builds and
works
However the console target remains unbuilt. I have not received any errors.
Places I have researched looking for higher resolution steps:
Googletest xcode tip (meandmark.com)
Google test project target docs (per my use case)
Should I be using one project with multiple targets?
Build static library target with main target for...
Xcode concepts
Xcode help docs
If you think you can help, I'd be much obliged.
It might not be the answer you are looking for, but if you are new enough to XCode, that setting up a test.cpp to your library is challange enough, you might try another tool that in the long run might prove to be more useful.
CMake is an excellent cross-platform tool that is capable of generating platform-specific makefiles or project/workspace files for various IDE-s, including XCode. So you need to learn only one tool, and you're good for all platforms and compilers.
CMake has a companion app that ships with it, CTest. It is meant for just the thing you are looking for. It basically adds build targets that build a certain app (test.cpp in your case), and check if the return of int main() is zero or not. Multiple tests can be created (all testing different aspects of your library), and CTest provides nice interface to run all tests, just the specified ones and what not, plus it prints runtime of tests and shows which have failed.
CMake and CTest have good documentation, and there are myriads of tutorials available online. It might take some time to master, but in the 2 days time you spent googling, you could've ported your workspace to CMake easily. In the long run, it pays off.

C++ Libraries ecosystem using CMake and Ryppl

I am interested in building a cross-platform C++ Library and distributing it in source form. I want the consumers of this library to be able to acquire it, build it and consume it inside their software very easily on whatever platform they are working on and for whatever platform they are targeting. At the same time while building my library, I also want to be able to consume other popular OSS libraries through a similar mechanism.
I see that CMake and Ryppl were created with these intentions in mind and to some extent they do solve some of these problems, especially the build problem. But I don't quite know how exactly to go about achieving the above mentioned goals. Is it OK to settle on CMake as the build solution? How do I solve the library acquisition and distribution problem? Simply host the sources somewhere and let people discover, download and build them? Or is there a better way?
At the time of writing there is no accepted solution that handles everything you want. CMake gives you cross-platform builds and git (with submodules) gives you a way to manage source-level dependencies if all other projects are using CMake. But, in practice, many common dependencies you project wil need don't use CMake, or even Git.
Ryppl is meant to solve this, but progress is slow because the challenge is such a hard one.
Arguably, the most successful solution so far is to write header-only libraries. This is common practice and means your users just include your files, and their build system of choice takes care of everthing. There are no binary dependencies to manage.
TheHouse's answer is still essentially true. Also there don't seem to have been any updates to ryppl itself for a while (3 years) and the ryppl.org domain has expired.
There are some new projects aiming to solve the packaging issue.
Both build2 and wrap from mesonbuild have that goal in mind.
A proposal was made recently to add packages to the c++ standard which may open up the debate (reddit discussion here).
Wrap looks promising as meson's author has learned from cmake.
There is a good video when its author discussing this here.
build2 seems more oblivious (and therefore condemned to reinvent). However both suffer from trying to solve the external project dependencies issue simultaneously with providing a complete build system.
conan.io is another recent attempt which doesn't try to provide the build system as well. Time will tell if any of these gain any traction.
The accepted standard for packaging C and C++ projects on Unix was always a source tarball + a configure script (autotools) + make.
cmake is now beginning to replace autotools as your first choice.
It is able create RPMs and tarballs for distribution purposes.
Its also worth considering the package managers built into the various flavours of Linux. The easiest to build and install projects are those where most of the dependencies can be pulled in via yum or apt. This won't help you on windows of course. While there is a high barrier to entry getting your own projects added to the main Linux repositories (e.g. RedHat, Debian) there is nothing to stop you adding your maintaining your own satellite repo.
The difference between that and just hosting your project on github or similar is you can provide pre-built binaries for a number of popular systems.
You might also consider that configure times checks (e.g. from cmake findLibrary()) and your own documentation will tell people what needs to be installed as a prerequisite and providing you don't make it too onerous that might be enough.