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

catch2 (2.x.x): support conan v2 #13794

Merged
merged 19 commits into from
Dec 2, 2022

Conversation

paulharris
Copy link
Contributor

catch2 (2.x.x): support conan v2, based on work by SpaceIm that was done for 3.x.x
ie #13184

It currently doesn't build the test_package with with_prefix=True

It seems that the package_info() self.cpp_info.defines are not being seen by the test_package. I'm not sure what I'm doing wrong.

@paulharris paulharris changed the title [catch2 (2.x.x): support conan v2 catch2 (2.x.x): support conan v2 Oct 27, 2022
@conan-center-bot

This comment has been minimized.

recipes/catch2/2.x.x/conanfile.py Outdated Show resolved Hide resolved
tc.variables["BUILD_TESTING"] = False
tc.cache_variables["CATCH_INSTALL_DOCS"] = False
tc.cache_variables["CATCH_INSTALL_HELPERS"] = "ON"
tc.cache_variables["CATCH_BUILD_STATIC_LIBRARY"] = self.options.with_main # FIXME cache_variables or just variables?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of doubt: conan-io/conan#11937 (comment)

Plus:

There are two main cases to use cache_variables:

  • When a definition is configured before project()
  • When an option uses CACHE. Need to check project's CMakeLists.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs currently focus on the difference that CACHE is for "single config" compare to "multiple config",
and says for the majority of cases cache_variables is what you probably want to use ... so this seems to be a complex topic...
I see almost all recipes use variables, but it seems like if you really want the variable to be set, you should use cache_variables and there is less room for surprises?

Copy link
Contributor

@jwillikers jwillikers Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CMake, cache variables are how CMake and projects expose options to be set by consumers. Cache variables are meant to be able to be preemptible by consumers. If a consumer sets it before a project does, the project won't change the value. I think you're right, @paulharris, that we should prefer setting cache variables instead when possible, as this is how projects should expose the options we are often setting.

There are of course, tons of CMake projects that don't respect cache variables and set normal variables with the same name which causes all sorts of problems.... ugh. And the issue with setting most variables before the first project command is quite problematic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully improvements for this are coming with a future CMake?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#13971 not the best but it's a start

@conan-center-bot

This comment has been minimized.

@paulharris
Copy link
Contributor Author

Can someone please help me understand why this line is in the 3.x.x recipe:

tc.variables["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix

tc.variables["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix
As far as I can tell, this is not a CMake variable...
I see it here:

target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE )
# Macro configuration does not touch the compiled parts, so we can link
# it against the main library
target_link_libraries( PrefixedMacros Catch2WithMain )

add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s)
set_tests_properties(
    CATCH_CONFIG_PREFIX_ALL
  PROPERTIES
    PASS_REGULAR_EXPRESSION "CATCH_"
...

But that is defining a test name(?) not a variable...

@@ -46,7 +46,7 @@ def _compilers_minimum_version(self):

@property
def _default_reporter_str(self):
return '"{}"'.format(str(self.options.default_reporter).strip('"'))
return str(self.options.default_reporter).strip('"')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SpaceIm as noted in main comment - please check this too

@paulharris
Copy link
Contributor Author

I've fixed up the prefix behaviour, looks like there was some errors in the 3.x.x recipe.

@SpaceIm can you please check the highlighted lines especially, as I'm not sure why the magic was required for the quotes. conan/cmake is quoting those values, so they end up double-quoted in conan_toolchain.cmake if the quotes are added here.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

prince-chrismc
prince-chrismc previously approved these changes Oct 30, 2022
@conan-center-bot

This comment has been minimized.

@ghost
Copy link

ghost commented Nov 9, 2022

I detected other pull requests that are modifying catch2/3.x.x recipe:

This message is automatically generated by https://github.com/ericLemanissier/conan-center-conflicting-prsso don't hesitate to report issues/improvements there.

Comment on lines +25 to +30
# note: this is required as self.dependencies is not available in test()
self._tests_todo.append("test_package")
if catch_opts.with_main:
self._tests_todo.append("standalone")
if not catch_opts.with_prefix and catch_opts.with_main and catch_opts.with_benchmark:
self._tests_todo.append("benchmark")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# note: this is required as self.dependencies is not available in test()
self._tests_todo.append("test_package")
if catch_opts.with_main:
self._tests_todo.append("standalone")
if not catch_opts.with_prefix and catch_opts.with_main and catch_opts.with_benchmark:
self._tests_todo.append("benchmark")
# note: this is required as self.dependencies is not available in test()
self._tests_todo.append("test_package")
if catch_opts.with_main:
self._tests_todo.append("standalone")
if not catch_opts.with_prefix and catch_opts.with_main and catch_opts.with_benchmark:
self._tests_todo.append("benchmark")

It does not work. Conan parse twice the recipe folder and _tests_todo will be empty as soon as test() is called.

You can create a temporary file and and those values. More information: conan-io/conan#12411

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this in 332eb40

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cherry-picked your commit and fixed it up slightly

@prince-chrismc
Copy link
Contributor

Whoops I pushed to the wrong repo 🙈

image

I got this working + applied a few of the comments

@conan-center-bot

This comment has been minimized.

This reverts commit 332eb40.
@conan-center-bot

This comment has been minimized.

danimtb
danimtb previously approved these changes Nov 15, 2022
@paulharris
Copy link
Contributor Author

Thanks @prince-chrismc, I included your work and fixed it up slightly

@ghost ghost mentioned this pull request Nov 28, 2022
4 tasks
Copy link
Member

@uilianries uilianries left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@conan-center-bot
Copy link
Collaborator

Conan v1 pipeline

All green in build 19 (bf47652e73f1abbc916f65c40cce6490cc182b49):

  • catch2/2.13.9@:
    All packages built successfully! (All logs)

  • catch2/2.11.3@:
    All packages built successfully! (All logs)

  • catch2/2.13.8@:
    All packages built successfully! (All logs)

  • catch2/2.12.4@:
    All packages built successfully! (All logs)

  • catch2/3.1.0@:
    All packages built successfully! (All logs)

  • catch2/2.13.7@:
    All packages built successfully! (All logs)

  • catch2/3.2.0@:
    All packages built successfully! (All logs)

  • catch2/3.0.1@:
    All packages built successfully! (All logs)

@conan-center-bot conan-center-bot merged commit 8c1c300 into conan-io:master Dec 2, 2022
@paulharris paulharris deleted the catch2-conan-v2 branch December 5, 2022 14:07
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

Successfully merging this pull request may close these issues.

7 participants