Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I setup a C++ project on github so that it is portable?

I would like to start a C++ project on GitHub such that I will be able to clone/build on different operating systems (for example, OSX and unix). There will be lots of dependencies that need to be installed (for example curl, libxml2, etc), and much as possible I'd like to avoid having the user need to manually install the deps on the system. Is it possible to do this?

like image 462
statguy Avatar asked Apr 06 '13 02:04

statguy


People also ask

How do I run a project directly from GitHub?

On GitHub.com, navigate to the main page of the repository. Above the list of files, click Code. Click Open with GitHub Desktop to clone and open the repository with GitHub Desktop. Follow the prompts in GitHub Desktop to complete the clone.

How do I implement a project in GitHub?

Click Projects (classic) Click New Project. Type a name and description for your project board. Optionally, to add a template to your project board, use the Template: drop-down menu and click a template. Under "Visibility", choose to make your project board public or private.


2 Answers

It depends on how much you want to bite off.

The short answer is let CMake do the work. It will generate projects for whatever platform and they should be usable. You don't need to distribute binaries for this, assuming they are readily available to you (and to them, by extension).

Here is an example that sets up sqlite, boost, and eigen that I used for one of my projects.

cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)

# boost
find_package(Boost 1.42.0 REQUIRED )
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

find_package(Eigen REQUIRED)
include_directories(${EIGEN_INCLUDE_DIRS})

find_package(Sqlite3 REQUIRED)
include_directories(${SQLITE3_INCLUDE_DIR})

set(CMAKE_CXX_FLAGS "-std=c++0x")

include_directories(.)

link_libraries(
    ${Boost_LIBRARIES}
    ${SQLITE3_LIBRARIES}
)

add_executable(igd_sqlite
    main.cpp
)

You'd take this and generate visual studio projects, makefiles, etc. Then build the project as you normally would.

CMake supports lots of libraries out of the box, though sometimes you do have to google for less popular ones and add them to your project.

I use it for my day-to-day work, even when I don't need cross platform.

When I do actually want to distribute binaries, I usually setup an external folder with the binary files.

Here is an example:

https://github.com/tomisarobot/curl_race

This works great if you don't have a lot of external dependencies and if they aren't huge. When that isn't the case, then I'd recommend putting each plattform in different repositories. Your source should be in its own too. You can use subprojects if you want, though that isn't strictly necessary. External deps dont change that often, so its not always worth the overhead. Usually I just write a bash script to document where to get everything. This script is usually necessary for a distribution build anyway.

Things like the maven-nar-plugin exist, though I am unaware of its maturity. If you're just creating all the binaries to distribute with your source anyway, then maybe it isn't that attractive. I don't see a lot of talk about it, so I assume adoption is low. Having seen what maven does for Java, it should be more popular.

like image 114
Tom Kerr Avatar answered Sep 25 '22 10:09

Tom Kerr


Few thoughts

1) Tools

  • When possible, include the tool sources in the repository so that one can build them as a first-time-only step

  • When not possible, clearly specify what minimum version of what tool is required so that the user can install them herself

    • Possibly check if the dependency requirements are satisfied by running a script

2) Language

Compile with strict language compliance. For example

   g++ -std=c++11 -pedantic
like image 43
Arun Avatar answered Sep 22 '22 10:09

Arun