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

passing command line arguments to cmake during conan build #4572

Closed
deekshith-elear opened this issue Feb 20, 2019 · 5 comments
Closed

passing command line arguments to cmake during conan build #4572

deekshith-elear opened this issue Feb 20, 2019 · 5 comments
Assignees

Comments

@deekshith-elear
Copy link

Hi
I'm trying to cross compile my code for android i have to pass an command line argument to cmake like mentioned below
cmake -DPlatform:STRING=android
Is there any way to provide these details during conan build command or Is there a way to mention in conanfile.py

@Johnnyxy
Copy link

Johnnyxy commented Feb 20, 2019

Have a look here in the docs.
At the end of the topic you can find an example how to manipulate or add new arguments.
This implies using the CMake build helper.
If you do not use the build helper you can traditionally invoke CMake with self.run (see here).

def build(self):
        cmake = CMake(self)
        cmake.definitions["Platform"] = "android"
        cmake.configure()
        cmake.build()
        cmake.install()  # Build --target=install

@danimtb
Copy link
Member

danimtb commented Feb 20, 2019

Hi @deekshith-elear

Please take a look at the example and links provided by @Johnnyxy. That should be the most convenient way to achieve what you are trying to do.

If you issue is solved please remember to get it closed. Thanks! 😄

@deekshith-elear
Copy link
Author

deekshith-elear commented Feb 21, 2019

Hi @danimtb @Johnnyxy
Insted of giving them in conanfile.py can I pass them through command line arguments because it is not fixed value it will change

@Johnnyxy
Copy link

I do not know if you can issue arguments directly to any subsequent processes (commandline -> conanfile.py -> process).

But you can use conan's options for that.

recipe

class recipe(Conanfile)
    ...
    options = {"Platform": None}
    ...

    def build(self):
        cmake = CMake(self)
        cmake.definitions["Platform"] = self.options.Platform
        cmake.configure()
        cmake.build()
        cmake.install()  # Build --target=install

commandline

conan create ... --options Platform="android"

comment

If you are building for android anyway, you could use the informations conan provides already.
You did not elaborate what strings are valid for the CMake argument, but it seems to be some mapping.

def build(self):
        cmake = CMake(self)
        if (self.settings.os == "Android"):
            cmake.definitions["Platform"] = "android"
        cmake.configure()
        cmake.build()
        cmake.install()  # Build --target=install

@danimtb
Copy link
Member

danimtb commented Feb 27, 2019

@deekshith-elear

Insted of giving them in conanfile.py can I pass them through command line arguments because it is not fixed value it will change

You could use Conan environment variables for that too, for example:

```$ conan create . user/channel -e PLATFORM=android``

However this will not be takeing into account in the package ID generation as it is created from settings and options. The right approach would be using settings or at least options for that.

We have a OS setting in settings.yml file for Andorid operating system as @Johnnyxy pointed out in the comment above. That would be the best way to do it.

I am closing this as the answer and approach is clear but feel free to comment or reopen the issue if you find any stopper. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants