Add platform abstraction & cross-platform ports

Introduce a cross-platform platform layer and port scaffolding for macOS and Linux. CMakeLists.txt refactored to select platform sources, set executable type per OS, and use CEF helper macros for runtime deployment. Add platform/types.h, startup/paths/browser_host APIs and implementations for Windows, macOS, and Linux (many are stubs for mac/linux). Refactor app entry and lifetime to use nebula::platform::AppStartup (app/main, run.{h,cpp}), move window/browser host logic into platform/browser_host.*, and update NebulaController to use platform APIs (native handles, sizing, visibility, cache-busting token, etc.). Add README and detailed docs/cross-platform.md describing build layout and porting status.
This commit is contained in:
Andrew Zambazos
2026-05-18 17:25:04 +12:00
parent 18bc607d93
commit e51594a010
28 changed files with 1461 additions and 508 deletions
+80 -44
View File
@@ -16,16 +16,11 @@ if(NOT EXISTS "${CEF_ROOT}/cmake/FindCEF.cmake")
"CEF was not found.\n"
"Expected CEF here:\n"
" ${CEF_ROOT}\n\n"
"Make sure the contents of the CEF binary distribution are inside thirdparty/cef."
"Unpack the CEF binary distribution for your OS into thirdparty/cef."
)
endif()
# ------------------------------------------------------------
# CEF setup
# ------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CEF_ROOT}/cmake")
find_package(CEF REQUIRED)
add_subdirectory(
@@ -33,11 +28,13 @@ add_subdirectory(
"${CMAKE_BINARY_DIR}/libcef_dll_wrapper"
)
SET_CEF_TARGET_OUT_DIR()
# ------------------------------------------------------------
# Nebula source files
# Sources
# ------------------------------------------------------------
set(NEBULA_SOURCES
set(NEBULA_COMMON_SOURCES
app/main.cpp
src/app/nebula_controller.cpp
src/app/run.cpp
@@ -48,20 +45,47 @@ set(NEBULA_SOURCES
src/cef/browser_client.cpp
src/cef/nebula_app.cpp
src/ui/paths.cpp
src/window/nebula_window.cpp
)
add_executable(NebulaBrowser WIN32
${NEBULA_SOURCES}
)
if(OS_WINDOWS)
set(NEBULA_PLATFORM_SOURCES
src/platform/win/paths_win.cpp
src/platform/win/startup_win.cpp
src/platform/win/browser_host_win.cpp
src/platform/win/nebula_window_win.cpp
)
add_executable(NebulaBrowser WIN32
${NEBULA_COMMON_SOURCES}
${NEBULA_PLATFORM_SOURCES}
)
elseif(OS_MACOSX)
set(NEBULA_PLATFORM_SOURCES
src/platform/mac/paths_mac.cpp
src/platform/mac/startup_mac.cpp
src/platform/mac/browser_host_mac.cpp
src/platform/mac/nebula_window_mac.cpp
)
add_executable(NebulaBrowser MACOSX_BUNDLE
${NEBULA_COMMON_SOURCES}
${NEBULA_PLATFORM_SOURCES}
)
elseif(OS_LINUX)
set(NEBULA_PLATFORM_SOURCES
src/platform/linux/paths_linux.cpp
src/platform/linux/startup_linux.cpp
src/platform/linux/browser_host_linux.cpp
src/platform/linux/nebula_window_linux.cpp
)
add_executable(NebulaBrowser
${NEBULA_COMMON_SOURCES}
${NEBULA_PLATFORM_SOURCES}
)
else()
message(FATAL_ERROR "Unsupported platform.")
endif()
SET_EXECUTABLE_TARGET_PROPERTIES(NebulaBrowser)
if(MSVC)
set_property(TARGET NebulaBrowser PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
endif()
add_dependencies(NebulaBrowser libcef_dll_wrapper)
target_include_directories(NebulaBrowser PRIVATE
"${CMAKE_SOURCE_DIR}/src"
@@ -69,42 +93,54 @@ target_include_directories(NebulaBrowser PRIVATE
"${CEF_ROOT}/include"
)
ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_RELEASE}" "${CEF_LIB_DEBUG}")
target_link_libraries(NebulaBrowser PRIVATE
libcef_lib
libcef_dll_wrapper
${CEF_STANDARD_LIBS}
)
# ------------------------------------------------------------
# Platform-specific CEF linking
# ------------------------------------------------------------
if(WIN32)
target_link_libraries(NebulaBrowser PRIVATE
"${CEF_ROOT}/Release/libcef.lib"
dwmapi
)
target_compile_definitions(NebulaBrowser PRIVATE
NOMINMAX
WIN32_LEAN_AND_MEAN
if(MSVC)
set_property(TARGET NebulaBrowser PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)
endif()
# ------------------------------------------------------------
# Copy CEF runtime files after build
# Platform-specific CEF runtime deployment
# ------------------------------------------------------------
if(WIN32)
add_custom_command(TARGET NebulaBrowser POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/Release"
"$<TARGET_FILE_DIR:NebulaBrowser>"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CEF_ROOT}/Resources"
"$<TARGET_FILE_DIR:NebulaBrowser>"
COMMENT "Copying CEF runtime files..."
if(OS_WINDOWS)
target_link_libraries(NebulaBrowser PRIVATE dwmapi)
target_compile_definitions(NebulaBrowser PRIVATE
NOMINMAX
WIN32_LEAN_AND_MEAN
)
COPY_FILES("NebulaBrowser" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR_RELEASE}" "${CEF_TARGET_OUT_DIR}")
COPY_FILES("NebulaBrowser" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")
elseif(OS_LINUX)
FIND_LINUX_LIBRARIES("X11")
COPY_FILES("NebulaBrowser" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR_RELEASE}" "${CEF_TARGET_OUT_DIR}")
COPY_FILES("NebulaBrowser" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}")
elseif(OS_MACOSX)
set(NEBULA_APP "${CEF_TARGET_OUT_DIR}/NebulaBrowser.app")
COPY_MAC_FRAMEWORK(
"NebulaBrowser"
"Chromium Embedded Framework"
"${CEF_BINARY_DIR_RELEASE}"
"${NEBULA_APP}/Contents/Frameworks"
)
COPY_FILES(
"NebulaBrowser"
"${CEF_BINARY_FILES}"
"${CEF_BINARY_DIR_RELEASE}"
"${NEBULA_APP}/Contents/Frameworks"
)
COPY_FILES(
"NebulaBrowser"
"${CEF_RESOURCE_FILES}"
"${CEF_RESOURCE_DIR}"
"${NEBULA_APP}/Contents/Resources"
)
endif()
@@ -122,4 +158,4 @@ add_custom_command(TARGET NebulaBrowser POST_BUILD
"$<TARGET_FILE_DIR:NebulaBrowser>/ui/assets"
COMMENT "Copying Nebula UI files and assets..."
)
)