diff --git a/CMakeLists.txt b/CMakeLists.txt index 306aaffd..68cea588 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -296,7 +296,6 @@ set(LOVR_SRC src/core/fs.c src/core/maf.c src/core/map.c - src/core/platform.c src/core/ref.c src/core/utf.c src/core/util.c @@ -513,6 +512,7 @@ endif() # Platforms if(WIN32) + target_sources(lovr PRIVATE src/core/os_win32.c) set_target_properties(lovr PROPERTIES COMPILE_FLAGS "/wd4244 /MP") set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:mainCRTStartup") @@ -541,6 +541,7 @@ if(WIN32) move_dll(${LOVR_LEAP}) target_compile_definitions(lovr PRIVATE -DLOVR_GL) elseif(APPLE) + target_sources(lovr PRIVATE src/core/os_macos.c) target_compile_definitions(lovr PRIVATE -DLOVR_GL) if(LOVR_BUILD_BUNDLE) function(move_lib) @@ -570,10 +571,13 @@ elseif(APPLE) ) endif() elseif(EMSCRIPTEN) + target_sources(lovr PRIVATE src/core/os_web.c) target_compile_definitions(lovr PRIVATE -DLOVR_WEBGL) elseif(ANDROID) + target_sources(lovr PRIVATE src/core/os_android.c) target_link_libraries(lovr log EGL GLESv3) target_compile_definitions(lovr PRIVATE -DLOVR_GLES) elseif(UNIX) + target_sources(lovr PRIVATE src/core/os_linux.c) target_compile_definitions(lovr PRIVATE -DLOVR_GL) endif() diff --git a/Tupfile b/Tupfile index d8285b34..772a8ed9 100644 --- a/Tupfile +++ b/Tupfile @@ -5,7 +5,7 @@ SRC += src/core/arr.c SRC += src/core/fs.c SRC += src/core/maf.c SRC += src/core/map.c -SRC += src/core/platform.c +SRC += src/core/os_$(PLATFORM).c SRC += src/core/ref.c SRC += src/core/utf.c SRC += src/core/util.c diff --git a/Tuprules.tup b/Tuprules.tup index 088edebb..b09ef593 100644 --- a/Tuprules.tup +++ b/Tuprules.tup @@ -41,14 +41,25 @@ CFLAGS_@(WEBVR) += LOVR_USE_WEBVR CFLAGS_@(LEAP) += LOVR_USE_LEAP ## Platforms -# $(LDFLAGS_@(TUP_PLATFORM)) doesn't seem to work, oh well -ifeq (@(TUP_PLATFORM),macosx) +# A little gnarly, but basically you can set CONFIG_PLATFORM to pick a specific one, otherwise +# we use the builtin TUP_PLATFORM which is the current OS (so it won't work with android/web). +# Also macosx gets converted to macos +ifeq (@(PLATFORM),) + PLATFORM = @(TUP_PLATFORM) +else + PLATFORM = @(PLATFORM) +endif +ifeq ($(PLATFORM),macosx) + PLATFORM = macos +endif + +ifeq ($(PLATFORM),macosx) LDFLAGS += -lobjc LDFLAGS += -pagezero_size 10000 -image_base 100000000 ORIGIN = @executable_path SO = dylib endif -ifeq (@(TUP_PLATFORM),linux) +ifeq ($(PLATFORM),linux) LDFLAGS += -lm -lpthread ORIGIN = \$ORIGIN SO = so diff --git a/src/api/api.c b/src/api/api.c index 55e483ca..8b41beaa 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -1,6 +1,6 @@ #include "api.h" +#include "core/os.h" #include "core/ref.h" -#include "core/platform.h" #include "core/util.h" #include #include diff --git a/src/api/l_event.c b/src/api/l_event.c index c4de5314..c601d3c5 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -1,7 +1,7 @@ #include "api.h" #include "event/event.h" #include "thread/thread.h" -#include "core/platform.h" +#include "core/os.h" #include "core/ref.h" #include "core/util.h" #include diff --git a/src/api/l_filesystem.c b/src/api/l_filesystem.c index b4c625dc..e1d0845d 100644 --- a/src/api/l_filesystem.c +++ b/src/api/l_filesystem.c @@ -2,7 +2,7 @@ #include "filesystem/filesystem.h" #include "data/blob.h" #include "core/fs.h" -#include "core/platform.h" +#include "core/os.h" #include "core/ref.h" #include #include diff --git a/src/api/l_lovr.c b/src/api/l_lovr.c index 4fdc0fa9..eb0897a8 100644 --- a/src/api/l_lovr.c +++ b/src/api/l_lovr.c @@ -1,6 +1,6 @@ #include "api.h" +#include "core/os.h" #include "core/util.h" -#include "core/platform.h" #include "lib/lua-cjson/lua_cjson.h" #include "lib/lua-enet/enet.h" diff --git a/src/core/platform.h b/src/core/os.h similarity index 100% rename from src/core/platform.h rename to src/core/os.h diff --git a/src/core/platform_android.c.h b/src/core/os_android.c similarity index 100% rename from src/core/platform_android.c.h rename to src/core/os_android.c diff --git a/src/core/platform_glfw.c.h b/src/core/os_glfw.h similarity index 99% rename from src/core/platform_glfw.c.h rename to src/core/os_glfw.h index 80435f65..ae852a18 100644 --- a/src/core/platform_glfw.c.h +++ b/src/core/os_glfw.h @@ -1,7 +1,5 @@ #include "util.h" -// Include this in ONE translation unit - #define GLFW_INCLUDE_NONE #include #ifndef EMSCRIPTEN diff --git a/src/core/platform_linux.c.h b/src/core/os_linux.c similarity index 94% rename from src/core/platform_linux.c.h rename to src/core/os_linux.c index 1eb5d3fb..a26136e4 100644 --- a/src/core/platform_linux.c.h +++ b/src/core/os_linux.c @@ -1,8 +1,8 @@ -#include "platform.h" +#include "os.h" #include #include -#include "platform_glfw.c.h" +#include "os_glfw.h" static uint64_t epoch; #define NS_PER_SEC 1000000000ULL diff --git a/src/core/platform_macos.c.h b/src/core/os_macos.c similarity index 100% rename from src/core/platform_macos.c.h rename to src/core/os_macos.c diff --git a/src/core/platform_web.c.h b/src/core/os_web.c similarity index 100% rename from src/core/platform_web.c.h rename to src/core/os_web.c diff --git a/src/core/platform_windows.c.h b/src/core/os_win32.c similarity index 100% rename from src/core/platform_windows.c.h rename to src/core/os_win32.c diff --git a/src/core/platform.c b/src/core/platform.c deleted file mode 100644 index f27113ae..00000000 --- a/src/core/platform.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "platform.h" - -#ifdef _WIN32 -#include "platform_windows.c.h" -#elif __APPLE__ -#include "platform_macos.c.h" -#elif __ANDROID__ -#include "platform_android.c.h" -#elif __linux__ -#include "platform_linux.c.h" -#elif EMSCRIPTEN -#include "platform_web.c.h" -#endif diff --git a/src/main.c b/src/main.c index 4f2345b9..5696bbeb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ #include "resources/boot.lua.h" #include "api/api.h" -#include "core/platform.h" +#include "core/os.h" #include "core/util.h" #include #include diff --git a/src/modules/event/event.c b/src/modules/event/event.c index 08a2d452..cdd82db4 100644 --- a/src/modules/event/event.c +++ b/src/modules/event/event.c @@ -1,6 +1,6 @@ #include "event/event.h" #include "core/arr.h" -#include "core/platform.h" +#include "core/os.h" #include "core/ref.h" #include "core/util.h" #include diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 6d9ed56b..442f356b 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -1,7 +1,7 @@ #include "graphics/font.h" #include "data/modelData.h" #include "core/maf.h" -#include "core/platform.h" +#include "core/os.h" #include "core/util.h" #include #include diff --git a/src/modules/headset/desktop.c b/src/modules/headset/desktop.c index d39039e9..361da066 100644 --- a/src/modules/headset/desktop.c +++ b/src/modules/headset/desktop.c @@ -1,7 +1,7 @@ #include "headset/headset.h" #include "graphics/graphics.h" #include "core/maf.h" -#include "core/platform.h" +#include "core/os.h" #include "core/util.h" #include #include diff --git a/src/modules/headset/leap.c b/src/modules/headset/leap.c index 9c85b301..95c2b732 100644 --- a/src/modules/headset/leap.c +++ b/src/modules/headset/leap.c @@ -1,6 +1,6 @@ #include "headset/headset.h" #include "core/maf.h" -#include "core/platform.h" +#include "core/os.h" #include "core/util.h" #include "lib/tinycthread/tinycthread.h" #include diff --git a/src/modules/headset/oculus_mobile.c b/src/modules/headset/oculus_mobile.c index a9a251df..8eb0f5cd 100644 --- a/src/modules/headset/oculus_mobile.c +++ b/src/modules/headset/oculus_mobile.c @@ -2,7 +2,7 @@ #include "oculus_mobile_bridge.h" #include "graphics/graphics.h" #include "graphics/canvas.h" -#include "core/platform.h" +#include "core/os.h" #include "lib/glad/glad.h" #include #include diff --git a/src/modules/headset/openvr.c b/src/modules/headset/openvr.c index 246e91ed..8f8bb2e2 100644 --- a/src/modules/headset/openvr.c +++ b/src/modules/headset/openvr.c @@ -8,7 +8,7 @@ #include "graphics/graphics.h" #include "graphics/canvas.h" #include "core/maf.h" -#include "core/platform.h" +#include "core/os.h" #include "core/ref.h" #include #include diff --git a/src/modules/timer/timer.c b/src/modules/timer/timer.c index 7ce4d1d2..8a6b9e44 100644 --- a/src/modules/timer/timer.c +++ b/src/modules/timer/timer.c @@ -1,5 +1,5 @@ #include "timer/timer.h" -#include "core/platform.h" +#include "core/os.h" #include static struct { diff --git a/tup.config b/tup.config index 678063e2..a1f7fd72 100644 --- a/tup.config +++ b/tup.config @@ -11,6 +11,7 @@ # CMAKE_DEPS: Assume libraries were built by CMake in the `build` folder. # EXTRA_CFLAGS: Additional compiler flags (e.g. libraries, warnings). # EXTRA_LDFLAGS: Additional linker flags. +# PLATFORM: The platform to compile for (win32, macos, linux, android, web, or blank to autodetect). CONFIG_CC=clang CONFIG_STRICT=y CONFIG_DEBUG=y @@ -19,6 +20,7 @@ CONFIG_SANITIZE=n CONFIG_CMAKE_DEPS=y CONFIG_EXTRA_CFLAGS= CONFIG_EXTRA_LDFLAGS= +CONFIG_PLATFORM= ## Modules # The set of enabled Lua modules.