Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Move platform detection to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
numberZero committed Feb 22, 2023
1 parent 38f18ee commit 06db7b7
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 309 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/build.yml
Expand Up @@ -48,9 +48,7 @@ jobs:

- name: Build
run: |
sed '/#define _IRR_COMPILE_WITH_OGLES2_/ s|^//||g' -i include/IrrCompileConfig.h
sed '/#define _IRR_COMPILE_WITH_OPENGL_/ s|^|//|g' -i include/IrrCompileConfig.h
cmake . -DBUILD_EXAMPLES=1
cmake . -DBUILD_EXAMPLES=1 -DENABLE_OPENGL=OFF -DENABLE_GLES2=ON
make -j2

- name: Test (headless)
Expand All @@ -61,7 +59,7 @@ jobs:
- name: Test (Xvfb)
run: |
cd bin/Linux
LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest
LIBGL_ALWAYS_SOFTWARE=true xvfb-run ./AutomatedTest ogles2

linux-sdl:
runs-on: ubuntu-latest
Expand All @@ -77,8 +75,7 @@ jobs:

- name: Build
run: |
sed '/#define _IRR_COMPILE_WITH_SDL_DEVICE_/ s|^//||g' -i include/IrrCompileConfig.h
cmake . -DBUILD_EXAMPLES=1
cmake . -DBUILD_EXAMPLES=1 -DUSE_SDL2=ON
make -j2

- name: Test (headless)
Expand Down
12 changes: 7 additions & 5 deletions examples/AutomatedTest/main.cpp
Expand Up @@ -10,15 +10,17 @@ static int test_fail = 0;
void test_irr_array();
void test_irr_string();

static video::E_DRIVER_TYPE chooseDriver(const char *arg_)
static video::E_DRIVER_TYPE chooseDriver(core::stringc arg_)
{
if (core::stringc(arg_) == "null")
if (arg_ == "null")
return video::EDT_NULL;

if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES1))
if (arg_ == "ogles1")
return video::EDT_OGLES1;
if (IrrlichtDevice::isDriverSupported(video::EDT_OGLES2))
if (arg_ == "ogles2")
return video::EDT_OGLES2;
if (arg_ == "opengl")
return video::EDT_OPENGL;
std::cerr << "Unknown driver type: " << arg_.c_str() << ". Trying OpenGL." << std::endl;
return video::EDT_OPENGL;
}

Expand Down
2 changes: 1 addition & 1 deletion include/EDeviceTypes.h
Expand Up @@ -31,7 +31,7 @@ namespace irr

//! A device which uses Simple DirectMedia Layer
/** The SDL device works under all platforms supported by SDL but first must be compiled
in by defining the _IRR_COMPILE_WITH_SDL_DEVICE_ macro in IrrCompileConfig.h */
in by setting the USE_SDL2 CMake option to ON */
EIDT_SDL,

