Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2eec638e rédigé par Kubat's avatar Kubat
Parcourir les fichiers

BUILD: Add headers for W + detect OS with CMAKE and not crafted things in the C code

parent fa1ddc65
Branches
Étiquettes v1.0.5
1 requête de fusion!179Queue download if update asked per ID
Pipeline #2543 réussi
......@@ -86,20 +86,34 @@ endif()
if(WIN32)
message(STATUS "You are building on windows, pay attenion to the dependencies")
set(GENERATE_MANPAGES 0)
set(LKT_OS_WIN 1)
add_compile_definitions(LKT_OS_WIN=1)
endif()
if(MSVC OR MSYS OR MINGW)
message(STATUS "You are building with a windows compiler")
set(GENERATE_MANPAGES 0)
set(LKT_OS_MINGW 1)
add_compile_definitions(LKT_OS_MINGW=1)
endif()
if(APPLE)
message(STATUS "You are building on MacOS X")
find_program(MAN man REQUIRED)
set(GENERATE_MANPAGES 1)
set(LKT_OS_APPLE 1)
add_compile_definitions(LKT_OS_APPLE=1)
endif()
if(UNIX AND NOT APPLE)
message(STATUS "You are building on Linux, FreeBSD or any other toaster OS")
find_program(MAN man REQUIRED)
set(GENERATE_MANPAGES 1)
set(LKT_OS_TOASTER 1)
add_compile_definitions(LKT_OS_TOASTER=1)
endif()
# Check for the OS
if((NOT DEFINED LKT_OS_WIN) AND (NOT DEFINED LKT_OS_MINGW) AND
(NOT DEFINED LKT_OS_APPLE) AND (NOT DEFINED LKT_OS_TOASTER))
message(FATAL_ERROR "The OS is not recognized")
endif()
### ###
......@@ -180,35 +194,6 @@ set(luka_SOURCES
${lektor_mkv_SOURCES}
)
set(common_HEADERS
<stdnoreturn.h>
<endian.h>
<inttypes.h>
<locale.h>
<memory.h>
<regex.h>
<stddef.h>
<unistd.h>
<stdint.h>
<stdlib.h>
<strings.h>
<string.h>
<memory.h>
<limits.h>
<stdbool.h>
<stdarg.h>
<errno.h>
<pthread.h>
<stdio.h>
<time.h>
<ctype.h>
<fcntl.h>
<endian.h>
<sys/stat.h>
<sys/types.h>
<sys/time.h>
)
set(common_DEFINITIONS
LKT_ARCH="${CMAKE_SYSTEM_PROCESSOR}"
LKT_MAN_BINARY="${MAN}"
......@@ -302,9 +287,10 @@ target_compile_definitions(lektord PRIVATE ${common_DEFINITIONS})
target_compile_definitions(lkt PRIVATE ${common_DEFINITIONS})
target_compile_definitions(luka PRIVATE ${common_DEFINITIONS})
target_precompile_headers(lektord PRIVATE ${common_HEADERS})
target_precompile_headers(lkt PRIVATE ${common_HEADERS})
target_precompile_headers(luka PRIVATE ${common_HEADERS})
# TODO: The common header should be the OS header...
# target_precompile_headers(lektord PRIVATE ${common_HEADERS})
# target_precompile_headers(lkt PRIVATE ${common_HEADERS})
# target_precompile_headers(luka PRIVATE ${common_HEADERS})
target_compile_options(lektord PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS})
target_compile_options(lkt PRIVATE ${COMMON_C_FLAGS} ${${CMAKE_C_COMPILER_ID}_C_FLAGS})
......
#if !defined(LKT_OS_H__)
#define LKT_OS_H__
#pragma once
#if defined(__cplusplus)
/* If this file is included by a C++ file, noreturn is not defined... */
#define noreturn __attribute__((noreturn))
extern "C" {
#endif
#if !(__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN)
#error "Unsuported endiannes"
#endif
/* The common headers, include them here because LSP don't like the precompiled
* header built from the cmake file */
#include <stdnoreturn.h>
#include <endian.h>
#include <inttypes.h>
#include <locale.h>
#include <memory.h>
......@@ -34,17 +23,30 @@ extern "C" {
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#if defined(LKT_OS_TOASTER) && (LKT_OS_TOASTER == 1)
#include <linux/limits.h>
#include <dirent.h>
#include <fcntl.h>
#include <endian.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#endif
#if defined(__linux__)
#include <linux/limits.h>
#if defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)
#include "lektor/internal/win32/dirent.h"
#include "lektor/internal/win32/endian.h"
#endif
#if !(__BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __BIG_ENDIAN)
#error "Unsuported endiannes"
#endif
/* File types for `d_type'. */
#if !defined(DT_UNKNOWN) && !defined(DT_FIFO) && !defined(DT_CHR) && !defined(DT_DIR) && \
!defined(DT_BLK) && !defined(DT_REG) && !defined(DT_LNK) && !defined(DT_SOCK) && \
!defined(DT_WHT)
enum {
DT_UNKNOWN = 0,
DT_FIFO = 1,
......@@ -54,7 +56,7 @@ enum {
DT_REG = 8,
DT_LNK = 10,
DT_SOCK = 12,
DT_WHT = 14
DT_WHT = 14,
};
#define DT_UNKNOWN DT_UNKNOWN
#define DT_FIFO DT_FIFO
......@@ -65,10 +67,12 @@ enum {
#define DT_LNK DT_LNK
#define DT_SOCK DT_SOCK
#define DT_WHT DT_WHT
#endif
typedef void (*function_ptr)(void);
/* Attributes */
#define noreturn __attribute__((noreturn))
#define UNUSED __attribute__((unused))
#define UNUSED_FUNCTION UNUSED
#define CONSTRUCTOR_FUNCTION __attribute__((constructor)) static void
......@@ -93,7 +97,7 @@ typedef void (*function_ptr)(void);
#define LKT_POP _Pragma("GCC diagnostic pop")
#elif defined(_MSC_VER)
#error "MS compiler not supported"
// #error "MS compiler not supported"
#else
#warn "Unknown compiler"
......@@ -145,4 +149,3 @@ uint64_t be_uint64_t(const uint8_t bytes[], size_t n);
#if defined(__cplusplus)
}
#endif
#endif /* LKT_OS_H__ */
Ce diff est replié.
//
// endian.h
//
// https://gist.github.com/panzi/6856583
//
// I, Mathias Panzenböck, place this file hereby into the public domain. Use
// it at your own risk for whatever you like. In case there are
// jurisdictions that don't support putting things in the public domain you
// can also consider it to be "dual licensed" under the BSD, MIT and Apache
// licenses, if you want to. This code is trivial anyway. Consider it an
// example on how to get the endian conversion functions on different
// platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
# define __WINDOWS__
#endif
#if defined(__linux__) || defined(__CYGWIN__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
# define htobe16(x) OSSwapHostToBigInt16(x)
# define htole16(x) OSSwapHostToLittleInt16(x)
# define be16toh(x) OSSwapBigToHostInt16(x)
# define le16toh(x) OSSwapLittleToHostInt16(x)
# define htobe32(x) OSSwapHostToBigInt32(x)
# define htole32(x) OSSwapHostToLittleInt32(x)
# define be32toh(x) OSSwapBigToHostInt32(x)
# define le32toh(x) OSSwapLittleToHostInt32(x)
# define htobe64(x) OSSwapHostToBigInt64(x)
# define htole64(x) OSSwapHostToLittleInt64(x)
# define be64toh(x) OSSwapBigToHostInt64(x)
# define le64toh(x) OSSwapLittleToHostInt64(x)
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#elif defined(__OpenBSD__)
# include <sys/endian.h>
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
# define be16toh(x) betoh16(x)
# define le16toh(x) letoh16(x)
# define be32toh(x) betoh32(x)
# define le32toh(x) letoh32(x)
# define be64toh(x) betoh64(x)
# define le64toh(x) letoh64(x)
#elif defined(__WINDOWS__)
# include <winsock2.h>
# include <sys/param.h>
# if BYTE_ORDER == LITTLE_ENDIAN
# define htobe16(x) htons(x)
# define htole16(x) (x)
# define be16toh(x) ntohs(x)
# define le16toh(x) (x)
# define htobe32(x) htonl(x)
# define htole32(x) (x)
# define be32toh(x) ntohl(x)
# define le32toh(x) (x)
# define htobe64(x) htonll(x)
# define htole64(x) (x)
# define be64toh(x) ntohll(x)
# define le64toh(x) (x)
# elif BYTE_ORDER == BIG_ENDIAN
/* that would be xbox 360 */
# define htobe16(x) (x)
# define htole16(x) __builtin_bswap16(x)
# define be16toh(x) (x)
# define le16toh(x) __builtin_bswap16(x)
# define htobe32(x) (x)
# define htole32(x) __builtin_bswap32(x)
# define be32toh(x) (x)
# define le32toh(x) __builtin_bswap32(x)
# define htobe64(x) (x)
# define htole64(x) __builtin_bswap64(x)
# define be64toh(x) (x)
# define le64toh(x) __builtin_bswap64(x)
# else
# error byte order not supported
# endif
# define __BYTE_ORDER BYTE_ORDER
# define __BIG_ENDIAN BIG_ENDIAN
# define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
#else
# error platform not supported
#endif
#endif
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter