Skip to content

#1420 : add platform definition macros #1422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions dev/functional/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,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 {}
Expand Down
36 changes: 36 additions & 0 deletions dev/functional/platform_definitions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#if defined(_WIN32)
#define SQLITE_ORM_WIN

#elif defined(__APPLE__)
#include <TargetConditionals.h>
#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
1 change: 1 addition & 0 deletions dev/vfs_name.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "serialize_result_type.h"
#include "functional/platform_definitions.h"

SQLITE_ORM_EXPORT namespace sqlite_orm {

Expand Down
46 changes: 37 additions & 9 deletions include/sqlite_orm/sqlite_orm.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,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 {}
Expand Down Expand Up @@ -13864,6 +13855,43 @@ namespace sqlite_orm {

// #include "serialize_result_type.h"

// #include "functional/platform_definitions.h"

#if defined(_WIN32)
#define SQLITE_ORM_WIN

#elif defined(__APPLE__)
#include <TargetConditionals.h>
#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

SQLITE_ORM_EXPORT namespace sqlite_orm {

#ifdef SQLITE_ORM_UNIX
Expand Down
54 changes: 54 additions & 0 deletions tests/static_tests/platform_definition_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <sqlite_orm/sqlite_orm.h>

/******************************************************************************/
/*************************** 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 <TargetConditionals.h>

#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