//! This selection allows Irrlicht to choose the best device from the ones available.
Expand Down
8 changes: 4 additions & 4 deletions include/IEventReceiver.h
Expand Up @@ -452,10 +452,10 @@ struct SEvent
/** Unlike other events, joystick events represent the result of polling
* each connected joystick once per run() of the device. Joystick events will
* not be generated by default. If joystick support is available for the
* active device, _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ is defined, and
* @ref irr::IrrlichtDevice::activateJoysticks() has been called, an event of
* this type will be generated once per joystick per @ref IrrlichtDevice::run()
* regardless of whether the state of the joystick has actually changed. */
* active device, and @ref irr::IrrlichtDevice::activateJoysticks() has been
* called, an event of this type will be generated once per joystick per
* @ref IrrlichtDevice::run() regardless of whether the state of the joystick
* has actually changed. */
struct SJoystickEvent
{
enum
Expand Down
233 changes: 0 additions & 233 deletions include/IrrCompileConfig.h
Expand Up @@ -20,243 +20,10 @@

#include <stdio.h> // TODO: Although included elsewhere this is required at least for mingw

//! The defines for different operating system are:
//! _IRR_WINDOWS_ for all irrlicht supported Windows versions
//! _IRR_WINDOWS_API_ for Windows or XBox
//! _IRR_LINUX_PLATFORM_ for Linux (it is defined here if no other os is defined)
//! _IRR_SOLARIS_PLATFORM_ for Solaris
//! _IRR_OSX_PLATFORM_ for Apple systems running OSX
//! _IRR_IOS_PLATFORM_ for Apple devices running iOS
//! _IRR_ANDROID_PLATFORM_ for devices running Android
//! _IRR_POSIX_API_ for Posix compatible systems
//! Note: PLATFORM defines the OS specific layer, API can group several platforms

//! DEVICE is the windowing system used, several PLATFORMs support more than one DEVICE
//! Irrlicht can be compiled with more than one device
//! _IRR_COMPILE_WITH_WINDOWS_DEVICE_ for Windows API based device
//! _IRR_COMPILE_WITH_OSX_DEVICE_ for Cocoa native windowing on OSX
//! _IRR_COMPILE_WITH_X11_DEVICE_ for Linux X11 based device
//! _IRR_COMPILE_WITH_SDL_DEVICE_ for platform independent SDL framework

//! Passing defines to the compiler which have NO in front of the _IRR definename is an alternative
//! way which can be used to disable defines (instead of outcommenting them in this header).
//! So defines can be controlled from Makefiles or Projectfiles which allows building
//! different library versions without having to change the sources.
//! Example: NO_IRR_COMPILE_WITH_X11_ would disable X11

//! Uncomment this line to compile with the SDL device
//#define _IRR_COMPILE_WITH_SDL_DEVICE_
#ifdef NO_IRR_COMPILE_WITH_SDL_DEVICE_
#undef _IRR_COMPILE_WITH_SDL_DEVICE_
#endif

//! WIN32 for Windows32
//! WIN64 for Windows64
// The windows platform and API support SDL and WINDOW device
#if defined(_WIN32) || defined(_WIN64)
#define _IRR_WINDOWS_
#define _IRR_WINDOWS_API_
#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_
#define _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#endif
#endif

#if defined(__APPLE__)
#if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
#define _IRR_IOS_PLATFORM_
#define _IRR_COMPILE_WITH_IOS_DEVICE_
#define NO_IRR_COMPILE_WITH_OPENGL_
// The application state events and following methods: IrrlichtDevice::isWindowActive, IrrlichtDevice::isWindowFocused,
// IrrlichtDevice::isWindowMinimized works out of box only if you'll use built-in CIrrDelegateiOS,
// so _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ must be enabled in this case. If you need a custom UIApplicationDelegate
// you must disable _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ definition and handle all application events yourself.
#define _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_
#else
#define _IRR_OSX_PLATFORM_
#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_
#define _IRR_COMPILE_WITH_OSX_DEVICE_
#endif
#define NO_IRR_COMPILE_WITH_OGLES1_
#define NO_IRR_COMPILE_WITH_OGLES2_
#define NO_IRR_COMPILE_WITH_WEBGL1_
#endif
#endif

#if defined(__EMSCRIPTEN__)
#define _IRR_EMSCRIPTEN_PLATFORM_
#define NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#define NO_IRR_COMPILE_WITH_OPENGL_
#define NO_IRR_COMPILE_WITH_OGLES1_
#define _IRR_COMPILE_WITH_OGLES2_
#define _IRR_COMPILE_WITH_WEBGL1_
#define _IRR_COMPILE_WITH_EGL_MANAGER_
#define _IRR_COMPILE_WITH_SDL_DEVICE_
#define NO_IRR_COMPILE_WITH_X11_DEVICE_
#define _IRR_LINUX_PLATFORM_ // emscripten basically working like a unix
#endif // __EMSCRIPTEN__

#if defined(__ANDROID__)
#define _IRR_ANDROID_PLATFORM_
#define _IRR_COMPILE_WITH_ANDROID_DEVICE_
#define _IRR_COMPILE_ANDROID_ASSET_READER_
#define NO_IRR_COMPILE_WITH_OPENGL_
#endif

#if defined(__SVR4) && defined(__sun)
#define _IRR_SOLARIS_PLATFORM_
#if defined(__sparc)
#define __BIG_ENDIAN__
#endif
#endif

#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_IOS_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_) && !defined(_IRR_EMSCRIPTEN_PLATFORM_)
#ifndef _IRR_SOLARIS_PLATFORM_
#define _IRR_LINUX_PLATFORM_
#endif
#define _IRR_POSIX_API_
#ifndef _IRR_COMPILE_WITH_SDL_DEVICE_
#define _IRR_COMPILE_WITH_X11_DEVICE_
#endif
#endif


//! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events.
#if !(defined(__FreeBSD__) || defined(__OpenBSD__))
#define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#endif
#ifdef NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#endif


//! Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht.
#define _IRR_MATERIAL_MAX_TEXTURES_ 4

//! Define _IRR_COMPILE_WITH_OPENGL_ to compile the Irrlicht engine with OpenGL.
/** If you do not wish the engine to be compiled with OpenGL, comment this
define out. */
#define _IRR_COMPILE_WITH_OPENGL_
#ifdef NO_IRR_COMPILE_WITH_OPENGL_
#undef _IRR_COMPILE_WITH_OPENGL_
#endif

//! Define required options for OpenGL drivers.
#if defined(_IRR_COMPILE_WITH_OPENGL_)
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
#define _IRR_OPENGL_USE_EXTPOINTER_
#define _IRR_COMPILE_WITH_WGL_MANAGER_
#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_)
#define _IRR_OPENGL_USE_EXTPOINTER_
#define _IRR_COMPILE_WITH_GLX_MANAGER_
#elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_)
#define _IRR_COMPILE_WITH_NSOGL_MANAGER_
#elif defined(_IRR_SOLARIS_PLATFORM_)
#define _IRR_COMPILE_WITH_GLX_MANAGER_
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
#define _IRR_OPENGL_USE_EXTPOINTER_
#endif
#endif

//! Define _IRR_COMPILE_WITH_OGLES1_ to compile the Irrlicht engine with OpenGL ES 1.1.
/** If you do not wish the engine to be compiled with OpenGL ES 1.1, comment this
define out.
Depending on platform you may have to enable _IRR_OGLES1_USE_KHRONOS_API_HEADERS_ as well when using it.
*/
#if defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_IOS_PLATFORM_)
#define _IRR_COMPILE_WITH_OGLES1_
#endif
#ifdef NO_IRR_COMPILE_WITH_OGLES1_
#undef _IRR_COMPILE_WITH_OGLES1_
#endif

#ifdef _IRR_COMPILE_WITH_OGLES1_
//! Define _IRR_OGLES1_USE_KHRONOS_API_HEADERS_ to use the OpenGL ES headers from the Debian Khronos-api package
//#define _IRR_OGLES1_USE_KHRONOS_API_HEADERS_
#endif

//! Define required options for OpenGL ES 1.1 drivers.
#if defined(_IRR_COMPILE_WITH_OGLES1_)
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
#define _IRR_OGLES1_USE_EXTPOINTER_
#ifndef _IRR_COMPILE_WITH_EGL_MANAGER_
#define _IRR_COMPILE_WITH_EGL_MANAGER_
#endif
#elif defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
#ifndef _IRR_COMPILE_WITH_EAGL_MANAGER_
#define _IRR_COMPILE_WITH_EAGL_MANAGER_
#endif
#endif
#endif

//! Define _IRR_COMPILE_WITH_OGLES2_ to compile the Irrlicht engine with OpenGL ES 2.0.
/** If you do not wish the engine to be compiled with OpenGL ES 2.0, comment this
define out. */
#if defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_IOS_PLATFORM_)
#define _IRR_COMPILE_WITH_OGLES2_
#else
//#define _IRR_COMPILE_WITH_OGLES2_
#endif
#ifdef NO_IRR_COMPILE_WITH_OGLES2_
#undef _IRR_COMPILE_WITH_OGLES2_
#endif

//! Define _IRR_COMPILE_WITH_WEBGL1_ to compile Irrlicht engine with a WebGL friendly
//! subset of the OpenGL ES 2.0 driver.
//#define _IRR_COMPILE_WITH_WEBGL1_
#ifdef NO_IRR_COMPILE_WITH_WEBGL1_
#undef _IRR_COMPILE_WITH_WEBGL1_
#endif
#ifdef _IRR_COMPILE_WITH_WEBGL1_
#define _IRR_COMPILE_WITH_OGLES2_ // it's a subset of OGL ES2, so always needed when using WebGL
#endif

//! Define required options for OpenGL ES 2.0 drivers.
#if defined(_IRR_COMPILE_WITH_OGLES2_)
#if defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(__EMSCRIPTEN__)
#define _IRR_OGLES2_USE_EXTPOINTER_
#ifndef _IRR_COMPILE_WITH_EGL_MANAGER_
#define _IRR_COMPILE_WITH_EGL_MANAGER_
#endif
#elif defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
#ifndef _IRR_COMPILE_WITH_EAGL_MANAGER_
#define _IRR_COMPILE_WITH_EAGL_MANAGER_
#endif
#endif
#endif



//! Define _IRR_COMPILE_WITH_X11_ to compile the Irrlicht engine with X11 support.
/** If you do not wish the engine to be compiled with X11, comment this
define out. */
// Only used in LinuxDevice.
#define _IRR_COMPILE_WITH_X11_
#ifdef NO_IRR_COMPILE_WITH_X11_
#undef _IRR_COMPILE_WITH_X11_
#endif

#if defined(_IRR_LINUX_PLATFORM_) && defined(_IRR_COMPILE_WITH_X11_)
//! XInput2 (library called Xi) is currently only used to support touch-input.
#define _IRR_LINUX_X11_XINPUT2_
#ifdef NO_IRR_LINUX_X11_XINPUT2_
#undef _IRR_LINUX_X11_XINPUT2_
#endif

//! X11 has by default only monochrome cursors, but using the Xcursor library we can also get color cursor support.
//! If you have the need for custom color cursors on X11 then enable this and make sure you also link
//! to the Xcursor library in your Makefile/Projectfile.
//#define _IRR_LINUX_XCURSOR_
#ifdef NO_IRR_LINUX_XCURSOR_
#undef _IRR_LINUX_XCURSOR_
#endif

#endif


#if defined(_IRR_SOLARIS_PLATFORM_)
#undef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
#endif


#ifdef _IRR_WINDOWS_API_

Expand Down
36 changes: 3 additions & 33 deletions include/IrrlichtDevice.h
Expand Up @@ -235,8 +235,8 @@ namespace irr
as this would consume joystick info that 3rd party libraries might rely on. Call this method to
activate joystick support in Irrlicht and to receive irr::SJoystickEvent events.
\param joystickInfo On return, this will contain an array of each joystick that was found and activated.
\return true if joysticks are supported on this device and _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
is defined, false if joysticks are not supported or support is compiled out.
\return true if joysticks are supported on this device, false if joysticks are not
supported or support is compiled out.
*/
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0;

Expand Down Expand Up @@ -310,37 +310,7 @@ namespace irr
for a configuration requested when creating the device. */
static bool isDriverSupported(video::E_DRIVER_TYPE driver)
{
switch (driver)
{
case video::EDT_NULL:
return true;
case video::EDT_OPENGL:
#ifdef _IRR_COMPILE_WITH_OPENGL_
return true;
#else
return false;
#endif
case video::EDT_OGLES1:
#ifdef _IRR_COMPILE_WITH_OGLES1_
return true;
#else
return false;
#endif
case video::EDT_OGLES2:
#ifdef _IRR_COMPILE_WITH_OGLES2_
return true;
#else
return false;
#endif
case video::EDT_WEBGL1:
#ifdef _IRR_COMPILE_WITH_WEBGL1_
return true;
#else
return false;
#endif
default:
return false;
}
return true;
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/SIrrCreationParameters.h
Expand Up @@ -53,7 +53,7 @@ namespace irr
UsePerformanceTimer(true),
SDK_version_do_not_use(IRRLICHT_SDK_VERSION),
PrivateData(0),
#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) || defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_EMSCRIPTEN_PLATFORM_)
#ifdef IRR_MOBILE_PATHS
OGLES2ShaderPath("media/Shaders/")
#else
OGLES2ShaderPath("../../media/Shaders/")
Expand Down
2 changes: 1 addition & 1 deletion include/exampleHelper.h
Expand Up @@ -13,7 +13,7 @@ namespace irr

static io::path getExampleMediaPath()
{
#if defined (_IRR_IOS_PLATFORM_) || defined (_IRR_ANDROID_PLATFORM_) || defined (_IRR_OSX_PLATFORM_) || defined (_IRR_EMSCRIPTEN_PLATFORM_)
#ifdef IRR_MOBILE_PATHS
return io::path("media/");
#else
return io::path("../../media/");
Expand Down

0 comments on commit 06db7b7

Please sign in to comment.