Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: allow arbitrary defines in conan new templates #2051

Merged
merged 1 commit into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions extending/template_system/command_new.rst
Expand Up @@ -100,3 +100,38 @@ This is a very simple example for a header only library:

def package_id(self):
self.info.header_only()

Custom definitions
------------------

Sometimes it's needed to provide additional variables for the custom templates. For instance, if
it's desired to have ``description`` and ``homepage`` to be templated as well:


.. code-block:: text

# Recipe autogenerated with Conan {{ conan_version }} using `conan new --template` command

from conans import ConanFile


class {{package_name}}Conan(ConanFile):
name = "{{ name }}"
version = "{{ version }}"
description = "{{ description }}"
homepage = "{{ homepage }}"
settings = "os", "arch", "compiler", "build_type"
exports_sources = "include/*"

def package(self):
self.copy("*.hpp", dst="include")
self.copy("LICENSE.txt", dst="licenses")

def package_id(self):
self.info.header_only()

now it's easy to overwrite these values from the command line:

.. code-block:: bash

$ conan new mypackage/version --template=header_only -d homepage=https://www.example.com -d description="the best package"
4 changes: 3 additions & 1 deletion reference/commands/creator/new.rst
Expand Up @@ -58,6 +58,9 @@ Creates a new package recipe template with a 'conanfile.py' and optionally,
excluded
-ciu CI_UPLOAD_URL, --ci-upload-url CI_UPLOAD_URL
Define URL of the repository to upload
-d DEFINE, --define DEFINE
Define additional variables to be processed within
template


**Examples**:
Expand Down Expand Up @@ -93,5 +96,4 @@ Creates a new package recipe template with a 'conanfile.py' and optionally,
$ conan new mypackage/1.0 --template=myconanfile.py # Single template file
$ conan new mypackage/1.0 --template=header_only # Template directory


Refer to the section :ref:`template_command_new` for more information about these templates.