From 7ca81678afc3b2c6ef79ed44774ad4b7172a1536 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Wed, 17 Oct 2012 03:43:44 +0400 Subject: [PATCH] Handle err.h functions on windows --- CMakeLists.txt | 20 ++++++++++++++++---- compat/err.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 compat/err.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f50c3..c9c5dc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,24 @@ INCLUDE_DIRECTORIES(${TTIP_INCLUDE_DIRS}) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") -IF(NOT WIN32) - ADD_DEFINITIONS(-DHAVE_FORK) -ENDIF(NOT WIN32) - ADD_DEFINITIONS(-std=c99) +INCLUDE(CheckFunctionExists) +INCLUDE(CheckIncludeFile) + +CHECK_FUNCTION_EXISTS(fork HAVE_FORK) +CHECK_INCLUDE_FILE(err.h HAVE_ERR_H) + +IF(HAVE_FORK) + ADD_DEFINITIONS(-DHAVE_FORK) +ENDIF(HAVE_FORK) +IF(NOT HAVE_ERR_H) + INCLUDE_DIRECTORIES(compat) # err.h compatibility for windows/mingw +ENDIF(NOT HAVE_ERR_H) +IF(WIN32) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mconsole") +ENDIF(WIN32) + # sources SET(TILETOOL_SRCS tiletool/bounds.c diff --git a/compat/err.h b/compat/err.h new file mode 100644 index 0000000..f6ae340 --- /dev/null +++ b/compat/err.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012 Dmitry Marakasov + * + * This file is part of tiletool. + * + * tiletool is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * tiletool is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with tiletool. If not, see . + */ + +#ifndef COMPAT_ERR_H +#define COMPAT_ERR_H + +#include +#include + +#define warn(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); } while (0) +#define warnx(...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } while (0) +#define err(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, ": %s\n", strerror(errno)); exit(eval); } while (0) +#define errx(eval, ...) do { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(eval); } while (0) + +#endif