فهرست منبع

Fix linux build

Moritz Wanzenböck 6 سال پیش
والد
کامیت
395ef4e6e5
4فایلهای تغییر یافته به همراه68 افزوده شده و 10 حذف شده
  1. 15 8
      CMakeLists.txt
  2. 45 0
      cmake/FindHDF4.cmake
  3. 6 0
      include/hdf4cpp/HdfDefines.h
  4. 2 2
      include/hdf4cpp/HdfObject.h

+ 15 - 8
CMakeLists.txt

@@ -28,7 +28,7 @@ if (DOXYGEN_FOUND)
             )
 else ()
     message(WARNING "Doxygen not found")
-endif()
+endif ()
 
 add_library(hdf4cpp
         lib/HdfFile.cpp
@@ -36,12 +36,12 @@ add_library(hdf4cpp
         lib/HdfAttribute.cpp
         lib/HdfException.cpp
         include/hdf4cpp/HdfObject.h
-		include/hdf4cpp/HdfAttribute.h
-		include/hdf4cpp/HdfAttribute_priv.h
-		include/hdf4cpp/HdfException.h
-		include/hdf4cpp/HdfFile.h
-		include/hdf4cpp/HdfItem.h
-		include/hdf4cpp/HdfDefines.h
+        include/hdf4cpp/HdfAttribute.h
+        include/hdf4cpp/HdfAttribute_priv.h
+        include/hdf4cpp/HdfException.h
+        include/hdf4cpp/HdfFile.h
+        include/hdf4cpp/HdfItem.h
+        include/hdf4cpp/HdfDefines.h
         )
 
 target_include_directories(hdf4cpp
@@ -51,9 +51,16 @@ target_include_directories(hdf4cpp
         )
 
 target_link_libraries(hdf4cpp
-		hdf4::mfhdf-static
+        ${HDF4_LIBRARIES}
         )
 
+if (MSVC)
+    target_compile_definitions(hdf4cpp PUBLIC
+            NEEDS_NORETURN
+            )
+endif ()
+
+
 enable_testing()
 find_package(GTest REQUIRED)
 find_package(Threads REQUIRED)

+ 45 - 0
cmake/FindHDF4.cmake

@@ -0,0 +1,45 @@
+# - Find the HDF4 library together with dependencies...
+# This module defines the following variables:
+#  HDF4_INCLUDE_DIRS - include directories for HDF4
+#  HDF4_LIBRARIES - libraries to link against HDF4
+#  HDF4_FOUND - true if HDF4 has been found and can be used
+
+
+find_package(HDF4 CONFIG QUIET)
+
+if (HDF4_FOUND)
+    set(HDF4_LIBRARIES hdf4::mfhdf-static hdf4::hdf-static)
+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 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 ()
+
+mark_as_advanced(HDF4_INCLUDE_DIR HDF4_LIBRARIES)

+ 6 - 0
include/hdf4cpp/HdfDefines.h

@@ -8,6 +8,12 @@
 #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
 

+ 2 - 2
include/hdf4cpp/HdfObject.h

@@ -83,12 +83,12 @@ class HdfObject {
     }
 
     /// Throws an HdfException by its type
-	__declspec(noreturn) 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.
-	__declspec(noreturn) void raiseException(const std::string &message) const {
+    NORETURN void raiseException(const std::string &message) const {
         throw HdfException(type, classType, message);
     }