diff --git a/dev/functional/config.h b/dev/functional/config.h index 3c75a91f..0ef4ab0e 100644 --- a/dev/functional/config.h +++ b/dev/functional/config.h @@ -1,6 +1,7 @@ #pragma once #include "cxx_universal.h" +#include "platform_definitions.h" #ifdef BUILD_SQLITE_ORM_MODULE #define SQLITE_ORM_EXPORT export @@ -72,15 +73,6 @@ #define SQLITE_ORM_WITH_CTE -#if defined(_WIN32) -#define SQLITE_ORM_WIN -#elif defined(__APPLE__) -#define SQLITE_ORM_APPLE -#define SQLITE_ORM_UNIX -#elif defined(__unix__) || defined(__unix) || defined(__linux__) || defined(__FreeBSD__) -#define SQLITE_ORM_UNIX -#endif - // define the inline namespace "literals" so that it is available even if it was not introduced by a feature namespace sqlite_orm { inline namespace literals {} diff --git a/dev/functional/platform_definitions.h b/dev/functional/platform_definitions.h new file mode 100644 index 00000000..11b8a29b --- /dev/null +++ b/dev/functional/platform_definitions.h @@ -0,0 +1,36 @@ +#pragma once + +#if defined(_WIN32) +#define SQLITE_ORM_WIN + +#elif defined(__APPLE__) +#include +#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1 +#define SQLITE_ORM_IOS +#elif TARGET_OS_OSX == 1 +#define SQLITE_ORM_MACOS +#endif +#define SQLITE_ORM_APPLE +#define SQLITE_ORM_UNIX + +#elif defined(__linux__) +#if defined(__ANDROID__) +#define SQLITE_ORM_ANDROID +#endif +#define SQLITE_ORM_LINUX +#define SQLITE_ORM_UNIX + +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +#define SQLITE_ORM_BSD +#define SQLITE_ORM_UNIX + +#elif defined(__RTP__) || defined(_WRS_KERNEL) +#define SQLITE_ORM_VXWORKS +#define SQLITE_ORM_UNIX + +#elif defined(__unix__) || defined(__unix) +#define SQLITE_ORM_UNIX + +#else +#error "Unknown target platform detected" +#endif diff --git a/include/sqlite_orm/sqlite_orm.h b/include/sqlite_orm/sqlite_orm.h index 129ec513..f91d27c9 100644 --- a/include/sqlite_orm/sqlite_orm.h +++ b/include/sqlite_orm/sqlite_orm.h @@ -192,6 +192,43 @@ using std::nullptr_t; #define SQLITE_ORM_BROKEN_NONTEMPLATE_CONCEPTS #endif +// #include "platform_definitions.h" + +#if defined(_WIN32) +#define SQLITE_ORM_WIN + +#elif defined(__APPLE__) +#include +#if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1 +#define SQLITE_ORM_IOS +#elif TARGET_OS_OSX == 1 +#define SQLITE_ORM_MACOS +#endif +#define SQLITE_ORM_APPLE +#define SQLITE_ORM_UNIX + +#elif defined(__linux__) +#if defined(__ANDROID__) +#define SQLITE_ORM_ANDROID +#endif +#define SQLITE_ORM_LINUX +#define SQLITE_ORM_UNIX + +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +#define SQLITE_ORM_BSD +#define SQLITE_ORM_UNIX + +#elif defined(__RTP__) || defined(_WRS_KERNEL) +#define SQLITE_ORM_VXWORKS +#define SQLITE_ORM_UNIX + +#elif defined(__unix__) || defined(__unix) +#define SQLITE_ORM_UNIX + +#else +#error "Unknown target platform detected" +#endif + #ifdef BUILD_SQLITE_ORM_MODULE #define SQLITE_ORM_EXPORT export #else @@ -262,15 +299,6 @@ using std::nullptr_t; #define SQLITE_ORM_WITH_CTE -#if defined(_WIN32) -#define SQLITE_ORM_WIN -#elif defined(__APPLE__) -#define SQLITE_ORM_APPLE -#define SQLITE_ORM_UNIX -#elif defined(__unix__) || defined(__unix) || defined(__linux__) || defined(__FreeBSD__) -#define SQLITE_ORM_UNIX -#endif - // define the inline namespace "literals" so that it is available even if it was not introduced by a feature namespace sqlite_orm { inline namespace literals {} diff --git a/tests/static_tests/platform_definition_tests.cpp b/tests/static_tests/platform_definition_tests.cpp new file mode 100644 index 00000000..1abde667 --- /dev/null +++ b/tests/static_tests/platform_definition_tests.cpp @@ -0,0 +1,54 @@ +#include + +/******************************************************************************/ +/*************************** Windows Tests ****************************/ +/******************************************************************************/ +#if defined(_WIN32) && !defined(SQLITE_ORM_WIN) +#error "Windows platform detection failed" +#endif + +/******************************************************************************/ +/*************************** macOS/iOS Tests ****************************/ +/******************************************************************************/ +#ifdef __APPLE__ + +#ifndef SQLITE_ORM_APPLE +#error "Apple platform detection failed" +#endif + +#include + +#if TARGET_OS_IPHONE == 1 && !defined(SQLITE_ORM_IOS) +#error "iOS platform detection failed" +#elif TARGET_OS_OSX == 1 && !defined(SQLITE_ORM_MACOS) +#error "macOS platform detection failed" +#endif + +/******************************************************************************/ +/*************************** Linux/BSD Tests ***************************/ +/******************************************************************************/ +#if defined(__linux__) && (!defined(SQLITE_ORM_LINUX) || !defined(SQLITE_ORM_UNIX)) +#error "Unix platform detection failed" +#endif + +#if defined(__ANDROID__) && !defined(SQLITE_ORM_ANDROID) +#error "Unix platform detection failed" +#endif + +#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)) && \ + (!defined(SQLITE_ORM_BSD) || !defined(SQLITE_ORM_UNIX)) +#error "BSD platform detection failed" +#endif + +/******************************************************************************/ +/*************************** Other Unix Tests ***************************/ +/******************************************************************************/ +#if (defined(__RTP__) || defined(_WRS_KERNEL)) && (!defined(SQLITE_ORM_VXWORKS) || !defined(SQLITE_ORM_UNIX)) +#error "VxWorks platform detection failed" +#endif + +#if defined(__unix__) && !defined(SQLITE_ORM_UNIX) +#error "Unix platform detection failed" +#endif + +#endif