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

How to properly set CMAKE_MAKE_PROGRAM? #14197

Closed
1 task done
AndrewAtAvenza opened this issue Jun 29, 2023 · 13 comments · Fixed by #14223
Closed
1 task done

How to properly set CMAKE_MAKE_PROGRAM? #14197

AndrewAtAvenza opened this issue Jun 29, 2023 · 13 comments · Fixed by #14223

Comments

@AndrewAtAvenza
Copy link

What is your question?

I'm new to Conan and I'm trying to get a sample package (sqlite) building for Android on my Windows machine. The main problem I'm having is that I cannot figure out how to set the CMAKE_MAKE_PROGRAM environment variable such that Conan picks it up properly and propagates it to CMake.

After a fair bit of tinkering, I've figured out how to get it to work, but I'm 100% sure this is the wrong way to do it:

    def generate(self):
        deps = CMakeDeps(self)
        deps.generate()
        tc = CMakeToolchain(self)
        # this feels very, very wrong
        tc.variables["CMAKE_MAKE_PROGRAM"]="c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/ninja.exe"
        tc.generate()

I know enough about Conan at this point to know that embedding local paths into recipes is a terrible idea. Also while it does build successfully, it fails the test step, which is probably a good thing since it further dissuades anyone from doing this. But how do I set CMAKE_MAKE_PROGRAM properly? I've tried setting it in the profile like this:

include(default)

[settings]
os=Android
os.api_level=26
arch=armv8
compiler=clang
compiler.version=14
compiler.libcxx=c++_static
compiler.cppstd=17

[buildenv]
# this felt like it should work, but it doesn't
CMAKE_MAKE_PROGRAM=c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/ninja.exe

[runenv]
# this felt like it could work, but it doesn't
CMAKE_MAKE_PROGRAM=c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/ninja.exe

[tool_requires]
android-ndk/r25

[conf]
tools.cmake.cmaketoolchain:generator=Ninja

But that doesn't seem to have an effect: I just get:

CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

There must be a way to do this, but I cannot find an example anywhere and I'm running out of things to read. What am I doing wrong? Any help would be greatly appreciated!

Thanks!

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@AbrilRBS AbrilRBS self-assigned this Jun 29, 2023
@AbrilRBS
Copy link
Member

Hi @AndrewAtAvenza, thanks a lot for your question.

You were most of the way there! The conf you're looking for to set in either your profile or your global.conf files is tools.gnu:make_program, which sets your CMAKE_MAKE_PROGRAM for the CMakeToolchain and Autotools integrations.

Please try that and let me know if it helps :)

@AndrewAtAvenza
Copy link
Author

Wow, thanks for the fast response!

I set it in my global.conf like so:

tools.gnu:make_program=c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/ninja.exe

But I'm still getting the same error complaining that CMAKE_MAKE_PROGRAM is not set. I verified that value is set using conan config show tools.gnu:make_program so it's not that it isn't picking up the value. The response was:

tools.gnu:make_program: c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/ninja.exe

@AndrewAtAvenza
Copy link
Author

BTW, in case it matters, I'm using conan 2.0.7

@AbrilRBS
Copy link
Member

Oh I see the issue, the variable is only being injected if using MinGW Makefiles generator. I'll check with the team as soon as possible to see if it makes sense to make this apply in a more general way, and will let you know once we come to a conclusion :)

@AndrewAtAvenza
Copy link
Author

I appreciate it!

I should mention that the NDK -- as far as I know -- always includes ninja. I have no idea if this make sense w.r.t. Conan packages or not, but since in my Android profile I'm using

[tool_requires]
android-ndk/r25

it'd be great if there was a way to either have it automatically choose the ninja from the NDK if you select that as the Generator or failing that (which does seem a bit too magical) maybe it could be possible to specify the CMAKE_MAKE_PROGRAM in a profile somehow using a constant exposed from the android-ndk package? If that's even a thing! I am such a Conan n00b that I have no idea if those suggestions are patent nonsense or not!

@AbrilRBS
Copy link
Member

While I figure out the best way forward with the conf I mentioned, heres a workaround for you:

In your profile's [buildenv] section, add the path to Ninja to the path, something like:

[buildenv]
PATH+=(path)c:/Users/andrew/AppData/Local/Android/Sdk/cmake/3.22.1/bin/

(Check here for the path appending syntax)

This will ensure that ninja is eventually found by CMake in the path (Thanks @jcar87 for the suggestion!)

Another alternative would be to add another tool_requires to ninja, which would automatically add it, but might be undesirable if you want to use the specific Ninja bundled with the ndk.


As for your suggestion about this being automatically handled, this is something that's totally possible with the right changes to the android-ndk recipe, but one which we would have to properly consider :)

@AndrewAtAvenza
Copy link
Author

That workaround did the trick! Thanks!

I'm glad it can be made more auto-magical -- it feels more than a bit weird to be using Conan to download the NDK package but then point at the ninja.exe from a different NDK installation!

@AbrilRBS
Copy link
Member

AbrilRBS commented Jul 4, 2023

Hi @AndrewAtAvenza I've now sent a PR to hopefully get the conf to work for all cases for the next Conan release, thanks a lot for your input. (Adding it to the buildenv profile seems to also be an ok solution from what I can see after discussing it with the team a bit further!)

@AndrewAtAvenza
Copy link
Author

Great! Thanks for all the help! I got my first local package built (sqlite, looking for the lowest hanging fruit) and and I'm playing with figuring out how to integrate Conan with our build system.

And I look forward to when the ndk-package gets updated to make this even more automatic :)

@AbrilRBS
Copy link
Member

AbrilRBS commented Jul 4, 2023

Great to hear! Feel free to open more issues should you have any other question :)

@mmomtchev
Copy link

@AbrilRBS the problem with tools.gnu:make_program is that it breaks autotools-based packages such as xz_utils for example - it will try to use ninja to compile its Makefile which does not work.

We need a tools.cmake:make_program that applies only to CMake-based packages.

@memsharded
Copy link
Member

@mmomtchev

for cmake only variables, you can use the tools.cmake.cmaketoolchain:extra_variable conf to inject that directly if you want.

@mmomtchev
Copy link

This works for almost everything else but CMAKE_MAKE_PROGRAM - which cannot be reliably set by a toolchain - it must be set on the command line:
https://stackoverflow.com/questions/78002497/cmake-not-set-make-program

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

Successfully merging a pull request may close this issue.

4 participants