use __has_include

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2023-01-27 21:41:53 -08:00
parent 376638259d
commit d874fc4dd8
6 changed files with 29 additions and 57 deletions

View File

@ -26,7 +26,7 @@
// + standard includes
#include <sys/stat.h> // for stat()
#include <sys/types.h> // for stat()
#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
#include <unistd.h> // for stat()
#endif

View File

@ -9,9 +9,6 @@
// Define if you require webready support.
#cmakedefine EXV_ENABLE_WEBREADY
// Define if you have the <libintl.h> header file.
#cmakedefine EXV_HAVE_LIBINTL_H
// Define if you want translation of program messages to the user's native language
#cmakedefine EXV_ENABLE_NLS
@ -44,15 +41,6 @@
// Define if you have the munmap function.
#cmakedefine EXV_HAVE_MUNMAP
/* Define if you have the <libproc.h> header file. */
#cmakedefine EXV_HAVE_LIBPROC_H
/* Define if you have the <unistd.h> header file. */
#cmakedefine EXV_HAVE_UNISTD_H
// Define if you have the <sys/mman.h> header file.
#cmakedefine EXV_HAVE_SYS_MMAN_H
// Define if you have the zlib library.
#cmakedefine EXV_HAVE_LIBZ

View File

@ -26,7 +26,7 @@
// getopt.{cpp|hpp} is not part of libexiv2
#include "getopt.hpp"
#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
#include <iostream>
@ -79,7 +79,7 @@ int main(int argc, char** const argv) {
int n;
#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
std::cout << "standard getopt()" << std::endl;
do {
n = ::getopt(argc, argv, ::optstring);

View File

@ -11,10 +11,6 @@
#include "image_int.hpp"
#include "types.hpp"
// + standard includes
#include <fcntl.h> // _O_BINARY in FileIo::FileIo
#include <sys/stat.h> // for stat, chmod
#include <cstdio> // for remove, rename
#include <cstdlib> // for alloc, realloc, free
#include <cstring> // std::memcpy
@ -22,14 +18,18 @@
#include <fstream> // write the temporary file
#include <iostream>
#ifdef EXV_HAVE_SYS_MMAN_H
// + standard includes
#include <fcntl.h> // _O_BINARY in FileIo::FileIo
#include <sys/stat.h> // for stat, chmod
#if __has_include(<sys/mman.h>)
#include <sys/mman.h> // for mmap and munmap
#endif
#ifdef EXV_HAVE_PROCESS_H
#if __has_include(<process.h>)
#include <process.h>
#endif
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for getpid, stat
#if __has_include(<unistd.h>)
#include <unistd.h>
#endif
#ifdef EXV_USE_CURL

View File

@ -30,10 +30,14 @@ namespace fs = std::experimental::filesystem;
// clang-format on
#endif
#if defined(__APPLE__) && defined(EXV_HAVE_LIBPROC_H)
#if __has_include(<libproc.h>)
#include <libproc.h>
#endif
#if __has_include(<unistd.h>)
#include <unistd.h> // for stat()
#endif
#if defined(__FreeBSD__)
#include <libprocstat.h>
#include <sys/mount.h>
@ -45,10 +49,6 @@ namespace fs = std::experimental::filesystem;
#include <sys/un.h>
#endif
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for stat()
#endif
#ifndef _MAX_PATH
#define _MAX_PATH 1024
#endif
@ -346,14 +346,12 @@ std::string getProcessPath() {
}
CloseHandle(processHandle);
}
#elif defined(__APPLE__)
#ifdef EXV_HAVE_LIBPROC_H
#elif __has_include(<libproc.h>)
const int pid = getpid();
char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
if (proc_pidpath(pid, pathbuf, sizeof(pathbuf)) > 0) {
ret = pathbuf;
}
#endif
#elif defined(__FreeBSD__)
unsigned int n;
char buffer[PATH_MAX] = {};

View File

@ -312,7 +312,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
int enable_video = 0;
int use_curl = 0;
#ifdef EXV_HAVE_INTTYPES_H
#if __has_include(<inttypes.h>)
have_inttypes = 1;
#endif
@ -324,21 +324,23 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_iconv = 1;
#endif
#ifdef EXV_HAVE_LIBINTL_H
#if __has_include(<libintl.h>)
have_libintl = 1;
#endif
#ifdef EXV_HAVE_MEMORY_H
#if __has_include(<memory.h>)
have_memory = 1;
#endif
#ifdef EXV_HAVE_STDBOOL_H
#if __has_include(<stdbool.h>)
have_stdbool = 1;
#endif
#if __has_include(<stdint.h>)
have_stdint = 1;
#endif
#ifdef EXV_HAVE_STDLIB_H
#if __has_include(<stdlib.h>)
have_stdlib = 1;
#endif
@ -346,7 +348,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_strerror_r = 1;
#endif
#ifdef EXV_HAVE_STRINGS_H
#if __has_include(<strings.h>)
have_strings = 1;
#endif
@ -358,19 +360,19 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_munmap = 1;
#endif
#ifdef EXV_HAVE_SYS_STAT_H
#if __has_include(<sys/stat.h>)
have_sys_stat = 1;
#endif
#ifdef EXV_HAVE_SYS_TYPES_H
#if __has_include(<sys/types.h>)
have_sys_types = 1;
#endif
#ifdef EXV_HAVE_UNISTD_H
#if __has_include(<unistd.h>)
have_unistd = 1;
#endif
#ifdef EXV_HAVE_SYS_MMAN_H
#if __has_include(<sys/mman.h>)
have_sys_mman = 1;
#endif
@ -390,22 +392,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
adobe_xmpsdk = EXV_ADOBE_XMPSDK;
#endif
#ifdef EXV_HAVE_BOOL
have_bool = 1;
#endif
#ifdef EXV_HAVE_STRINGS
have_strings = 1;
#endif
#ifdef EXV_SYS_TYPES
have_sys_types = 1;
#endif
#ifdef EXV_HAVE_UNISTD
have_unistd = 1;
#endif
#ifdef EXV_ENABLE_BMFF
enable_bmff = 1;
#endif