diff --git a/.gitignore b/.gitignore index 3ac25e5..ece2a50 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build *.egg-info dist commit_id +*.DS_Store diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index 30fb84e..fb83eff 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") @@ -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() 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/cmake/Finduuid.cmake b/harfang/cmake/Finduuid.cmake index c4f9618..a90f277 100644 --- a/harfang/cmake/Finduuid.cmake +++ b/harfang/cmake/Finduuid.cmake @@ -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) \ No newline at end of file diff --git a/harfang/foundation/CMakeLists.txt b/harfang/foundation/CMakeLists.txt index f37e4ed..e052ef5 100644 --- a/harfang/foundation/CMakeLists.txt +++ b/harfang/foundation/CMakeLists.txt @@ -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) 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);