ソースを参照

Merge branch 'fix-msvc' into 'master'

Fix windows build

See merge request !1
Patrik Kovacs 6 年 前
コミット
0a194faf1c

+ 16 - 2
CMakeLists.txt

@@ -28,7 +28,7 @@ if (DOXYGEN_FOUND)
             )
 else ()
     message(WARNING "Doxygen not found")
-endif()
+endif ()
 
 add_library(hdf4cpp
         lib/HdfFile.cpp
@@ -36,6 +36,11 @@ add_library(hdf4cpp
         lib/HdfAttribute.cpp
         lib/HdfException.cpp
         include/hdf4cpp/HdfObject.h
+        include/hdf4cpp/HdfAttribute.h
+        include/hdf4cpp/HdfException.h
+        include/hdf4cpp/HdfFile.h
+        include/hdf4cpp/HdfItem.h
+        include/hdf4cpp/HdfDefines.h
         )
 
 target_include_directories(hdf4cpp
@@ -48,6 +53,13 @@ target_link_libraries(hdf4cpp
         ${HDF4_LIBRARIES}
         )
 
+if (MSVC)
+    target_compile_definitions(hdf4cpp PUBLIC
+            NEEDS_NORETURN
+            )
+endif ()
+
+
 enable_testing()
 find_package(GTest REQUIRED)
 find_package(Threads REQUIRED)
@@ -58,13 +70,15 @@ add_executable(hdf4cpp-tests
 target_include_directories(hdf4cpp-tests
         PRIVATE
         ${GTEST_INCLUDE_DIRS}
-        ${hdf4cpp_INCLUDE_DIRS}
         )
 target_link_libraries(hdf4cpp-tests
         ${GTEST_BOTH_LIBRARIES}
         ${CMAKE_THREAD_LIBS_INIT}
         hdf4cpp
         )
+target_compile_definitions(hdf4cpp-tests PRIVATE
+        GTEST_DONT_DEFINE_FAIL
+        GTEST_DONT_DEFINE_SUCCEED)
 
 
 if (NOT DEFINED TEST_DATA_PATH)

+ 37 - 24
cmake/FindHDF4.cmake

@@ -4,32 +4,45 @@
 #  HDF4_LIBRARIES - libraries to link against HDF4
 #  HDF4_FOUND - true if HDF4 has been found and can be used
 
-find_path(HDF4_INCLUDE_DIR hdf.h PATH_SUFFIXES hdf)
-find_library(MFHDF_LIB NAMES mfhdf mfhdfalt)
-find_library(DF_LIB NAMES df dfalt)
-
-# dependencies for the static library version of hdf4
-find_package(JPEG)
-find_package(ZLIB)
-
-set(HDF4_INCLUDE_DIRS ${HDF4_INCLUDE_DIR})
-set(HDF4_LIBRARIES
-  ${MFHDF_LIB}
-  ${DF_LIB}
-  ${JPEG_LIBRARIES}
-  ${ZLIB_LIBRARIES}
-  )
+
+find_package(HDF4 CONFIG QUIET)
+
+if (HDF4_FOUND)
+    set(HDF4_LIBRARIES hdf4::mfhdf-static hdf4::hdf-static)
+    set(HDF4_INCLUDE_DIRS
+            $<TARGET_PROPERTY:hdf4::mfhdf-static,INTERFACE_INCLUDE_DIRECTORIES>
+            $<TARGET_PROPERTY:hdf4::hdf-static,INTERFACE_INCLUDE_DIRECTORIES>)
+else ()
+    find_path(HDF4_INCLUDE_DIRS hdf.h PATH_SUFFIXES hdf)
+    find_library(MFHDF_LIB NAMES mfhdf mfhdfalt)
+    find_library(HDF_LIB NAMES df dfalt hdf)
+
+    # dependencies for the static library version of hdf4
+    find_package(JPEG)
+    find_package(ZLIB)
+
+    if (NOT (MFHDF_LIB AND HDF_LIB AND JPEG_LIBRARIES AND ZLIB_LIBRARIES))
+        set (HDF4_LIBRARIES HDF4_LIBRARIES-NOTFOUND)
+    else()
+        set(HDF4_LIBRARIES
+                ${MFHDF_LIB}
+                ${HDF_LIB}
+                ${JPEG_LIBRARIES}
+                ${ZLIB_LIBRARIES}
+                )
+    endif ()
+endif ()
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(HDF4
-	FOUND_VAR HDF4_FOUND
-	REQUIRED_VARS MFHDF_LIB DF_LIB HDF4_INCLUDE_DIR JPEG_LIBRARIES ZLIB_LIBRARIES) 
+        FOUND_VAR HDF4_FOUND
+        REQUIRED_VARS HDF4_INCLUDE_DIRS HDF4_LIBRARIES)
 
-if(HDF4_FOUND)
-	message(-- " HDF4 include path: ${HDF4_INCLUDE_DIRS}")
-	message(-- " HDF4 libs:  ${HDF4_LIBRARIES}")
-else()
-	message(WARNING "HDF4 not found")	
-endif()
+if (HDF4_FOUND)
+    message(-- " HDF4 include path: ${HDF4_INCLUDE_DIRS}")
+    message(-- " HDF4 libs:  ${HDF4_LIBRARIES}")
+else ()
+    message(WARNING "HDF4 not found")
+endif ()
 
-mark_as_advanced(HDF4_INCLUDE_DIR MFHDF_LIB DF_LIB)
+mark_as_advanced(HDF4_INCLUDE_DIR HDF4_LIBRARIES)

+ 11 - 11
include/hdf4cpp/HdfAttribute.h

@@ -4,7 +4,7 @@
 #ifndef HDF4CPP_HDFATTRIBUTE_H
 #define HDF4CPP_HDFATTRIBUTE_H
 
-#include <hdf/hdfi.h>
+#include <hdfi.h>
 #include <hdf4cpp/HdfItem.h>
 #include <hdf4cpp/HdfObject.h>
 
@@ -28,7 +28,7 @@ class HdfAttribute : public HdfObject {
         }
 
         /// \returns The number of existing data in the attribute
-        virtual intn size() const = 0;
+        virtual int32 size() const = 0;
 
         /// \returns The data type number of the data held by the attribute
         virtual int32 getDataType() const = 0;
@@ -48,10 +48,10 @@ class HdfAttribute : public HdfObject {
       public:
         HdfDatasetAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
-        intn size() const;
+        int32 size() const;
 
       private:
-        intn _size;
+        int32 _size;
         int32 dataType;
 
         void get(void *dest);
@@ -63,10 +63,10 @@ class HdfAttribute : public HdfObject {
       public:
         HdfGroupAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
-        intn size() const;
+        int32 size() const;
 
       private:
-        intn _size;
+        int32 _size;
         int32 dataType;
 
         void get(void *dest);
@@ -78,10 +78,10 @@ class HdfAttribute : public HdfObject {
       public:
         HdfDataAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
-        intn size() const;
+        int32 size() const;
 
       private:
-        intn _size;
+        int32 _size;
         int32 dataType;
         void get(void *dest);
         int32 getDataType() const;
@@ -93,12 +93,12 @@ class HdfAttribute : public HdfObject {
     HdfAttribute &operator=(const HdfAttribute &attribute) = delete;
     HdfAttribute &operator=(HdfAttribute &&attribute);
     /// \returns the number of elements of the attribute data
-    intn size() const;
+    int32 size() const;
 
     /// Reads the data from the attribute
     /// \param dest the vector in which the data will be stored
     template <class T> void get(std::vector<T> &dest) {
-        intn length = size();
+        int32 length = size();
         auto it = typeSizeMap.find(getDataType());
         if (it != typeSizeMap.end()) {
             if ((size_t)it->second != sizeof(T)) {
@@ -128,4 +128,4 @@ class HdfAttribute : public HdfObject {
 };
 }
 
-#endif // HDF4CPP_HDFATTRIBUTE_H
+#endif //HDF4CPP_HDFATTRIBUTE_H

+ 7 - 1
include/hdf4cpp/HdfDefines.h

@@ -5,8 +5,14 @@
 #ifndef HDF4CPP_HDFDEFINES_H
 #define HDF4CPP_HDFDEFINES_H
 
-#include <hdf/mfhdf.h>
 #include <map>
+#include <mfhdf.h>
+
+#ifdef NEEDS_NORETURN
+#define NORETURN __declspec(noreturn)
+#else
+#define NORETURN
+#endif
 
 #define MAX_DIMENSION 32
 #define MAX_NAME_LENGTH 1000

+ 10 - 10
include/hdf4cpp/HdfItem.h

@@ -10,7 +10,7 @@
 #include <hdf4cpp/HdfFile.h>
 
 #include <algorithm>
-#include <hdf/hdf.h>
+#include <hdf.h>
 #include <map>
 #include <memory>
 #include <vector>
@@ -35,7 +35,7 @@ struct Range {
     }
 
     /// What would be the number of data to read, if we read in this range
-    intn size() const {
+    int32 size() const {
         if (!stride) {
             return 0;
         }
@@ -73,7 +73,7 @@ class HdfItem : public HdfObject {
     std::vector<int32> getDims();
 
     /// \returns The number of data being in the item
-    intn size() const;
+    int32 size() const;
 
     /// \returns the attribute of the item with the given name
     /// \param name the name of the attribute
@@ -156,7 +156,7 @@ class HdfItem : public HdfObject {
         /// Get the dimensions of the item
         virtual std::vector<int32> getDims() = 0;
         /// Get the number of data from the item
-        virtual intn size() const = 0;
+        virtual int32 size() const = 0;
         /// Get the attribute from the item given by its name
         virtual HdfAttribute getAttribute(const std::string &name) const = 0;
 
@@ -174,7 +174,7 @@ class HdfItem : public HdfObject {
         int32 getId() const;
         std::string getName() const;
         std::vector<int32> getDims();
-        intn size() const;
+        int32 size() const;
         HdfAttribute getAttribute(const std::string &name) const;
 
         /// Reads the data in a specific range. See Range
@@ -183,7 +183,7 @@ class HdfItem : public HdfObject {
         template <class T> void read(std::vector<T> &dest, std::vector<Range> &ranges) {
             std::vector<int32> dims = getDims();
             Range::fill(ranges, dims);
-            intn length = 1;
+            int32 length = 1;
             for (size_t i = 0; i < ranges.size(); ++i) {
                 if (!ranges[i].check(dims[i])) {
                     raiseException(INVALID_RANGES);
@@ -223,7 +223,7 @@ class HdfItem : public HdfObject {
         }
 
       private:
-        intn _size;
+        int32 _size;
         int32 dataType;
         std::string name;
         std::vector<int32> dims;
@@ -239,7 +239,7 @@ class HdfItem : public HdfObject {
         int32 getId() const;
         std::string getName() const;
         std::vector<int32> getDims();
-        intn size() const;
+        int32 size() const;
 
         HdfAttribute getAttribute(const std::string &name) const;
 
@@ -261,7 +261,7 @@ class HdfItem : public HdfObject {
 
         std::vector<int32> getDims();
 
-        intn size() const;
+        int32 size() const;
 
         HdfAttribute getAttribute(const std::string &name) const;
 
@@ -347,7 +347,7 @@ class HdfItem : public HdfObject {
         }
 
       private:
-        intn _size;
+        int32 _size;
         std::string name;
 
         int32 nrRecords;

+ 2 - 2
include/hdf4cpp/HdfObject.h

@@ -83,12 +83,12 @@ class HdfObject {
     }
 
     /// Throws an HdfException by its type
-    virtual void raiseException(const ExceptionType &exceptionType) const {
+    NORETURN void raiseException(const ExceptionType &exceptionType) const {
         throw HdfException(type, classType, exceptionType);
     }
 
     /// Thorws an HdfException by its message, the type will be OTHER.
-    virtual void raiseException(const std::string &message) const {
+    NORETURN void raiseException(const std::string &message) const {
         throw HdfException(type, classType, message);
     }
 

+ 5 - 5
lib/HdfAttribute.cpp

@@ -17,7 +17,7 @@ hdf4cpp::HdfAttribute::HdfDatasetAttribute::HdfDatasetAttribute(int32 id,
         raiseException(STATUS_RETURN_FAIL);
     }
 }
-intn hdf4cpp::HdfAttribute::HdfDatasetAttribute::size() const {
+int32 hdf4cpp::HdfAttribute::HdfDatasetAttribute::size() const {
     return _size;
 }
 int32 hdf4cpp::HdfAttribute::HdfDatasetAttribute::getDataType() const {
@@ -39,7 +39,7 @@ hdf4cpp::HdfAttribute::HdfGroupAttribute::HdfGroupAttribute(int32 id,
                                                             const std::string &name,
                                                             const HdfDestroyerChain &chain)
     : HdfAttributeBase(id, 0, VGROUP, chain) {
-    int32 nrAtts = Vnattrs2(id);
+    intn nrAtts = Vnattrs2(id);
     for (intn i = 0; i < nrAtts; ++i) {
         char names[MAX_NAME_LENGTH];
         int32 type, count, size, nFields;
@@ -54,7 +54,7 @@ hdf4cpp::HdfAttribute::HdfGroupAttribute::HdfGroupAttribute(int32 id,
     }
     raiseException(INVALID_NAME);
 }
-intn hdf4cpp::HdfAttribute::HdfGroupAttribute::size() const {
+int32 hdf4cpp::HdfAttribute::HdfGroupAttribute::size() const {
     return _size;
 }
 int32 hdf4cpp::HdfAttribute::HdfGroupAttribute::getDataType() const {
@@ -73,7 +73,7 @@ hdf4cpp::HdfAttribute::HdfDataAttribute::HdfDataAttribute(int32 id,
         raiseException(STATUS_RETURN_FAIL);
     }
 }
-intn hdf4cpp::HdfAttribute::HdfDataAttribute::size() const {
+int32 hdf4cpp::HdfAttribute::HdfDataAttribute::size() const {
     return _size;
 }
 void hdf4cpp::HdfAttribute::HdfDataAttribute::get(void *dest) {
@@ -94,7 +94,7 @@ hdf4cpp::HdfAttribute &hdf4cpp::HdfAttribute::operator=(HdfAttribute &&attr) {
     setClassType(attribute->getClassType());
     return *this;
 }
-intn hdf4cpp::HdfAttribute::size() const {
+int32 hdf4cpp::HdfAttribute::size() const {
     return attribute->size();
 }
 HdfAttribute::HdfAttribute(HdfAttributeBase *attribute)

+ 1 - 1
lib/HdfFile.cpp

@@ -2,7 +2,7 @@
 /// \author Patrik Kovacs, Catalysts GmbH
 
 
-#include <hdf/mfhdf.h>
+#include <mfhdf.h>
 #include <stdexcept>
 
 #include <hdf4cpp/HdfDefines.h>

+ 7 - 7
lib/HdfItem.cpp

@@ -2,11 +2,11 @@
 /// \author Patrik Kovacs, Catalysts GmbH
 
 
-#include <hdf/mfhdf.h>
+#include <hdf4cpp/HdfAttribute.h>
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
+#include <mfhdf.h>
 #include <sstream>
-#include <hdf4cpp/HdfAttribute.h>
 
 hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain &chain)
     : HdfItemBase(id, SDATA, chain) {
@@ -37,7 +37,7 @@ int32 hdf4cpp::HdfItem::HdfDatasetItem::getDataType() const {
 }
 hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
 }
-intn hdf4cpp::HdfItem::HdfDatasetItem::size() const {
+int32 hdf4cpp::HdfItem::HdfDatasetItem::size() const {
     return _size;
 }
 hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
@@ -61,7 +61,7 @@ int32 hdf4cpp::HdfItem::HdfGroupItem::getId() const {
 }
 hdf4cpp::HdfItem::HdfGroupItem::~HdfGroupItem() {
 }
-intn hdf4cpp::HdfItem::HdfGroupItem::size() const {
+int32 hdf4cpp::HdfItem::HdfGroupItem::size() const {
     raiseException(INVALID_OPERATION);
 }
 int32 hdf4cpp::HdfItem::HdfGroupItem::getDataType() const {
@@ -88,7 +88,7 @@ std::string hdf4cpp::HdfItem::HdfDataItem::getName() const {
 std::vector<int32> hdf4cpp::HdfItem::HdfDataItem::getDims() {
     raiseException(INVALID_OPERATION);
 }
-intn hdf4cpp::HdfItem::HdfDataItem::size() const {
+int32 hdf4cpp::HdfItem::HdfDataItem::size() const {
     raiseException(INVALID_OPERATION);
 }
 int32 hdf4cpp::HdfItem::HdfDataItem::getDataType() const {
@@ -119,7 +119,7 @@ hdf4cpp::HdfAttribute hdf4cpp::HdfItem::getAttribute(const std::string &name) co
 std::string hdf4cpp::HdfItem::getName() const {
     return item->getName();
 }
-intn hdf4cpp::HdfItem::size() const {
+int32 hdf4cpp::HdfItem::size() const {
     return item->size();
 }
 hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
@@ -133,4 +133,4 @@ hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
     }
     default: { return Iterator(sId, vId, item->getId(), 0, getType(), chain); }
     }
-}
+}

+ 2 - 2
tests/HdfFileTest.cpp

@@ -39,7 +39,7 @@ TEST_F(HdfFileTest, ReadData2) {
     HdfItem item = file.get("DataWithAttributes");
     std::vector<float32> vec;
     item.read(vec);
-    ASSERT_EQ(vec, std::vector<float32>({0.0, 0.1, 0.2, 1.0, 1.1, 1.2, 2.0, 2.1, 2.2}));
+    ASSERT_EQ(vec, std::vector<float32>({0.0f, 0.1f, 0.2f, 1.0f, 1.1f, 1.2f, 2.0f, 2.1f, 2.2f}));
 }
 
 TEST_F(HdfFileTest, ReadDatasetAttributes) {
@@ -96,7 +96,7 @@ TEST_F(HdfFileTest, ReadDataInRange) {
         HdfItem item = file.get("DataWithAttributes");
         std::vector<float32> vec;
         item.read(vec, std::vector<Range>({Range(2, 1), Range(0, 2)}));
-        ASSERT_EQ(vec, std::vector<float32>({2.0, 2.1}));
+        ASSERT_EQ(vec, std::vector<float32>({2.0f, 2.1f}));
     }
 }