summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt9
-rw-r--r--include/tng_io.h59
-rw-r--r--src/lib/CMakeLists.txt4
-rw-r--r--src/lib/tng_io.c3
-rw-r--r--src/tests/CMakeLists.txt4
-rw-r--r--src/tests/tng_io_testing.c3
6 files changed, 79 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6c84303..3a810af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,14 +11,17 @@ option(BUILD_FORTRAN "Build Fortran examples" OFF)
option(USE_OPENMP "Try to use the OpenMP library (if available)" ON)
if(USE_OPENMP)
- FIND_PACKAGE(OpenMP)
+ find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
endif()
-FIND_PACKAGE(ZLIB)
+find_package(ZLIB)
+
+include(CheckIncludeFile)
+check_include_file(inttypes.h HAVE_INTTYPES_H)
add_subdirectory(src)
@@ -27,7 +30,7 @@ file(COPY example_files DESTINATION .)
#-- Add an Option to toggle the generation of the API documentation
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
if(BUILD_DOCUMENTATION)
- FIND_PACKAGE(Doxygen)
+ find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR
"Doxygen is needed to build the documentation. Please install it correctly")
diff --git a/include/tng_io.h b/include/tng_io.h
index ea2add5..6acbe47 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -225,7 +225,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
+
+#ifdef USE_STD_INTTYPES_H
#include <inttypes.h>
+#else
+
+/* Visual Studio does not contain inttypes.h and stdint.h. Some defines and
+ * typedefs are used from the GNU C Library */
+
+/* This first part is from stdint.h (GNU C Library) */
+#ifndef __int8_t_defined
+# define __int8_t_defined
+typedef signed char int8_t;
+typedef short int int16_t;
+typedef int int32_t;
+# if __WORDSIZE == 64
+typedef long int int64_t;
+# else
+__extension__
+typedef long long int int64_t;
+# endif
+#endif
+
+typedef unsigned char uint8_t;
+typedef unsigned short int uint16_t;
+#ifndef __uint32_t_defined
+typedef unsigned int uint32_t;
+# define __uint32_t_defined
+#endif
+#if __WORDSIZE == 64
+typedef unsigned long int uint64_t;
+#else
+__extension__
+typedef unsigned long long int uint64_t;
+#endif
+
+/* This is from inttypes.h (GNU C Library) */
+/* The ISO C99 standard specifies that these macros must only be
+ defined if explicitly requested. */
+#if !defined __cplusplus || defined __STDC_FORMAT_MACROS
+
+# if __WORDSIZE == 64
+# define __PRI64_PREFIX "l"
+# define __PRIPTR_PREFIX "l"
+# else
+# define __PRI64_PREFIX "ll"
+# define __PRIPTR_PREFIX
+# endif
+
+/* From stdint.h (GNU C Library) */
+/* Macros for printing format specifiers. */
+/* Decimal notation. */
+# define PRId8 "d"
+# define PRId16 "d"
+# define PRId32 "d"
+# define PRId64 __PRI64_PREFIX "d"
+#endif
+
+#endif
+
/** The version of this TNG build */
#define TNG_VERSION 2
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index b6fd655..18cf32f 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -1,5 +1,9 @@
add_library(tng_io SHARED tng_io.c md5.c)
+if(HAVE_INTTYPES_H)
+ set_target_properties(tng_io PROPERTIES COMPILE_DEFINITIONS USE_STD_INTTYPES_H=1)
+endif()
+
if(ZLIB_FOUND)
set_target_properties(tng_io PROPERTIES COMPILE_DEFINITIONS USE_ZLIB=1)
target_link_libraries(tng_io ${ZLIB_LIBRARIES})
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 5971c30..82568e9 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -13,7 +13,10 @@
* of the License, or (at your option) any later version.
*/
+#ifdef USE_STD_INTTYPES_H
#include <inttypes.h>
+#endif
+
#include <limits.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 8ec785b..4a63c54 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -13,6 +13,10 @@ include_directories(${CMAKE_BINARY_DIR}/generated/)
add_executable(tng_testing tng_io_testing.c)
target_link_libraries(tng_testing tng_io)
+if(HAVE_INTTYPES_H)
+ set_target_properties(tng_testing PROPERTIES COMPILE_DEFINITIONS USE_STD_INTTYPES_H=1)
+endif()
+
if(OPENMP_FOUND)
add_executable(md_openmp md_openmp.c)
target_link_libraries(md_openmp tng_io ${OpenMP_LIBS} m)
diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c
index a8782f2..133a1fb 100644
--- a/src/tests/tng_io_testing.c
+++ b/src/tests/tng_io_testing.c
@@ -13,7 +13,10 @@
* of the License, or (at your option) any later version.
*/
+#ifdef USE_STD_INTTYPES_H
#include <inttypes.h>
+#endif
+
#include <stdlib.h>
#include <string.h>
#include <tng_io.h>
contact: Jan Huwald // Impressum