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] tools.build:defines is broken in multiconfig setting #15921

Closed
stevenwdv opened this issue Mar 22, 2024 · 11 comments · Fixed by #15924 or #16637
Closed

[bug] tools.build:defines is broken in multiconfig setting #15921

stevenwdv opened this issue Mar 22, 2024 · 11 comments · Fixed by #15924 or #16637
Assignees
Milestone

Comments

@stevenwdv
Copy link
Contributor

stevenwdv commented Mar 22, 2024

Describe the bug

tools.build:defines is broken in multiconfig setting, e.g. with MSVC. The quoting in the generator expression is not correct in blocks.py.

How to reproduce it

  • Set tools.build:defines=['A=1', 'B=2']
  • Observe how the generated toolchain file or afterwards generated vxproj by CMake does not contain the right definitions.

EDIT: See PR #15924 for more info

@stevenwdv
Copy link
Contributor Author

I'm working on a PR

@memsharded memsharded self-assigned this Mar 22, 2024
@memsharded
Copy link
Member

Thanks for the report and the offer to fix it @stevenwdv

This was tested in test_cmake_toolchain_cxxflags_multi_config, maybe it is because the single quotes vs double quotes?

@stevenwdv
Copy link
Contributor Author

stevenwdv commented Mar 22, 2024

maybe it is because the single quotes vs double quotes

No it's the generator expressions, but I'll explain more in the PR and probably create a follow-up issue.

Btw all contributing docs mention the develop branch instead of develop2, which I thought was weird.

@memsharded
Copy link
Member

#15922 will fix that, thanks for raising it too!

czoido pushed a commit that referenced this issue Mar 25, 2024
…15924)

* Fix handling of `tools.build:defines` for multiconfig CMake (#15921)

* add test checks

* fix

* fix test

---------

Co-authored-by: memsharded <james@conan.io>
czoido pushed a commit that referenced this issue Mar 25, 2024
…15924)

* Fix handling of `tools.build:defines` for multiconfig CMake (#15921)

* add test checks

* fix

* fix test

---------

Co-authored-by: memsharded <james@conan.io>
@memsharded
Copy link
Member

The PR in #15924 will be released in 2.2.2 today, as it could be considered a regression. Thanks again for reporting.

@memsharded memsharded added this to the 2.2.2 milestone Mar 25, 2024
@stevenwdv
Copy link
Contributor Author

Maybe you can re-open this for now?

@memsharded memsharded reopened this Apr 1, 2024
@memsharded
Copy link
Member

Sure re-opening.

It would be great to have a PR with a test similar to test_cmake_toolchain_cxxflags_multi_config(), as seen in https://github.com/conan-io/conan/pull/15924/files that fails. Probably the best would be a new test if it can add just new checks, or a full new test if changing something else.

@stevenwdv
Copy link
Contributor Author

@memsharded What I don't understand yet is why the current test is passing (see #15924 (comment))

@DenizThatMenace
Copy link
Contributor

This is still broken in Conan 2.5.

But the fix is quite simple, as I already commented in #15924 (comment):

--- a/conan/tools/cmake/toolchain/blocks.py
+++ b/conan/tools/cmake/toolchain/blocks.py
@@ -724,7 +724,7 @@ class ExtraFlagsBlock(Block):
         {% if defines %}
         {% if config %}
         {% for define in defines %}
-        add_compile_definitions($<$<CONFIG:{{config}}>:"{{ define }}">)
+        add_compile_definitions("$<$<CONFIG:{{config}}>:{{ define }}>")
         {% endfor %}
         {% else %}
         add_compile_definitions({% for define in defines %} "{{ define }}"{% endfor %})

@memsharded
Copy link
Member

To consider these changes, we would need first a failing test that reproduces the issues.

I am trying to reproduce, and added tools.cmake.cmaketoolchain:generator=Ninja Multi-Config in the existing test, but it is still green and passing.

Maybe you want to try to do a change or a new test like

def test_cmake_toolchain_cxxflags_multi_config():
, and submit a PR with it that showcases the error? That would help to clarify the issues.

@DenizThatMenace
Copy link
Contributor

I have created a fix and test for this issue in PR #16637.

memsharded added a commit that referenced this issue Jul 10, 2024
…CMake (#15921) (#16637)

* Add test for handling of tools.build:defines for Ninja multi-config CMake

* Fix handling of tools.build:defines for (Ninja) multi-config CMake

The CMake generator-expressions that results from the values given to
Conan's `tools.build:defines` configuration will now properly be put
into quotes to form a CMake string. (Note: CMake's generator-expressions
should never contain any (non-escaped) quotes.)

* use CMake 3.23 in test

* fix Windows (might pass by luck, using clang++ instead of cl)

* fix Windows activating conanbuild.bat for vcvars

---------

Co-authored-by: memsharded <james@conan.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment