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

[bug] Generated CMake files for macOS universal binaries not compatible with Ninja #17009

Closed
phlipsi opened this issue Sep 17, 2024 · 3 comments · Fixed by #17024
Closed

[bug] Generated CMake files for macOS universal binaries not compatible with Ninja #17009

phlipsi opened this issue Sep 17, 2024 · 3 comments · Fixed by #17024
Assignees
Milestone

Comments

@phlipsi
Copy link

phlipsi commented Sep 17, 2024

Describe the bug

Using generated CMake files for macOS universal binaries aren't compatible with Ninja. For example:

# conanfile.txt
[requires]
zlib/1.3.1

[generators]
CMakeToolchain
CMakeDeps
# CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(ninjatest CXX)

find_package(ZLIB CONFIG REQUIRED)

Please run the following commands:

$ conan install . -s arch="armv8|x86_64" -b missing -of build
$ cd build
$ cmake .. -GNinja \
    -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
    -DCMAKE_POLICY_DEFAULT_CMP0091=NEW \
    -DCMAKE_BUILD_TYPE=Release

Then you'll get something like

CMake Error:
  Running

   'ninja' '-C' '.../build' '-t' 'cleandead'

  failed with:

   ninja: error: build.ninja:81: expected newline, got '|'

The reason for this error is the phony target which refreshes the CMake cache

build ../CMakeLists.txt ... ZLIB-release-armv8|x86_64-data.cmake ...

which uses a filename with the non-escaped reserved symbol | in Ninja syntax.

Of course, one could argue that CMake should escape the referenced files in the generated build.ninja file correctly. On the other hand, it seems that Ninja doesn't support any escape sequence for the pipe character. So CMake got its hands tied in this matter. What is your take on this issue?

How to reproduce it

No response

@memsharded
Copy link
Member

Hi @phlipsi

Thanks for the report.

Just to make sure, is this happening if using the Unix Makefiles CMake generator instead of the Ninja one?

ZLIB-release-armv8|x86_64-data.cmake

This seems the cause, I am now a bit surprised that this doesn't generate issues with other generators. I guess that we could do a replace of the | character too for the file names? cc @czoido

@czoido
Copy link
Contributor

czoido commented Sep 19, 2024

Just to make sure, is this happening if using the Unix Makefiles CMake generator instead of the Ninja one?

I think the reason why it only fails in Ninja is because | is a reserved character in Ninja files and when making reference to files that have that character in the filename Ninja interprets them incorrectly, that's why it does not fail with Unix Makefiles.

This seems the cause, I am now a bit surprised that this doesn't generate issues with other generators. I guess that we could do a replace of the | character too for the file names? cc @czoido

Yes, I think the only solution we can bring would be to do a replace of the character | in the filenames. Let's check that solution.

@memsharded
Copy link
Member

This has been fixed by #17024, so it will be in next Conan 2.8.

Thanks again for the feedback!

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.

3 participants