Repository: conan-io/conan-center-index

Issue:
GLOG 0.4.0 : unresolved external symbol google::InitGoogleLogging

Package Name/Version: **glog/0.4.0**
Operating System+version: **Win 10**
Compiler+version: **MSVS 2015 & MSVS 2019**
Conan version: **1.28.0**
cmake version:**3.18.0**
Ninja version:**1.10.0**

This may be similar to: https://github.com/conan-io/conan-center-index/issues/1691

Using conan-cmake:
``` Bash
conan_cmake_run(
            REQUIRES
                glog/0.4.0
            IMPORTS
                ${CONANIMPORTS}
            BASIC_SETUP
                CMAKE_TARGETS
            )

add_executable( ${PROJECT_NAME} ${SOURCES}   )
target_link_libraries(${PROJECT_NAME} CONAN_PKG::glog)

```

main.cpp is simple enough:

```Bash

#include <glog/logging.h>

int main(int argc, char* argv[]) {


     // Initialize Google's logging library.
     google::InitGoogleLogging(argv[0]);

     LOG(INFO) << "This is an info  message";
     LOG(WARNING) << "This is a warning message";
     LOG(ERROR) << "This is an error message";
     LOG(FATAL) << "This is a fatal message";

     return 0;
}
```

Log attached below.
[Conan_GLOG_Fail.log](https://github.com/conan-io/conan-center-index/files/5062714/Conan_GLOG_Fail.log)


Discussion:
Looking at test_package in glog recipe, it injects a definition if windows and not mingw. This definition should be in cpp_info.
Ok so your comments are welcome, but they go right over my head.

But I read so .... the recipe has 
```Bash
       if self.settings.os == "Windows":
            del self.options.fPIC
```
So the recipe deletes the fPIC option? As opposed to resetting it to False?

Not sure how this really helps me at the moment... just ignorant on how to use the information

Not related with PIC.

In test_package:
```c++
#include <iostream>
#ifdef _WIN32
#ifndef __MINGW32__
#define GOOGLE_GLOG_DLL_DECL 
#endif
#endif
#include <glog/logging.h>

int main(int argc, char** argv) {
    google::InitGoogleLogging(argv[0]);
    LOG(INFO) << "It works";
    return 0;
}
```

This `GOOGLE_GLOG_DLL_DECL` should be injected by cmake target, not manually added by consumers. So it's a bug in glog recipe.
Good that means I dodged that bullet, not my fault.

Thanks

Resolving patch:
diff --git a/recipes/glog/all/conanfile.py b/recipes/glog/all/conanfile.py
--- a/recipes/glog/all/conanfile.py
+++ b/recipes/glog/all/conanfile.py
@@ -8,7 +8,7 @@ class GlogConan(ConanFile):
     homepage = "https://github.com/google/glog/"
     description = "Google logging library"
     topics = ("conan", "glog", "logging")
-    license = "BSD 3-Clause"
+    license = "BSD-3-Clause"
     exports_sources = ["CMakeLists.txt", "patches/**"]
     generators = "cmake", "cmake_find_package"
     settings = "os", "arch", "compiler", "build_type"
@@ -64,5 +64,12 @@ def package(self):
 
     def package_info(self):
         self.cpp_info.libs = tools.collect_libs(self)
+        self.cpp_info.names["pkgconfig"] = ["libglog"]
         if self.settings.os == "Linux":
-            self.cpp_info.system_libs.append("pthread")
+            self.cpp_info.system_libs = ["pthread"]
+        elif self.settings.os == "Windows":
+            self.cpp_info.defines = ["GLOG_NO_ABBREVIATED_SEVERITIES"]
+            decl = "__declspec(dllimport)" if self.options.shared else ""
+            self.cpp_info.defines.append("GOOGLE_GLOG_DLL_DECL={}".format(decl))
+        if self.options.with_gflags and not self.options.shared:
+            self.cpp_info.defines.extend(["GFLAGS_DLL_DECLARE_FLAG=", "GFLAGS_DLL_DEFINE_FLAG="])


Test patch:
diff --git a/recipes/glog/all/test_package/CMakeLists.txt b/recipes/glog/all/test_package/CMakeLists.txt
--- a/recipes/glog/all/test_package/CMakeLists.txt
+++ b/recipes/glog/all/test_package/CMakeLists.txt
@@ -4,7 +4,7 @@ project(test_package)
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
 conan_basic_setup()
 
-find_package(glog REQUIRED CONFIG)
+find_package(glog REQUIRED)
 
 add_executable(${PROJECT_NAME} test_package.cpp)
 target_link_libraries(${PROJECT_NAME} glog::glog)
diff --git a/recipes/glog/all/test_package/conanfile.py b/recipes/glog/all/test_package/conanfile.py
--- a/recipes/glog/all/test_package/conanfile.py
+++ b/recipes/glog/all/test_package/conanfile.py
@@ -4,7 +4,7 @@
 
 class TestPackageConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
-    generators = "cmake", "cmake_find_package_multi"
+    generators = "cmake", "cmake_find_package"
 
     def build(self):
         cmake = CMake(self)
diff --git a/recipes/glog/all/test_package/test_package.cpp b/recipes/glog/all/test_package/test_package.cpp
--- a/recipes/glog/all/test_package/test_package.cpp
+++ b/recipes/glog/all/test_package/test_package.cpp
@@ -1,9 +1,4 @@
 #include <iostream>
-#ifdef _WIN32
-#ifndef __MINGW32__
-#define GOOGLE_GLOG_DLL_DECL 
-#endif
-#endif
 #include <glog/logging.h>
 
 int main(int argc, char** argv) {