Repository: conan-io/conan-center-index

Issue:
[package] imgui/1.84.1: Shared library does not automatically import global data symbols
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **imgui/1.84.1**
  * Operating System+version: **Windows 10 21H1 Build 19043.1165**
  * Compiler+version: **Visual Studio 16 (2019)**
  * Docker image: **N/A**
  * Conan version: **conan 1.39.0**
  * Python version: **Python 3.9.6**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
[conf]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
Try to reference any code that uses global data symbols since those need to use `__declspec(dllimport)` when using [`WINDOWS_EXPORT_ALL_SYMBOLS`](https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html#windows-export-all-symbols). One example could be using [`ImGuiTextBuffer`](https://github.com/ocornut/imgui/blob/v1.84.1/imgui.h#L2078) (which has `IMGUI_API static char EmptyString[1];`).
The following diff is for ImGui's [`test_package.cpp`](https://github.com/conan-io/conan-center-index/blob/master/recipes/imgui/all/test_package/test_package.cpp) and can reproduce this issue.

```
--- a/recipes/imgui/all/test_package/test_package.cpp
+++ b/recipes/imgui/all/test_package/test_package.cpp
@@ -5,6 +5,9 @@ int main(int, char**)
 {
     ImGuiContext* context =ImGui::CreateContext();
     ImGuiIO& io = ImGui::GetIO();
+	
+    ImGuiTextBuffer textBuffer;
+    textBuffer.append("Hello, ImGui");
 
     // Build atlas
     unsigned char* tex_pixels = NULL;
@@ -20,6 +23,7 @@ int main(int, char**)
 
         static float f = 0.0f;
         ImGui::Text("Hello, world!");
+        ImGui::Text(textBuffer.begin());
         ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
         ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
         ImGui::ShowDemoWindow(NULL);
```

Then, try to create the package with `conan create . imgui/1.84.1@ -o imgui:shared=True`.


### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
test_package.obj : error LNK2019: unresolved external symbol "public: static char * ImGuiTextBuffer::EmptyString" (?Emp
tyString@ImGuiTextBuffer@@2PADA) referenced in function main
```

</details>

I think the simplest solution would be to add something like this

```
if self.options.shared and self.settings.os == "Windows":
    self.cpp_info.defines.append("IMGUI_API=__declspec(dllimport)")
```

I'd be happy to open a PR with this change.


Discussion:
I think this is supposed to be defined either in https://github.com/ocornut/imgui/blob/master/imconfig.h#L26, or in another file which name is saved in IMGUI_USER_CONFIG macro https://github.com/ocornut/imgui/blob/master/imgui.h#L41

Resolving patch:
diff --git a/recipes/imgui/all/conanfile.py b/recipes/imgui/all/conanfile.py
--- a/recipes/imgui/all/conanfile.py
+++ b/recipes/imgui/all/conanfile.py
@@ -12,19 +12,18 @@ class IMGUIConan(ConanFile):
     topics = ("conan", "imgui", "gui", "graphical")
     license = "MIT"
 
-    exports_sources = ["CMakeLists.txt"]
-    generators = "cmake"
-
     settings = "os", "arch", "compiler", "build_type"
     options = {
         "shared": [True, False],
-         "fPIC": [True, False]
+        "fPIC": [True, False],
     }
     default_options = {
         "shared": False,
-        "fPIC": True
+        "fPIC": True,
     }
 
+    exports_sources = "CMakeLists.txt"
+    generators = "cmake"
     _cmake = None
 
     @property
@@ -56,7 +55,7 @@ def build(self):
 
     def package(self):
         self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
-        backends_folder = src=os.path.join(
+        backends_folder = os.path.join(
             self._source_subfolder,
             "backends" if tools.Version(self.version) >= "1.80" else "examples"
         )
@@ -68,6 +67,7 @@ def package(self):
 
     def package_info(self):
         self.cpp_info.libs = ["imgui"]
+        self.cpp_info.defines.append("IMGUI_USER_CONFIG=\"imgui_user_config.h\"")
         if self.settings.os == "Linux":
             self.cpp_info.system_libs.append("m")
         self.cpp_info.srcdirs = [os.path.join("res", "bindings")]


Test patch:
diff --git a/recipes/imgui/all/test_package/test_package.cpp b/recipes/imgui/all/test_package/test_package.cpp
--- a/recipes/imgui/all/test_package/test_package.cpp
+++ b/recipes/imgui/all/test_package/test_package.cpp
@@ -6,6 +6,9 @@ int main(int, char**)
     ImGuiContext* context =ImGui::CreateContext();
     ImGuiIO& io = ImGui::GetIO();
 
+    ImGuiTextBuffer textBuffer;
+    textBuffer.append("Hello, ImGui");
+
     // Build atlas
     unsigned char* tex_pixels = NULL;
     int tex_w, tex_h;
@@ -20,6 +23,7 @@ int main(int, char**)
 
         static float f = 0.0f;
         ImGui::Text("Hello, world!");
+        ImGui::Text("%s", textBuffer.begin());
         ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
         ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
         ImGui::ShowDemoWindow(NULL);