Merge pull request #26 from tommo/macos

OS X port effort by Tommo.
This commit is contained in:
astrofra 2022-11-04 15:29:33 +01:00 committed by GitHub
commit 1cacbb6640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 124 additions and 38 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ build
*.egg-info
dist
commit_id
*.DS_Store

View File

@ -35,7 +35,7 @@ if(HG_USE_GLFW)
set(HG_GLFW_BACKEND "WAYLAND")
elseif (WIN32)
set(HG_GLFW_BACKEND "WIN32")
elseif (HG_APPLE)
elseif (APPLE)
set(HG_GLFW_BACKEND "COCOA")
elseif (UNIX)
set(HG_GLFW_BACKEND "X11")
@ -354,7 +354,9 @@ target_include_directories(cmft PRIVATE cmft/include cmft/dependency cmft/src/cm
target_compile_definitions(cmft PRIVATE CMFT_ENABLE_INFO_MESSAGES=1)
set_target_properties(cmft PROPERTIES FOLDER "harfang/tools")
if(UNIX)
if(APPLE)
target_link_libraries(cmft pthread dl)
elseif(UNIX)
target_compile_definitions(cmft PRIVATE linux)
target_link_libraries(cmft pthread dl)
endif()

View File

@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.1)
if( APPLE AND NOT XCODE )
set( CMAKE_CXX_FLAGS "-ObjC++" )
endif()
set( BGFX_SRCS
bgfx/src/bgfx.cpp bgfx/src/renderer_gl.cpp
bgfx/src/debug_renderdoc.cpp bgfx/src/renderer_gnm.cpp
@ -15,6 +19,15 @@ set( BGFX_SRCS
bgfx/src/glcontext_html5.cpp bgfx/src/renderer_agc.cpp
)
if( APPLE )
set( BGFX_SRCS
${BGFX_SRCS}
bgfx/src/glcontext_eagl.mm
bgfx/src/glcontext_nsgl.mm
bgfx/src/renderer_mtl.mm
)
endif()
set( BGFX_HDRS
bgfx/src/bgfx_p.h bgfx/src/glimports.h
bgfx/src/charset.h bgfx/src/nvapi.h
@ -107,6 +120,26 @@ if( UNIX AND NOT APPLE AND NOT EMSCRIPTEN )
endif()
endif()
if( ${CMAKE_SYSTEM_NAME} MATCHES iOS|tvOS )
target_link_libraries (bgfx PUBLIC
"-framework OpenGLES -framework Metal -framework UIKit -framework CoreGraphics -framework QuartzCore -framework IOKit -framework CoreFoundation")
elseif( APPLE )
find_library( COCOA_LIBRARY Cocoa )
find_library( METAL_LIBRARY Metal )
find_library( QUARTZCORE_LIBRARY QuartzCore )
find_library( IOKIT_LIBRARY IOKit )
find_library( COREFOUNDATION_LIBRARY CoreFoundation )
mark_as_advanced( COCOA_LIBRARY )
mark_as_advanced( METAL_LIBRARY )
mark_as_advanced( QUARTZCORE_LIBRARY )
mark_as_advanced( IOKIT_LIBRARY )
mark_as_advanced( COREFOUNDATION_LIBRARY )
target_link_libraries( bgfx PUBLIC ${COCOA_LIBRARY} ${METAL_LIBRARY} ${QUARTZCORE_LIBRARY} ${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} )
target_link_libraries (bgfx PUBLIC
"-framework OpenGL")
endif()
if( NOT ${OPENGL_VERSION} STREQUAL "" )
target_compile_definitions( bgfx PRIVATE BGFX_CONFIG_RENDERER_OPENGL=${OPENGL_VERSION})
message(STATUS "OpenGL version: ${OPENGL_VERSION}")

View File

@ -73,6 +73,8 @@ target_compile_definitions( bx
PUBLIC
$<$<CONFIG:Debug>:BX_CONFIG_DEBUG=1>
$<$<CONFIG:Release>:BX_CONFIG_DEBUG=0>
$<$<CONFIG:RelWithDebInfo>:BX_CONFIG_DEBUG=0>
$<$<CONFIG:MinSizeRel>:BX_CONFIG_DEBUG=0>
)
if( UNIX AND NOT APPLE )

View File

@ -1,30 +1,56 @@
#[[
Try to find libuuid
Provides the following target and variables:
* uuid : library target
* UUID_FOUND : set if libuuid was found
* UUID_INCLUDE_DIR : libuuid include diretory
* UUID_LIBRARY : libuuid library file
#]]
find_path(UUID_INCLUDE_DIR
NAMES uuid/uuid.h
HINTS ${UUID_ROOT_DIR}
)
find_library(UUID_LIBRARY
NAMES uuid
HINTS ${UUID_ROOT_DIR}
)
#.rst:
# Finduuid
# -----------
#
# Find libuuid, DCE compatible Universally Unique Identifier library.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``UUID_FOUND``
# True if libuuid has been found.
# ``UUID_INCLUDE_DIRS``
# Where to find uuid/uuid.h.
# ``UUID_LIBRARIES``
# The libraries to link against to use libuuid.
#
# Obsolete variables
# ^^^^^^^^^^^^^^^^^^
#
# The following variables may also be set, for backwards compatibility:
#
# ``UUID_LIBRARY``
# where to find the libuuid library (same as UUID_LIBRARIES).
# ``UUID_INCLUDE_DIR``
# where to find the uuid/uuid.h header (same as UUID_INCLUDE_DIRS).
include(CheckCXXSymbolExists)
include(CheckLibraryExists)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(uuid REQUIRED_VARS UUID_LIBRARY UUID_INCLUDE_DIR)
mark_as_advanced(UUID_FOUND UUID_LIBRARY UUID_INCLUDE_DIR)
if(UUID_FOUND AND NOT TARGET uuid)
add_library(uuid UNKNOWN IMPORTED)
set_target_properties(uuid PROPERTIES
IMPORTED_LOCATION "${UUID_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${UUID_INCLUDE_DIR}"
)
if(NOT UUID_INCLUDE_DIR)
find_path(UUID_INCLUDE_DIR uuid/uuid.h)
endif()
if(EXISTS UUID_INCLUDE_DIR)
set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR})
set(CMAKE_REQUIRED_INCLUDES ${UUID_INCLUDE_DIRS})
check_cxx_symbol_exists("uuid_generate_random" "uuid/uuid.h" _uuid_header_only)
endif()
if(NOT _uuid_header_only AND NOT UUID_LIBRARY)
check_library_exists("uuid" "uuid_generate_random" "" _have_libuuid)
if(_have_libuuid)
set(UUID_LIBRARY "uuid")
set(UUID_LIBRARIES ${UUID_LIBRARY})
endif()
endif()
unset(CMAKE_REQUIRED_INCLUDES)
unset(_uuid_header_only)
unset(_have_libuuid)
find_package_handle_standard_args(uuid DEFAULT_MSG UUID_INCLUDE_DIR)
mark_as_advanced(UUID_INCLUDE_DIR UUID_LIBRARY)

