Repository: conan-io/conan-center-index

Issue:
[package] thrift/0.15.0: thriftnb component not disabled with libevent
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **thrift/0.15.0**
  * Operating System+version: **Windows 11 21H2**
  * Compiler+version: **Visual Studio 2022 / VC++ 14.31**
  * Conan version: **conan 1.47.0**
  * Python version: **Python 3.10.2**

### Conan profile
```
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.cppstd=None
compiler.runtime=MD
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
```

### Steps to reproduce (Include if Applicable)
When installing thrift/0.15.0 with the option `thrift:with_libevent=False`,
thrift's cmake build disables the `thriftnb` library (see https://github.com/apache/thrift/blob/v0.15.0/lib/cpp/CMakeLists.txt#L162-L166).
The conan recipe however still declares the libthrift_nb component referencing that (now non-existant) library (see https://github.com/conan-io/conan-center-index/blob/master/recipes/thrift/all/conanfile.py#L214-L217).

Trying to link to this package then fails with errors like 
```
fatal error LNK1104: cannot open file 'thriftnbmd.lib'
```
since that library doesn't exist in the package.

I don't know if this is a separate issue with the recipe, but for some reason both the `libthrift` component and the global package target are named `thrift::thrift` for the cmake_find_package generator,
which makes it impossible to try to link just the `libthrift` component without `libthrift_nb`, making the library unusable if `with_libevent=False` is used.



Discussion:

Resolving patch:
diff --git a/recipes/thrift/all/conanfile.py b/recipes/thrift/all/conanfile.py
--- a/recipes/thrift/all/conanfile.py
+++ b/recipes/thrift/all/conanfile.py
@@ -129,6 +129,7 @@ def _configure_cmake(self):
             self._cmake.definitions["OPENSSL_ROOT_DIR"] = self.deps_cpp_info["openssl"].rootpath
         if self.options.with_zlib:
             self._cmake.definitions["ZLIB_ROOT"] = self.deps_cpp_info["zlib"].rootpath
+        self._cmake.definitions["WITH_LIBEVENT"] = self.options.with_libevent
         if self.options.with_libevent:
             self._cmake.definitions["LIBEVENT_ROOT"] = self.deps_cpp_info["libevent"].rootpath
 
@@ -155,9 +156,11 @@ def package(self):
         tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
 
         # TODO: to remove in conan v2 once cmake_find_package* generators removed
-        targets = {"thriftnb::thriftnb": "thrift::thriftnb"}
+        targets = {}
         if self.options.with_zlib:
             targets.update({"thriftz::thriftz": "thrift::thriftz"})
+        if self.options.with_libevent:
+            targets.update({"thriftnb::thriftnb": "thrift::thriftnb"})
         if self.options.with_qt:
             targets.update({"thriftqt5::thriftqt5": "thrift::thriftqt5"})
         self._create_cmake_module_alias_targets(
@@ -202,8 +205,6 @@ def package_info(self):
         self.cpp_info.components["libthrift"].requires.append("boost::headers")
         if self.options.with_openssl:
             self.cpp_info.components["libthrift"].requires.append("openssl::openssl")
-        if self.options.with_libevent:
-            self.cpp_info.components["libthrift"].requires.append("libevent::libevent")
 
         if self.options.with_zlib:
             self.cpp_info.components["libthrift_z"].set_property("cmake_target_name", "thriftz::thriftz")
@@ -211,10 +212,12 @@ def package_info(self):
             self.cpp_info.components["libthrift_z"].libs = ["thriftz" + libsuffix]
             self.cpp_info.components["libthrift_z"].requires = ["libthrift", "zlib::zlib"]
 
-        self.cpp_info.components["libthrift_nb"].set_property("cmake_target_name", "thriftnb::thriftnb")
-        self.cpp_info.components["libthrift_nb"].set_property("pkg_config_name", "thrift-nb")
-        self.cpp_info.components["libthrift_nb"].libs = ["thriftnb" + libsuffix]
-        self.cpp_info.components["libthrift_nb"].requires = ["libthrift"]
+
+        if self.options.with_libevent:
+            self.cpp_info.components["libthrift_nb"].set_property("cmake_target_name", "thriftnb::thriftnb")
+            self.cpp_info.components["libthrift_nb"].set_property("pkg_config_name", "thrift-nb")
+            self.cpp_info.components["libthrift_nb"].libs = ["thriftnb" + libsuffix]
+            self.cpp_info.components["libthrift_nb"].requires = ["libthrift", "libevent::libevent"]
 
         if self.options.with_qt:
             self.cpp_info.components["libthrift_qt5"].set_property("cmake_target_name", "thriftqt5::thriftqt5")
@@ -239,10 +242,11 @@ def package_info(self):
             self.cpp_info.components["libthrift_z"].names["cmake_find_package_multi"] = "thriftz"
             self.cpp_info.components["libthrift_z"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
             self.cpp_info.components["libthrift_z"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
-        self.cpp_info.components["libthrift_nb"].names["cmake_find_package"] = "thriftnb"
-        self.cpp_info.components["libthrift_nb"].names["cmake_find_package_multi"] = "thriftnb"
-        self.cpp_info.components["libthrift_nb"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
-        self.cpp_info.components["libthrift_nb"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
+        if self.options.with_libevent:
+            self.cpp_info.components["libthrift_nb"].names["cmake_find_package"] = "thriftnb"
+            self.cpp_info.components["libthrift_nb"].names["cmake_find_package_multi"] = "thriftnb"
+            self.cpp_info.components["libthrift_nb"].build_modules["cmake_find_package"] = [self._module_file_rel_path]
+            self.cpp_info.components["libthrift_nb"].build_modules["cmake_find_package_multi"] = [self._module_file_rel_path]
         if self.options.with_qt:
             self.cpp_info.components["libthrift_qt5"].names["cmake_find_package"] = "thriftqt5"
             self.cpp_info.components["libthrift_qt5"].names["cmake_find_package_multi"] = "thriftqt5"


Test patch:
diff --git a/recipes/thrift/all/test_package/CMakeLists.txt b/recipes/thrift/all/test_package/CMakeLists.txt
--- a/recipes/thrift/all/test_package/CMakeLists.txt
+++ b/recipes/thrift/all/test_package/CMakeLists.txt
@@ -12,5 +12,5 @@ add_executable(${PROJECT_NAME}
     Calculator.cpp
     test_package.cpp
 )
-target_link_libraries(${PROJECT_NAME} thriftnb::thriftnb)
+target_link_libraries(${PROJECT_NAME} thrift::thrift)
 set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
diff --git a/recipes/thrift/all/test_package/test_package.cpp b/recipes/thrift/all/test_package/test_package.cpp
--- a/recipes/thrift/all/test_package/test_package.cpp
+++ b/recipes/thrift/all/test_package/test_package.cpp
@@ -7,12 +7,10 @@
 #include <thrift/server/TSimpleServer.h>
 #include <thrift/server/TThreadPoolServer.h>
 #include <thrift/server/TThreadedServer.h>
-#include "thrift/server/TNonblockingServer.h"
 
 #include <thrift/concurrency/ThreadManager.h>
 #include <thrift/concurrency/ThreadFactory.h>
 #include <thrift/protocol/TBinaryProtocol.h>
-#include "thrift/transport/TNonblockingServerSocket.h"
 #include <thrift/transport/TBufferTransports.h>
 #include <thrift/transport/TServerSocket.h>
 #include <thrift/transport/TSocket.h>
@@ -48,12 +46,10 @@ int main(int argc, char **argv) {
     std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
     std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
 
-    std::shared_ptr<TNonblockingServerSocket> nonBlockingserverTransport(new TNonblockingServerSocket(port));
 
     TSimpleServer server1(processor, serverTransport, transportFactory, protocolFactory);
     TThreadedServer server2(processor, serverTransport, transportFactory, protocolFactory);
     TThreadPoolServer server3(processor, serverTransport, transportFactory, protocolFactory);
-    TNonblockingServer server4(processor, nonBlockingserverTransport);
 
     const int workerCount = 4;
     std::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);