[libzomg] Fixed build issues when a system libpng isn't present.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 12 Sep 2015 16:11:21 +0000 (12:11 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Sat, 12 Sep 2015 16:11:21 +0000 (12:11 -0400)
Define the PNG typedefs like before, but only if PNG_H isn't defined,
i.e. png.h hasn't been included.

Note that this means that if you #include "Metadata.hpp" and <png.h>
in the same file, you *must* #include <png.h> first.

src/libzomg/Metadata.cpp
src/libzomg/Metadata.hpp
src/libzomg/PngWriter.cpp

index b4795c7..9c5b96b 100644 (file)
 // _POSIX_SOURCE and _POSIX_C_SOURCE definitions.
 #include "libcompat/reentrant.h"
 
-// Ensure CPU_Flags is initialized.
-#include "libcompat/cpuflags.h"
+// libpng
+// MUST be included before Metadata.hpp.
+#include <png.h>
 
+// ZOMG metadata.
 #include "Metadata.hpp"
 
+// Ensure CPU_Flags is initialized.
+#include "libcompat/cpuflags.h"
+
 // C includes. (C++ namespace)
 #include <ctime>
 #include <cstring>
@@ -44,9 +49,6 @@ using std::string;
 using std::swap;
 using std::ostringstream;
 
-// libpng
-#include <png.h>
-
 // Platform-dependent newline constant.
 #ifdef _WIN32
 #define NL "\r\n"
index 5f4decc..d3eea88 100644 (file)
 // C++ includes.
 #include <string>
 
-// libpng
-// NOTE: The PNG struct definitions changed in libpng-1.5.0.
-// Instead of doing a bunch of complicated maneuvers to get
-// it working without including png.h, just include png.h.
-#include <png.h>
+// PNG structs.
+// NOTE: Copied fron png.h to avoid having to include it here.
+// NOTE: If you're using png.h, include it *before* Metadata.hpp
+// in order to prevent duplicate definitions.
+#ifndef PNG_H
+extern "C" {
+struct png_struct_def;
+typedef struct png_struct_def png_struct;
+typedef png_struct * png_structp;
+
+struct png_info_def;
+typedef struct png_info_def png_info;
+typedef png_info * png_infop;
+}
+#endif
 
 namespace LibZomg {
 
index 2370b85..6112ba2 100644 (file)
 #include "PngWriter.hpp"
 #include "img_data.h"
 
-// ZOMG metadata.
-#include "Metadata.hpp"
-
 // libpng
+// MUST be included before Metadata.hpp.
 #include <png.h>
 
+// ZOMG metadata.
+#include "Metadata.hpp"
+
 // MiniZip
 #include "minizip/zip.h"