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

[question] Is there a way to define information in a recipe that can be used in CMake (or other build systems potentially) #16299

Open
1 task done
rconde01 opened this issue May 17, 2024 · 2 comments
Assignees

Comments

@rconde01
Copy link

What is your question?

I have a package which contains a python script that I want to call from my CMakeLists.txt. It lives in the bin directory within the package. In my CMakeLists.txt I would like to do something like:

Python3::Interpreter ${PATH_TO_MY_PYTHON_SCRIPT} ${some_args}

Is there any way to do this? The best I can find is to do something like mypackage_INCLUDE_DIR/../bin/myscript.py but that's pretty yuck.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this May 18, 2024
@memsharded
Copy link
Member

Hi @rconde01

If I understood correctly, you have a Python script in one of your dependencies, and you want to run that script from the CMakeLists.txt of a consumer of that dependency, that has a requires() or tool_requires to it?

Would the explicit way be good for your use case? Something like:

requires = "mydep/0.1"

def  generate(self):
    tc = CMakeToolchain(self)
    tc.variables["PATH_TO_MY_PYTHON_SCRIPT"] = os.path.join(self.dependencies["mydep"].cpp_info.bindir, "myscript.py")
    tc.generate()

@rconde01
Copy link
Author

I did a slight variation which was:

class my_tool(ConanFile):
   def package_info(self):
      self.cpp_info.set_property(my_tool_py", join(self.package_folder, "bin", "my_tool.py"))
def generate(self):
   tc= CMakeToolchain(self)
   tc.variables["MY_TOOL_PATH"] = self.dependencies["my_tool"].cpp_info.get_property("my_tool_py")
   tc.generate()

which works well - except on windows the path ends up in the variable with unescaped backslashes. I can manually fix that up but maybe CMakeToolchain should be doing that?

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

No branches or pull requests

2 participants