View File

@ -167,7 +167,7 @@ if(NOT WIN32)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
find_package(uuid REQUIRED)
endif()
target_link_libraries(foundation PUBLIC uuid)
target_link_libraries(foundation PUBLIC ${UUID_LIBRARIES})
else()
target_link_libraries(foundation PUBLIC Iphlpapi)
if(MSVC)

View File

@ -40,6 +40,10 @@ if(WIN32)
elseif(APPLE)
list(APPEND SRCS
osx/platform.cpp
posix/crash_dump.cpp
posix/process.cpp
posix/shared_library.cpp
posix/thread.cpp
)
else()
list(APPEND SRCS

View File

@ -3,7 +3,8 @@
#include "osx_input_system/osx_input_system.h"
#include "osx_input_system/osx_input_keyboard.h"
#include "osx_input_system/osx_input_mouse.h"
#include "window_system/window_system.h"
// #include "window_system/window_system.h"
#include "window_system.h"
#include "cstl/log.h"
namespace gs {

View File

@ -2,9 +2,7 @@
#pragma once
#include "input_system/input_system.h"
#include "input_system/input_mouse.h"
#include "input_system/input_keyboard.h"
#include "../input_system.h"
namespace gs {
namespace input {

View File

@ -1,15 +1,23 @@
// HARFANG(R) Copyright (C) 2021 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details.
#include "platform/osx/osx_input_system.h"
#include "platform/platform.h"
#include <string>
namespace hg {
bool InitPlatform() { return true; }
bool OpenFileDialog(const std::string &title, const std::string &filter, std::string &OUTPUT, const std::string &initial_dir) { return false; }
bool SaveFileDialog(const std::string &title, const std::string &filter, std::string &OUTPUT, const std::string &initial_dir) { return false; }
bool OpenFolderDialog(const std::string &title, std::string &OUTPUT, const std::string &initial_dir) { return false; }
bool OpenFolderDialog(const std::string &title, std::string &output, const std::string &initial_dir) {
return false;
}
bool OpenFileDialog(const std::string &title, const std::vector<hg::FileFilter> &filters, std::string &output, const std::string &initial_dir) {
return false;
}
bool SaveFileDialog(const std::string &title, const std::vector<hg::FileFilter> &filters, std::string &output, const std::string &initial_dir) {
return false;
}
void DebugBreak() { /* STUB */ }

View File

@ -19,7 +19,11 @@ add_library(hg_lua SHARED
target_include_directories(hg_lua PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../extern/lua/src)
target_link_libraries(hg_lua engine foundation platform)
set_target_properties(hg_lua PROPERTIES OUTPUT_NAME "harfang" PREFIX "" DEBUG_POSTFIX "")
if(APPLE)
set_target_properties(hg_lua PROPERTIES SUFFIX ".so")
endif()
set_target_properties(hg_lua PROPERTIES FOLDER "harfang/languages")
add_dependencies(hg_lua lua)
if(WIN32)

View File

@ -22,6 +22,9 @@ if(WIN32)
set_target_properties(hg_python PROPERTIES COMPILE_FLAGS /bigobj)
else()
set_target_properties(hg_python PROPERTIES OUTPUT_NAME harfang PREFIX "")
if(APPLE)
set_target_properties(hg_python PROPERTIES SUFFIX ".so")
endif()
endif()
message(STATUS "Python libs: " ${Python3_LIBRARIES})

View File

@ -962,7 +962,7 @@ void Texture(std::map<std::string, Hash> &hashes, std::string path) {
}
//
if (api == "DX12" || api == "DX11" || api == "GL" || api == "GLES" || api == "VK") {
if (api == "DX12" || api == "DX11" || api == "GL" || api == "GLES" || api == "VK" || api == "MTL" ) {
const auto src = FullInputPath(in_path);
if (type == "Copy") {
@ -1164,6 +1164,8 @@ static void BuildComputeShader(std::map<std::string, Hash> &hashes, const std::s
// no profile => essl
} else if (api == "VK") {
cs_profile = "spirv";
} else if (api == "MTL") {
cs_profile = "metal";
} else {
const json json_err = {{"type", "UnsupportedComputeAPI"}, {"api", api}};
log_error(json_err);
@ -1231,6 +1233,8 @@ static void BuildShader(std::map<std::string, Hash> &hashes, const std::string &
// no profile => essl
} else if (api == "VK") {
vs_profile = fs_profile = "spirv";
} else if (api == "MTL") {
vs_profile = fs_profile = "metal";
} else {
const json json_err = {{"type", "UnsupportedShaderAPI"}, {"api", api}};
log_error(json_err);