From 3c6c66df0c2d6a7bd6ecb0011e34b35a479f2757 Mon Sep 17 00:00:00 2001 From: Tommo Zhou Date: Sat, 29 Oct 2022 15:23:29 +0800 Subject: [PATCH] -fixing macos build --- extern/CMakeLists.txt | 2 +- extern/bgfx/bgfx.cmake | 33 +++++++++++++++++++++++ extern/bgfx/bx.cmake | 2 ++ harfang/platform/CMakeLists.txt | 4 +++ harfang/platform/osx/osx_input_system.cpp | 3 ++- harfang/platform/osx/osx_input_system.h | 4 +-- harfang/platform/osx/platform.cpp | 16 ++++++++--- languages/hg_lua/CMakeLists.txt | 4 +++ languages/hg_python/CMakeLists.txt | 3 +++ tools/assetc/assetc.cpp | 6 ++++- 10 files changed, 67 insertions(+), 10 deletions(-) diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 30fb84e..8c9d819 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -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") diff --git a/extern/bgfx/bgfx.cmake b/extern/bgfx/bgfx.cmake index bfb0913..94dbc81 100644 --- a/extern/bgfx/bgfx.cmake +++ b/extern/bgfx/bgfx.cmake @@ -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}") diff --git a/extern/bgfx/bx.cmake b/extern/bgfx/bx.cmake index fa62072..dc6db42 100644 --- a/extern/bgfx/bx.cmake +++ b/extern/bgfx/bx.cmake @@ -73,6 +73,8 @@ target_compile_definitions( bx PUBLIC $<$:BX_CONFIG_DEBUG=1> $<$:BX_CONFIG_DEBUG=0> + $<$:BX_CONFIG_DEBUG=0> + $<$:BX_CONFIG_DEBUG=0> ) if( UNIX AND NOT APPLE ) diff --git a/harfang/platform/CMakeLists.txt b/harfang/platform/CMakeLists.txt index 8fa7198..551f343 100644 --- a/harfang/platform/CMakeLists.txt +++ b/harfang/platform/CMakeLists.txt @@ -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 diff --git a/harfang/platform/osx/osx_input_system.cpp b/harfang/platform/osx/osx_input_system.cpp index ca1d0e1..09a7520 100644 --- a/harfang/platform/osx/osx_input_system.cpp +++ b/harfang/platform/osx/osx_input_system.cpp @@ -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 { diff --git a/harfang/platform/osx/osx_input_system.h b/harfang/platform/osx/osx_input_system.h index dd22675..f00b7dd 100644 --- a/harfang/platform/osx/osx_input_system.h +++ b/harfang/platform/osx/osx_input_system.h @@ -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 { diff --git a/harfang/platform/osx/platform.cpp b/harfang/platform/osx/platform.cpp index 6297cfe..a930999 100644 --- a/harfang/platform/osx/platform.cpp +++ b/harfang/platform/osx/platform.cpp @@ -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 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 &filters, std::string &output, const std::string &initial_dir) { + return false; +} + +bool SaveFileDialog(const std::string &title, const std::vector &filters, std::string &output, const std::string &initial_dir) { + return false; +} void DebugBreak() { /* STUB */ } diff --git a/languages/hg_lua/CMakeLists.txt b/languages/hg_lua/CMakeLists.txt index e596048..9cc3ddd 100644 --- a/languages/hg_lua/CMakeLists.txt +++ b/languages/hg_lua/CMakeLists.txt @@ -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) diff --git a/languages/hg_python/CMakeLists.txt b/languages/hg_python/CMakeLists.txt index aeeef4b..dd985a1 100644 --- a/languages/hg_python/CMakeLists.txt +++ b/languages/hg_python/CMakeLists.txt @@ -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}) diff --git a/tools/assetc/assetc.cpp b/tools/assetc/assetc.cpp index bf61c73..01acd53 100644 --- a/tools/assetc/assetc.cpp +++ b/tools/assetc/assetc.cpp @@ -962,7 +962,7 @@ void Texture(std::map &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 &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 &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);