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 // + standard includes
#include <sys/stat.h> // for stat() #include <sys/stat.h> // for stat()
#include <sys/types.h> // for stat() #include <sys/types.h> // for stat()
#ifdef EXV_HAVE_UNISTD_H #if __has_include(<unistd.h>)
#include <unistd.h> // for stat() #include <unistd.h> // for stat()
#endif #endif

View File

@ -9,9 +9,6 @@
// Define if you require webready support. // Define if you require webready support.
#cmakedefine EXV_ENABLE_WEBREADY #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 // Define if you want translation of program messages to the user's native language
#cmakedefine EXV_ENABLE_NLS #cmakedefine EXV_ENABLE_NLS
@ -44,15 +41,6 @@
// Define if you have the munmap function. // Define if you have the munmap function.
#cmakedefine EXV_HAVE_MUNMAP #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. // Define if you have the zlib library.
#cmakedefine EXV_HAVE_LIBZ #cmakedefine EXV_HAVE_LIBZ

View File

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

View File

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

View File

@ -30,10 +30,14 @@ namespace fs = std::experimental::filesystem;
// clang-format on // clang-format on
#endif #endif
#if defined(__APPLE__) && defined(EXV_HAVE_LIBPROC_H) #if __has_include(<libproc.h>)
#include <libproc.h> #include <libproc.h>
#endif #endif
#if __has_include(<unistd.h>)
#include <unistd.h> // for stat()
#endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
#include <libprocstat.h> #include <libprocstat.h>
#include <sys/mount.h> #include <sys/mount.h>
@ -45,10 +49,6 @@ namespace fs = std::experimental::filesystem;
#include <sys/un.h> #include <sys/un.h>
#endif #endif
#ifdef EXV_HAVE_UNISTD_H
#include <unistd.h> // for stat()
#endif
#ifndef _MAX_PATH #ifndef _MAX_PATH
#define _MAX_PATH 1024 #define _MAX_PATH 1024
#endif #endif
@ -346,14 +346,12 @@ std::string getProcessPath() {
} }
CloseHandle(processHandle); CloseHandle(processHandle);
} }
#elif defined(__APPLE__) #elif __has_include(<libproc.h>)
#ifdef EXV_HAVE_LIBPROC_H
const int pid = getpid(); const int pid = getpid();
char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
if (proc_pidpath(pid, pathbuf, sizeof(pathbuf)) > 0) { if (proc_pidpath(pid, pathbuf, sizeof(pathbuf)) > 0) {
ret = pathbuf; ret = pathbuf;
} }
#endif
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
unsigned int n; unsigned int n;
char buffer[PATH_MAX] = {}; 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 enable_video = 0;
int use_curl = 0; int use_curl = 0;
#ifdef EXV_HAVE_INTTYPES_H #if __has_include(<inttypes.h>)
have_inttypes = 1; have_inttypes = 1;
#endif #endif
@ -324,21 +324,23 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_iconv = 1; have_iconv = 1;
#endif #endif
#ifdef EXV_HAVE_LIBINTL_H #if __has_include(<libintl.h>)
have_libintl = 1; have_libintl = 1;
#endif #endif
#ifdef EXV_HAVE_MEMORY_H #if __has_include(<memory.h>)
have_memory = 1; have_memory = 1;
#endif #endif
#ifdef EXV_HAVE_STDBOOL_H #if __has_include(<stdbool.h>)
have_stdbool = 1; have_stdbool = 1;
#endif #endif
#if __has_include(<stdint.h>)
have_stdint = 1; have_stdint = 1;
#endif
#ifdef EXV_HAVE_STDLIB_H #if __has_include(<stdlib.h>)
have_stdlib = 1; have_stdlib = 1;
#endif #endif
@ -346,7 +348,7 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_strerror_r = 1; have_strerror_r = 1;
#endif #endif
#ifdef EXV_HAVE_STRINGS_H #if __has_include(<strings.h>)
have_strings = 1; have_strings = 1;
#endif #endif
@ -358,19 +360,19 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
have_munmap = 1; have_munmap = 1;
#endif #endif
#ifdef EXV_HAVE_SYS_STAT_H #if __has_include(<sys/stat.h>)
have_sys_stat = 1; have_sys_stat = 1;
#endif #endif
#ifdef EXV_HAVE_SYS_TYPES_H #if __has_include(<sys/types.h>)
have_sys_types = 1; have_sys_types = 1;
#endif #endif
#ifdef EXV_HAVE_UNISTD_H #if __has_include(<unistd.h>)
have_unistd = 1; have_unistd = 1;
#endif #endif
#ifdef EXV_HAVE_SYS_MMAN_H #if __has_include(<sys/mman.h>)
have_sys_mman = 1; have_sys_mman = 1;
#endif #endif
@ -390,22 +392,6 @@ void Exiv2::dumpLibraryInfo(std::ostream& os, const std::vector<std::regex>& key
adobe_xmpsdk = EXV_ADOBE_XMPSDK; adobe_xmpsdk = EXV_ADOBE_XMPSDK;
#endif #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 #ifdef EXV_ENABLE_BMFF
enable_bmff = 1; enable_bmff = 1;
#endif #endif