Skip to content

Instantly share code, notes, and snippets.

@peter-moran
Last active August 11, 2019 17:24
Show Gist options
  • Save peter-moran/a180ea85ef2ffe46b1342433cec990fd to your computer and use it in GitHub Desktop.
Save peter-moran/a180ea85ef2ffe46b1342433cec990fd to your computer and use it in GitHub Desktop.
# @brief Downloads and Includes cmake-conan
# @param VERSION -- The cmake-conan release version to get. Commit codes
# also applicable.
# @option INSTALL -- Specifies if cmake-conan should be installed to the user's home directory.
# This allows cmake-conan to only be downloaded once, rather than every
# time the build directory is cleaned.
# @note Browse release versions at: https://github.com/conan-io/cmake-conan/releases
# @note cmake-conan is a CMake wrapper for the Conan C and C++ package manager.
# It allows cmake to automatically configure and launch `conan install` as
# part of cmake configuration. It will take CMake current settings (os,
# compiler, compiler version, architecture) and translate them to conan
# settings for installing and retrieving dependencies.
# See: https://github.com/conan-io/cmake-conan
# @example `get_cmake_conan(INSTALL VERSION v0.13)`
function(get_cmake_conan)
# Parse arguments
cmake_parse_arguments(ARGS "INSTALL" "VERSION" "" ${ARGN})
# Set file paths
if(${ARGS_INSTALL})
set(CMAKE_CONAN_DIR $ENV{HOME}/.cmake_conan/${ARGS_VERSION})
else()
set(CMAKE_CONAN_DIR ${CMAKE_BINARY_DIR})
endif()
set(CMAKE_CONAN_FILE ${CMAKE_CONAN_DIR}/conan.cmake)
# Download
if(NOT EXISTS "${CMAKE_CONAN_FILE}")
set(URL https://raw.githubusercontent.com/conan-io/cmake-conan/${ARGS_VERSION}/conan.cmake)
message(STATUS "Downloading conan.cmake from ${URL} to ${CMAKE_CONAN_FILE}")
file(DOWNLOAD "${URL}"
"${CMAKE_CONAN_FILE}")
else()
message(STATUS "Found conan.cmake at ${CMAKE_CONAN_FILE}")
endif()
include(${CMAKE_CONAN_FILE})
endfunction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment