Giter Site home page Giter Site logo

dmc's Introduction

The problem

When you develop C/C++ projects, it's quite hard to handle your development environment. For a long time, I end up with Makefile full of commands to prepare the build environment. This command was in charge of installing needed libraries using tools like apt/macport/hombrew.

This approach is not crossplatform and doesn't manage library version you used => When two projects on the same CI server depends on two different versions of a library, it can become a nightmare.

I solve this problem by using CMake and its new ExternalProject command. Within a CMakeLists.txt file I define the External Libraries I used and how to install it.

But it's hard to share the ExternalProject recipes I have written: To do so, you have to put it on the web and other developers will have to:

  • find it searching on GitHub/Bitbucket/GoogleCode ...
  • copy it to their CMakeLists.txt file
  • Use it

The project

Usage

From a file defining the list of dependencies (libraries/tools), the C/C++ developer will be able to prepapre his build environment.

    dmc 'Igloo', '~> 0.8'
    dmc 'HippoMock', '~> 3.1'

Preparing build environment will mean the following steps:

  • Fetching/loading recipes to generate a first CMakeLists.txt file (with ExternalProject_Add commands) used to install libraries.
  • Launching CMake a first time to install these libraries at a given location
  • Generating a CMakeLists.txt file that contains informations about where to find headers and libraries
  • Launching CMake a second time to generate the build environment of your choice (GNU Make, Code::Blocks, Visual Studio, XCode ...)

Dependencies handling

In a first time, DMC will only install libraries that are defined inside the dependencies file. You will have to handle dependencies by your self: If your project depends on Cinder you will have to specify Cinder and Boost

In a second time, we will handle dependecies by ourself: you will just need to specify Cinder and we will install the Boost version as indicated inside Cinder recipe.

CMake: ExternalProject_Add command

From version 2.8 CMake comes with a new ExternalProject set of commands that allow to define how to download, build and install external libraries/tools. It's really usefull, but you can't use find_package to check headers/libraries existence and link your project with them. Indeed, at the time CMakeLists.txt file is parsed, these ExternalProject packages (headers/libraries) have not been handled by CMake => they cannot be found.

The best practice is to build and install all the ExternalProject packages in a known location (${CMAKE_SOURCE_DIR}/vendors) and to add these locations to the build process with link_directories/include_directories:

	ExternalProject_Add(AnExternalLibrary
		...
	)
	
	link_directories(${CMAKE_SOURCE_DIR}/vendors/libs)
	include_directories(${CMAKE_SOURCE_DIR}/vendors/include)
	// Specify libraries our app should be linked to
	target_link_libraries(MyApp AnExternalLibrary_Name)
	// To be sure that ExternalProject is run before trying to build 
	// MyApp
	add_dependencies(MyApp AnExternalLibrary)

Existing solutions

Idea is too provide tools like gem or pip but for C++ developers.

Closest solution is CocoaPods that manage library dependencies for Objective-C projects. It downloads libraries and make them available generating adapted XCode workspace file.

dmc's People

Contributors

bcachet avatar

Stargazers

Bulk0815 avatar

Watchers

James Cloos avatar Bulk0815 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.