Repository: conan-io/conan-center-index

Issue:
[package] catch2/2.9.2: Expected CMake scripts to be included in the package 
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **catch2/2.9.2**

I expected to have access to cmake scripts that are installed with Catch2.

The helper scripts are set to be installed.

https://github.com/conan-io/conan-center-index/blob/6a7ff72be4e6fa6362112459f7319f6e6e565a99/recipes/catch2/2.x.x/conanfile.py#L33

Then they are deleted during packaging.

https://github.com/conan-io/conan-center-index/blob/6a7ff72be4e6fa6362112459f7319f6e6e565a99/recipes/catch2/2.x.x/conanfile.py#L51

Currently, I am using the older bincrafters package (catch2/2.5.0@bincrafters/stable) which still includes the CMake scripts. I would need to maintain my own conan package to use the newer version of Catch2.


Discussion:
See discussion here https://github.com/conan-io/conan-center-index/issues/209
Catch2 provides more than just install scripts though: some of the provided CMake scripts such as `CatchAddTests.cmake` allow to discover Catch tests in the source and register them as CTest tests. It's notably not the `Config.cmake` files and yet they seem to be removed to from the package.

Those scripts should be kept since they're not meant for dependency discovery.
In that case, it is totally fine to have them packaged. Thanks for the info @Morwenn 
Thanks for the response

@Morwenn That is exactly my use case. I use `catch_discover_tests`.

@danimtb I'll keep updated with https://github.com/conan-io/conan/issues/5798 and https://github.com/conan-io/conan-center-index/issues/209 for now. For now, I'll keep using the old package. Do you want to close this issue or keep it open to specifically track the catch2 package?

If I understand correctly this issue is independent of the ones you linked to: they try to solve the problems with packages that provide more than the basic dependency mechanisms in `Find*.cmake` and `*Config.cmake` files. In the test of Catch2 the relevant files are separate from the dependency-finding ones, so we should update the Catch2 recipe to not get rid of them.
The CMake scripts require the config file to be loaded so that they are in the path. The first bullet point of https://github.com/conan-io/conan/issues/5798#issuecomment-537469608 should fix this.

Edit: Fixed typo

Resolving patch:
diff --git a/recipes/catch2/2.x.x/conanfile.py b/recipes/catch2/2.x.x/conanfile.py
--- a/recipes/catch2/2.x.x/conanfile.py
+++ b/recipes/catch2/2.x.x/conanfile.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-
 import os
 
 from conans import ConanFile, CMake, tools
@@ -12,20 +10,16 @@ class ConanRecipe(ConanFile):
     homepage = "https://github.com/catchorg/Catch2"
     url = "https://github.com/conan-io/conan-center-index"
     license = "BSL-1.0"
-
     settings = "os", "compiler", "build_type", "arch"
-
     generators = "cmake"
-
     _source_subfolder = "source_subfolder"
+    _build_subfolder = "build_subfolder"
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version])
         extracted_dir = "Catch2-" + self.version
         os.rename(extracted_dir, self._source_subfolder)
 
-    _build_subfolder = "build_subfolder"
-
     def _configure_cmake(self):
         cmake = CMake(self)
         cmake.definitions["BUILD_TESTING"] = "OFF"
@@ -42,14 +36,18 @@ def build(self):
         cmake.build()
 
     def package(self):
-        self.copy(pattern="LICENSE.txt", dst="licenses",
-                  src=self._source_subfolder)
-
+        self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
         cmake = self._configure_cmake()
         cmake.install()
-
         tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
         tools.rmdir(os.path.join(self.package_folder, "share"))
+        for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake"]:
+            self.copy(cmake_file,
+                      src=os.path.join(self._source_subfolder, "contrib"),
+                      dst=os.path.join("lib", "cmake", "Catch2"))
 
     def package_id(self):
         self.info.header_only()
+
+    def package_info(self):
+        self.cpp_info.builddirs = [os.path.join("lib", "cmake", "Catch2")]


Test patch: