Browse Source

Build library for Visual Studio

DarkMorford 5 years ago
parent
commit
220dd1d346
4 changed files with 59 additions and 26 deletions
  1. 3 0
      .gitignore
  2. 4 1
      conandata.yml
  3. 40 25
      conanfile.py
  4. 12 0
      patches/001-remove-default-cflags.patch

+ 3 - 0
.gitignore

@@ -28,6 +28,9 @@
 # When using Gradle or Maven with auto-import, you should exclude module files,
 # When using Gradle or Maven with auto-import, you should exclude module files,
 # since they will be recreated, and may cause churn.  Uncomment if using
 # since they will be recreated, and may cause churn.  Uncomment if using
 # auto-import.
 # auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
 # .idea/modules.xml
 # .idea/modules.xml
 # .idea/*.iml
 # .idea/*.iml
 # .idea/modules
 # .idea/modules

+ 4 - 1
conandata.yml

@@ -1,4 +1,7 @@
 sources:
 sources:
   1.2.11:
   1.2.11:
-    url: "http://www.zlib.net/fossils/zlib-1.2.11.tar.gz"
+    url: "http://zlib.net/fossils/zlib-1.2.11.tar.gz"
     sha256: "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"
     sha256: "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"
+patches:
+  1.2.11:
+    - patch_file: "patches/001-remove-default-cflags.patch"

+ 40 - 25
conanfile.py

@@ -1,38 +1,56 @@
-from conans import ConanFile, CMake, tools
+from conans import ConanFile, tools
+from conans.errors import ConanInvalidConfiguration
+from conans.tools import os_info
+import os
 
 
 
 
 class ZlibConan(ConanFile):
 class ZlibConan(ConanFile):
     name = "zlib"
     name = "zlib"
     version = "1.2.11"
     version = "1.2.11"
-    license = "<Put the package license here>"
-    author = "<Put your name here> <And your email here>"
-    url = "<Package recipe repository url here, for issues about the package>"
-    description = "<Description of Zlib here>"
-    topics = ("<Put some tag here>", "<here>", "<and here>")
+    license = "Zlib"
+    author = "Shawn Morford <DarkMorford@Gmail.com>"
+    url = "https://code.darkmorford.net/conan-pkg/zlib"
+    description = "A Massively Spiffy Yet Delicately Unobtrusive Compression Library"
+    homepage = "http://zlib.net/"
+    topics = ("compression", "utility")
+    exports_sources = ["patches/*"]
     settings = "os", "compiler", "build_type", "arch"
     settings = "os", "compiler", "build_type", "arch"
     options = {"shared": [True, False]}
     options = {"shared": [True, False]}
     default_options = {"shared": False}
     default_options = {"shared": False}
-    generators = "cmake"
+
+    @property
+    def subfolder(self):
+        return os.path.join(self.source_folder, f"zlib-{self.version}")
+
+    def configure(self):
+        del self.settings.compiler.cppstd
+        del self.settings.compiler.libcxx
 
 
     def source(self):
     def source(self):
-        self.run("git clone https://github.com/conan-io/hello.git")
-        # This small hack might be useful to guarantee proper /MT /MD linkage
-        # in MSVC if the packaged project doesn't have variables to set it
-        # properly
-        tools.replace_in_file("hello/CMakeLists.txt", "PROJECT(HelloWorld)",
-                              '''PROJECT(HelloWorld)
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup()''')
+        tools.get(**self.conan_data["sources"][self.version])
+        for patch in self.conan_data["patches"][self.version]:
+            tools.patch(base_path=self.subfolder, **patch)
+
+    def _build_nmake(self):
+        flags = [f"-{self.settings.compiler.runtime}"]
+        if self.settings.build_type == "Debug":
+            flags.append("-Od")
+        else:
+            flags.append("-O2")
+        with tools.vcvars(self.settings), tools.chdir(self.subfolder):
+            makefile = os.path.join("win32", "Makefile.msc")
+            flags = " ".join(flags)
+            self.run(f'nmake -f "{makefile}" LOC="{flags}"')
 
 
     def build(self):
     def build(self):
-        cmake = CMake(self)
-        cmake.configure(source_folder="hello")
-        cmake.build()
+        if self.settings.compiler == "Visual Studio" and os_info.is_windows:
+            self._build_nmake()
+        else:
+            raise ConanInvalidConfiguration("This configuration is not yet supported.")
 
 
-        # Explicit way:
-        # self.run('cmake %s/hello %s'
-        #          % (self.source_folder, cmake.command_line))
-        # self.run("cmake --build . %s" % cmake.build_config)
+    def build_id(self):
+        if self.settings.compiler == "Visual Studio":
+            self.info_build.options.shared = "Both"
 
 
     def package(self):
     def package(self):
         self.copy("*.h", dst="include", src="hello")
         self.copy("*.h", dst="include", src="hello")
@@ -44,6 +62,3 @@ conan_basic_setup()''')
 
 
     def package_info(self):
     def package_info(self):
         self.cpp_info.libs = ["hello"]
         self.cpp_info.libs = ["hello"]
-
-    def configure(self):
-        del self.settings.compiler.libcxx

+ 12 - 0
patches/001-remove-default-cflags.patch

@@ -0,0 +1,12 @@
+diff -Naur a/win32/Makefile.msc b/win32/Makefile.msc
+--- a/win32/Makefile.msc	2017-01-15 09:07:08.000000000 -0800
++++ b/win32/Makefile.msc	2019-12-15 11:50:46.690189400 -0800
+@@ -26,7 +26,7 @@
+ LD = link
+ AR = lib
+ RC = rc
+-CFLAGS  = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
++CFLAGS  = -nologo -W3 -Oy- -Zi -Fd"zlib" $(LOC)
+ WFLAGS  = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE
+ ASFLAGS = -coff -Zi $(LOC)
+ LDFLAGS = -nologo -debug -incremental:no -opt:ref