Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Maven for C/C++ projects

I'm putting Maven build around cluster of amateur, poorly written and frankly - primitive C/C++ code (meaning some C, some C++). Problem is - there's lots of it in circulation currently and cannot be easily replaced. Building it requires a lot of tribal knowledge (you have to go from cube to cube just to find out how to compile/build various parts) and releasing is total nightmare. (No - I'm not going to rewrite it, plz don't ask) My question is - should I use maven-native-plugin to replace multitude of short makefiles or use exec-maven-plugin to simply execute these? I had pretty good experience so far with the latter doing .NET and don't know if I should invest into native plugin or stay with exec? If you had experience with "Mavenizing" C/C++ I would love to get some advice.

like image 717
Bostone Avatar asked Oct 09 '09 04:10

Bostone


People also ask

Can Maven be used for C++?

I'm quite happy with the result, the usual maven commands can be used to grab dependencies, compile, clean, and deploy. I would definitely use Maven for dependency management for C and C++ projects, or really any other situation where you need it, and it isn't already provided for whatever reason.

What is Maven project and why is it used?

Maven is written in Java and is used to build projects written in C#, Scala, Ruby, etc. Based on the Project Object Model (POM), this tool has made the lives of Java developers easier while developing reports, checks build and testing automation setups.

What is Maven with example?

Maven is a popular open-source build tool that the Apache Group developed for building, publishing, and deploying several projects. Maven is written in Java and is used to create projects written in C#, Scala, Ruby, and so on. The tool is used to build and manage any Java-based project.

How do you create a Maven?

To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.


2 Answers

I highly recommend the maven-nar-plugin. I find it superior in many ways to the alternatives. It doesn't require listing out source files, handles multiple OSes and architectures, handles unit and integration tests, and generally follows "the maven way". It introduces a new kind of packaging - the NAR, or "native archive", that contains the artifact you care about (.dll, .so, .a, .exe, etc.) but also metadata, headers, etc. in a way that makes sense.

It does require a bit of up front work to package third-party software up into NARs, but its pretty straightforward. Once they are NARs, you simply use the normal Maven dependency mechanism to link with them, for example:

<dependency>
  <groupId>cppunit</groupId>
  <artifactId>cppunit</artifactId>
  <scope>test</scope>
</dependency>

One drawback is that it does not appear to be actively maintained, but it is full-featured and is a rather impressive example of Maven plugin authoring.

like image 107
SingleShot Avatar answered Oct 10 '22 15:10

SingleShot


To have an equivalent at Maven (Java). My advice is to use CMake + CPM for build and PKG management, most commun tools used in C++ world. As an alternative Gradle exist also for C++.

useful link: https://medium.com/swlh/cpm-an-awesome-dependency-manager-for-c-with-cmake-3c53f4376766

like image 1
Chris Hess Avatar answered Oct 10 '22 14:10

Chris Hess