From 634a5fa31cf4dfe7583e73c0a140e0b75ccd34f3 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Sat, 10 Nov 2018 17:43:38 +0300 Subject: [PATCH] Fix macOS compilation --- .gitignore | 4 ++++ .travis.yml | 3 --- .travis/build-mac.bash | 6 +++++- 3rdparty/CMakeLists.txt | 5 ++++- CMakeLists.txt | 5 +++++ Utilities/Thread.cpp | 9 +++++++++ rpcs3/CMakeLists.txt | 4 +++- 7 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 61d989f233..3542589944 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,7 @@ CMakeLists.txt.user # CLion /.idea/* /cmake-build-*/ + +# macOS +.DS_Store + diff --git a/.travis.yml b/.travis.yml index 1417400af2..86815e2483 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,6 @@ matrix: osx_image: xcode10 script: "/bin/bash -ex .travis/build-mac.bash" cache: ccache - # Unfortunately Requires MacOS 10.14 Mojave for latest c++ features, which Travis doesn't use yet - allow_failures: - - os: osx git: depth: false # Unshallow clone to obtain proper GIT_VERSION diff --git a/.travis/build-mac.bash b/.travis/build-mac.bash index 2ef51f74c5..6662921455 100644 --- a/.travis/build-mac.bash +++ b/.travis/build-mac.bash @@ -3,10 +3,14 @@ export CCACHE_SLOPPINESS=pch_defines,time_macros export CMAKE_PREFIX_PATH=/usr/local/opt/qt5/ export PATH="/usr/local/opt/ccache/libexec:$PATH" +# Allow using optional on 10.13 +sudo perl -pi -e 'BEGIN{undef $/;} s/(_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS[ ]+\\\n[^\n]+10)\.14/\1.13/;' \ + $(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__config + # Setup vulkan and gfx-rs/portability curl -sLO https://github.com/gfx-rs/portability/releases/download/latest/gfx-portability-macos-latest.zip unzip -: gfx-portability-macos-latest.zip -curl -sLO https://github.com/KhronosGroup/Vulkan-Headers/archive/sdk-1.1.77.0.zip +curl -sLO https://github.com/KhronosGroup/Vulkan-Headers/archive/sdk-1.1.85.0.zip unzip -: sdk-*.zip mkdir vulkan-sdk ln -s ${PWD}/Vulkan-Headers*/include vulkan-sdk/include diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 53eb4b7ae1..bd890f93ca 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -178,6 +178,9 @@ if (WIN32 OR CMAKE_SYSTEM MATCHES "Linux" OR APPLE) find_library(DISCORD_RPC_LIB discord-rpc-mac PATHS discord-rpc/lib/ NO_DEFAULT_PATH) endif() target_link_libraries(3rdparty_discord-rpc INTERFACE ${DISCORD_RPC_LIB}) + if(APPLE) + target_link_libraries(3rdparty_discord-rpc INTERFACE "objc" "-framework Foundation" "-framework CoreServices") + endif() endif() @@ -231,7 +234,7 @@ endif() # Vulkan set(VULKAN_TARGET 3rdparty_dummy_lib) -if(NOT APPLE AND USE_VULKAN) +if(USE_VULKAN) find_package(Vulkan) if(VULKAN_FOUND) add_library(3rdparty_vulkan INTERFACE) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7ba8602ac..603cb63602 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,11 @@ if(WIN32) add_definitions(-D_WIN32_WINNT=0x0602) endif() +if(APPLE) + include_directories(/opt/local/include) + link_directories(/opt/local/lib) +endif() + add_subdirectory(Vulkan EXCLUDE_FROM_ALL) add_subdirectory(asmjitsrc EXCLUDE_FROM_ALL) add_subdirectory(3rdparty) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 2a81974b61..33ae752d6f 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1783,6 +1783,15 @@ u64 thread_base::get_cycles() #ifdef _WIN32 if (QueryThreadCycleTime((HANDLE)m_thread.load(), &cycles)) { +#elif __APPLE__ + mach_port_name_t port = pthread_mach_thread_np((pthread_t)m_thread.load()); + mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; + thread_basic_info_data_t info; + kern_return_t ret = thread_info(port, THREAD_BASIC_INFO, (thread_info_t)&info, &count); + if (ret == KERN_SUCCESS) + { + cycles = static_cast(info.user_time.seconds + info.system_time.seconds) * 1'000'000'000 + + static_cast(info.user_time.microseconds + info.system_time.microseconds) * 1'000; #else clockid_t _clock; struct timespec thread_time; diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index 78c3e805cd..7050470f14 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -60,11 +60,13 @@ if (WIN32) target_sources(rpcs3 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/rpcs3.rc") endif() -if(UNIX) +if(UNIX AND NOT APPLE) find_package(X11 REQUIRED) target_include_directories(rpcs3 PUBLIC ${X11_INCLUDE_DIR}) target_link_libraries(rpcs3 ${X11_LIBRARIES}) +endif() +if(UNIX) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads REQUIRED) target_link_libraries(rpcs3 Threads::Threads)