Giter Site home page Giter Site logo

william-froelich / cmake-conan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from conan-io/cmake-conan

0.0 0.0 0.0 145 KB

CMake wrapper for conan C and C++ package manager

License: MIT License

Shell 1.83% CMake 59.85% C++ 2.25% Python 36.07%

cmake-conan's Introduction

cmake-conan

Build status

Build Status

CMake wrapper for the Conan C and C++ package manager.

This cmake module allows to launch conan install from cmake.

The branches in this repo are:

You probably want to use a tagged release to ensure controlled upgrades.

You can just clone or grab the conan.cmake file and put in in your project. Or it can be used in this way. Note the v0.12 tag in the URL, change it to point to your desired release:

cmake_minimum_required(VERSION 2.8)
project(myproject CXX)

# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
   message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
   file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.12/conan.cmake"
                 "${CMAKE_BINARY_DIR}/conan.cmake")
endif()

include(${CMAKE_BINARY_DIR}/conan.cmake)

conan_cmake_run(REQUIRES Hello/0.1@memsharded/testing
                BASIC_SETUP 
                BUILD missing)

add_executable(main main.cpp)
target_link_libraries(main ${CONAN_LIBS})

conan_cmake_run() options

CMAKE_TARGETS

If you want to use targets, you could do:

include(conan.cmake)
conan_cmake_run(REQUIRES Hello/0.1@memsharded/testing
                BASIC_SETUP CMAKE_TARGETS
                BUILD missing)

add_executable(main main.cpp)
target_link_libraries(main CONAN_PKG::Hello)

This will do a conan_basic_setup(TARGETS) for modern CMake targets definition.

CONANFILE

If you want to use your own conanfile.txt or conanfile.py instead of generating a temporary one, you could do:

include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt  # or relative build/conanfile.txt
                BASIC_SETUP CMAKE_TARGETS
                BUILD missing)

The resolution of the path will be relative to the root CMakeLists.txt file.

KEEP_RPATHS

include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
                BASIC_SETUP KEEP_RPATHS)

NO_OUTPUT_DIRS

include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
                BASIC_SETUP NO_OUTPUT_DIRS)

Pass to conan_basic_setup(NO_OUTPUT_DIRS) so conanbuildinfo.cmake does not change the output directories (lib, bin).

ARCH

include(conan.cmake)
conan_cmake_run(ARCH armv7)

Use it to override the architecture detection and force to call conan with the provided one. The architecture should exist in settings.yml.

BUILD_TYPE

include(conan.cmake)
conan_cmake_run(BUILD_TYPE "None")

Use it to override the build_type detection and force to call conan with the provided one. The build type should exist in settings.yml.

PROFILE

include(conan.cmake)
conan_cmake_run(PROFILE default)

Use it to use the default conan profile rather than inferring settings from CMake.

CMAKE_BUILD_TYPE

To use the cmake_multi generator you just need to make sure CMAKE_BUILD_TYPE is empty and use a CMake generator that supports multi-configuration.

SETTINGS

include(conan.cmake)
conan_cmake_run(...
                SETTINGS arch=armv6
                SETTINGS cppstd=14)

INSTALL_FOLDER

Provide the conan install --install-folder=[folder] argument:

include(conan.cmake)
conan_cmake_run(...
                INSTALL_FOLDER myfolder
                )

GENERATORS

Add additional generators. It may useful to add the virtualrunenv-generator:

include(conan.cmake)
conan_cmake_run(...
                GENERATORS virtualrunenv)

Other macros and functions

conan_check()

Checks conan availability in PATH. Arguments REQUIRED and VERSION are optional.

Example usage:

conan_check(VERSION 1.0.0 REQUIRED)

conan_add_remote()

Adds a remote. Arguments URL and NAME are required, INDEX is optional.

Example usage:

conan_add_remote(NAME bincrafters INDEX 1
            URL https://api.bintray.com/conan/bincrafters/public-conan)

Creating packages

This cmake wrapper launches conan, installing dependencies, and injecting a conan_basic_setup() call. So it is for end-users only, but not necessary at all for creating packages, because conan already downloaded and installed dependencies the moment that a package needs to be built. If you are using the same CMakeLists.txt for both consuming and creating packages, consider doing something like:

if(CONAN_EXPORTED) # in conan local cache
    # standard conan installation, deps will be defined in conanfile.py
    # and not necessary to call conan again, conan is already running
    include(${CMAKE_BINAR_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
else() # in user space
    include(conan.cmake)
    # Make sure to use conanfile.py to define dependencies, to stay consistent
    conan_cmake_run(CONANFILE conanfile.py
                    BASIC_SETUP)
endif()

Please check the source code for other options and arguments.

Development, contributors

There are some tests, you can run in python, with nosetests, for example:

$ nosetests . --nocapture

cmake-conan's People

Contributors

alandefreitas avatar artalus avatar bc-lee avatar bilke avatar birsoyo avatar bobeff avatar cguenthertuchemnitz avatar chuet-thermo avatar davidzemon avatar dvetutnev avatar g-s-m avatar gatorque avatar kinddragon avatar lbakman avatar mattgodbolt avatar matthew-d-jones avatar memsharded avatar parsifal-47 avatar r4zzz4k avatar sixten-hilborn avatar tonka3000 avatar unjello avatar xaltotun 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.