* macOS build fixes (#1773)

* macOS build fixes

Add missing headers
Threads_Pthreads: do not call pthread_setname_np() on macOS as it does not do
the same as on Linux
DebugStr() -> os_log()

* Make the project build with Makefiles on macOS

* Fix getting modifier key state on Mac (#1774)

We really need to clean up all Carbon calls here (many will go away when the
project switches to SDL2 for all platforms)

* Fix Xcode build; bump minimum version of macOS (#1775)

* Build fixes for the "Unix Makefiles" generator
Pass CMAKE_BUILD_TYPE to the external projects
* Fix indent
This commit is contained in:
Tatsh
2018-12-31 22:28:59 -05:00
committed by Colby Klein
parent 338becc5d7
commit d395028bd4
13 changed files with 195 additions and 20 deletions
+8
View File
@@ -32,6 +32,14 @@ if(MACOSX)
"--arch=i386"
"--cc=clang -m32"
)
find_program(
FFMPEG_YASM_EXECUTABLE
yasm
PATHS /usr/bin /usr/local/bin /opt/local/bin)
list(APPEND FFMPEG_CONFIGURE
"--yasmexe=${FFMPEG_YASM_EXECUTABLE}"
)
endif()
if(WITH_GPL_LIBS)
+66
View File
@@ -0,0 +1,66 @@
set(SM_OGG_SRC_DIR "${SM_EXTERN_DIR}/libogg-git")
if (NOT (IS_DIRECTORY "${SM_OGG_SRC_DIR}"))
message(ERROR "Submodule for ogg missing. Run git submodule init && git submodule update first.")
endif()
externalproject_add("ogg"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
SOURCE_DIR "${SM_OGG_SRC_DIR}"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
externalproject_get_property("ogg" BINARY_DIR)
set(SM_OGG_ROOT ${BINARY_DIR})
set(SM_OGG_INCLUDE_DIR "${SM_OGG_SRC_DIR}/include")
if(APPLE AND CMAKE_GENERATOR MATCHES "Unix Makefiles")
# Xcode does this and CMake is somehow aware, but with Unix Makefiles this is
# necessary for the time being.
externalproject_add_step("ogg"
fix-path
COMMAND ${CMAKE_COMMAND} -E make_directory ${SM_OGG_ROOT}/${CMAKE_BUILD_TYPE}
DEPENDEES build)
externalproject_add_step("ogg"
copy-libogg
COMMAND ${CMAKE_COMMAND} -E copy ${SM_OGG_ROOT}/libogg.a ${SM_OGG_ROOT}/${CMAKE_BUILD_TYPE}/
DEPENDEES fix-path)
endif()
set(SM_VORBIS_SRC_DIR "${SM_EXTERN_DIR}/libvorbis-git")
if (NOT (IS_DIRECTORY "${SM_VORBIS_SRC_DIR}"))
message(ERROR "Submodule for vorbis missing. Run git submodule init && git submodule update first.")
endif()
externalproject_add("vorbis"
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DOGG_INCLUDE_DIRS:STRING=${SM_OGG_INCLUDE_DIR} -DOGG_LIBRARIES:STRING=${SM_OGG_ROOT}/${CMAKE_BUILD_TYPE}/libogg.a
SOURCE_DIR "${SM_VORBIS_SRC_DIR}"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
externalproject_get_property("vorbis" BINARY_DIR)
set(SM_VORBIS_ROOT ${BINARY_DIR})
set(SM_VORBIS_INCLUDE_DIR "${SM_VORBIS_SRC_DIR}/include")
if(APPLE AND CMAKE_GENERATOR MATCHES "Unix Makefiles")
# See note above
externalproject_add_step("vorbis"
fix-path
COMMAND ${CMAKE_COMMAND} -E make_directory ${SM_VORBIS_ROOT}/lib/${CMAKE_BUILD_TYPE}
DEPENDEES build)
externalproject_add_step("vorbis"
copy-libvorbis
COMMAND ${CMAKE_COMMAND} -E copy ${SM_VORBIS_ROOT}/lib/libvorbis.a ${SM_VORBIS_ROOT}/lib/${CMAKE_BUILD_TYPE}/
DEPENDEES fix-path)
externalproject_add_step("vorbis"
copy-libvorbisfile
COMMAND ${CMAKE_COMMAND} -E copy ${SM_VORBIS_ROOT}/lib/libvorbisfile.a ${SM_VORBIS_ROOT}/lib/${CMAKE_BUILD_TYPE}/
DEPENDEES fix-path)
endif()
add_dependencies("vorbis" "ogg")
+14 -5
View File
@@ -221,6 +221,18 @@ if(WITH_OGG)
endif()
endif()
if(WITH_SDL)
find_package(SDL2)
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL2 Library was not found. If you wish to compile without SDL2, set WITH_SDL to OFF when configuring.")
else()
set(HAS_SDL TRUE)
endif()
endif()
find_package(nasm)
find_package(yasm)
@@ -279,11 +291,8 @@ elseif(MACOSX)
set(SYSTEM_PCRE_FOUND FALSE)
set(WITH_CRASH_HANDLER TRUE)
# Apple Archs needs to be 32-bit for now.
# When SDL2 is introduced, this may change.
set(CMAKE_OSX_ARCHITECTURES "i386")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.7")
set(CMAKE_OSX_DEPLOYMENT_TARGET_FULL "10.7.1")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9")
set(CMAKE_OSX_DEPLOYMENT_TARGET_FULL "10.9.0")
find_library(MAC_FRAME_ACCELERATE Accelerate ${CMAKE_SYSTEM_FRAMEWORK_PATH})
find_library(MAC_FRAME_APPKIT AppKit ${CMAKE_SYSTEM_FRAMEWORK_PATH})
+39
View File
@@ -0,0 +1,39 @@
if (NOT IS_DIRECTORY "${SM_EXTERN_DIR}/cppformat")
message(ERROR "Submodule for cppformat missing. Run git submodule init && git submodule update first.")
return()
endif()
list(APPEND CPPFORMAT_SRC
"cppformat/fmt/format.cc"
)
list(APPEND CPPFORMAT_HPP
"cppformat/fmt/format.h"
)
source_group("" FILES ${CPPFORMAT_SRC} ${CPPFORMAT_HPP})
add_library("cppformat" ${CPPFORMAT_SRC} ${CPPFORMAT_HPP})
set_property(TARGET "cppformat" PROPERTY FOLDER "External Libraries")
disable_project_warnings("cppformat")
target_include_directories("cppformat" PUBLIC "cppformat")
if (MSVC)
sm_add_compile_definition("cppformat" _CRT_SECURE_NO_WARNINGS)
elseif(APPLE)
set_target_properties("cppformat" PROPERTIES
XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "${SM_CPP_STANDARD}"
XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
)
sm_add_compile_flag("cppformat" "-std=${SM_CPP_STANDARD}")
sm_add_compile_flag("cppformat" "-stdlib=libc++")
else() # Unix
sm_add_compile_flag("cppformat" "-std=${SM_CPP_STANDARD}")
if (CMAKE_CXX_COMPILER MATCHES "clang")
sm_add_compile_flag("cppformat" "-stdlib=libc++")
endif()
endif()
+2
View File
@@ -31,6 +31,8 @@ elseif(APPLE)
XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "gnu++14"
XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++"
)
sm_add_compile_flag("jsoncpp" "-std=${SM_CPP_STANDARD}")
sm_add_compile_flag("jsoncpp" "-stdlib=libc++")
else() # Unix/Linux
sm_add_compile_flag("jsoncpp" "-std=gnu++11")
if (CMAKE_CXX_COMPILER MATCHES "clang")
+14
View File
@@ -183,6 +183,7 @@ if(WIN32)
)
endif()
elseif(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14 -stdlib=libc++ -DMACOSX")
set_target_properties("${SM_EXE_NAME}" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${SM_ROOT_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${SM_ROOT_DIR}"
@@ -430,6 +431,14 @@ elseif(APPLE)
"pcre"
)
if (HAS_OGG)
list(APPEND SMDATA_LINK_LIB
"${SM_OGG_ROOT}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>$<$<CONFIG:MinSizeRel>:MinSizeRel>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>/libogg.a"
"${SM_VORBIS_ROOT}/lib/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>$<$<CONFIG:MinSizeRel>:MinSizeRel>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>/libvorbis.a"
"${SM_VORBIS_ROOT}/lib/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>$<$<CONFIG:MinSizeRel>:MinSizeRel>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>/libvorbisfile.a"
)
endif()
if(HAS_FFMPEG)
list(APPEND SMDATA_LINK_LIB
"${SM_FFMPEG_ROOT}/libavformat/libavformat.a"
@@ -518,6 +527,11 @@ else() # Unix / Linux
list(APPEND SMDATA_LINK_LIB ${X11_LIBRARIES})
endif()
if(SDL2_FOUND)
list(APPEND SMDATA_LINK_LIB ${SDL2_LIBRARY})
sm_add_compile_definition("${SM_EXE_NAME}" HAVE_SDL)
endif()
if(PCRE_FOUND)
list(APPEND SMDATA_LINK_LIB ${PCRE_LIBRARY})
endif()
+2
View File
@@ -3,6 +3,8 @@
#ifndef RAGE_FILE_BASIC_H
#define RAGE_FILE_BASIC_H
#include "global.h"
/* This is a simple file I/O interface. Although most of these operations
* are straightforward, there are several of them; most of the time, you'll
* only want to implement RageFileObj. */
@@ -450,7 +450,9 @@ wchar_t InputHandler_MacOSX_HID::DeviceButtonToChar( DeviceButton button, bool b
UInt8 iMacVirtualKey;
if( KeyboardDevice::DeviceButtonToMacVirtualKey( button, iMacVirtualKey ) )
{
UInt32 nModifiers = bUseCurrentKeyModifiers ? GetCurrentKeyModifiers() : 0;
CGEventRef event = CGEventCreate(NULL);
CGEventFlags mods = CGEventGetFlags(event);
UInt32 nModifiers = bUseCurrentKeyModifiers ? (UInt32)mods : 0;
wchar_t sCharCode = KeyCodeToChar( iMacVirtualKey, nModifiers );
if( sCharCode != 0 )
{
+2
View File
@@ -1,6 +1,8 @@
#ifndef LOADING_WINDOW_H
#define LOADING_WINDOW_H
#include <string>
struct RageSurface;
/** @brief Opens and displays the loading banner. */
class LoadingWindow
+39 -11
View File
@@ -89,6 +89,39 @@ ThreadImpl *MakeThread( int (*pFunc)(void *pData), void *pData, uint64_t *piThre
thread->m_StartFinishedSem->Wait();
delete thread->m_StartFinishedSem;
// Copy the thread name.
const char *rawname = RageThread::GetThreadNameByID( *piThreadID );
const size_t maxNameLen = sizeof( thread->name );
if (strlen(rawname) < maxNameLen) {
// If it fits, I sits^H^H^H^Hcopy.
strncpy( thread->name, rawname, maxNameLen );
} else {
if ( strstr( rawname, "Worker thread" ) && strchr( rawname, '(' ) ) {
// Special case for RageUtil_WorkerThread.cpp
// "Worker thread (name)", e.g.
// "Worker thread (/@mc1int/)" => "(/@mc1int/)".
const char *workername = strchr( rawname, '(' );
strncpy( thread->name, workername, maxNameLen );
} else {
// Abbreviate the name by taking the first 6, last 7
// characters and adding '..' in the middle.
LOG->Trace( "Truncated thread name due to size limit of %d: %s",
maxNameLen, rawname );
snprintf( thread->name, maxNameLen, "%.6s..%s",
rawname, &rawname[strlen(rawname) - 7] );
}
}
// Ensure there is always a terminating NUL character.
thread->name[maxNameLen - 1] = '\0';
#ifndef MACOSX
// macOS/BSD can only set the name of the calling thread
ret = pthread_setname_np(thread->thread, thread->name);
if (ret != 0 && LOG) {
LOG->Trace("pthead_setname_np: %s", strerror(ret));
}
#endif
return thread;
}
@@ -127,7 +160,7 @@ bool MutexImpl_Pthreads::Lock()
while( tries-- )
{
/* Wait for ten seconds. If it takes longer than that, we're
/* Wait for ten seconds. If it takes longer than that, we're
* probably deadlocked. */
timeval tv;
gettimeofday( &tv, NULL );
@@ -208,11 +241,6 @@ MutexImpl *MakeMutex( RageMutex *pParent )
#if defined(UNIX)
#include <dlfcn.h>
#include "arch/ArchHooks/ArchHooks_Unix.h"
// commented out to allow comilation on macOS 10.12. -dguzek
//#elif defined(MACOSX)
//typedef int clockid_t;
//static const clockid_t CLOCK_REALTIME = 0;
//static const clockid_t CLOCK_MONOTONIC = 1;
#endif // On MinGW clockid_t is defined in pthread.h
namespace
{
@@ -288,7 +316,7 @@ EventImpl_Pthreads::EventImpl_Pthreads( MutexImpl_Pthreads *pParent )
m_pParent = pParent;
InitMonotonic();
pthread_condattr_t condattr;
pthread_condattr_init( &condattr );
@@ -420,7 +448,7 @@ bool SemaImpl_Pthreads::TryWait()
int ret = sem_trywait( &sem );
if( ret == -1 && errno == EAGAIN )
return false;
ASSERT_M( ret == 0, ssprintf("TryWait: sem_trywait failed: %s", strerror(errno)) );
return true;
@@ -433,7 +461,7 @@ SemaImpl_Pthreads::SemaImpl_Pthreads( int iInitialValue )
ASSERT_M( ret == 0, ssprintf( "SemaImpl_Pthreads: pthread_cond_init: %s", strerror(errno)) );
ret = pthread_mutex_init( &m_Mutex, NULL );
ASSERT_M( ret == 0, ssprintf( "SemaImpl_Pthreads: pthread_mutex_init: %s", strerror(errno)) );
m_iValue = iInitialValue;
}
@@ -542,7 +570,7 @@ SemaImpl *MakeSemaphore( int iInitialValue )
/*
* (c) 2001-2004 Glenn Maynard
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
@@ -552,7 +580,7 @@ SemaImpl *MakeSemaphore( int iInitialValue )
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
+3 -2
View File
@@ -3,6 +3,7 @@
#include "ProductInfo.h"
#include "arch/ArchHooks/ArchHooks.h"
#include <CoreServices/CoreServices.h>
#include <os/log.h>
#include <sys/types.h>
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
@@ -97,13 +98,13 @@ bool CrashHandler::IsDebuggerPresent()
void CrashHandler::DebugBreak()
{
DebugStr( "\pDebugBreak()" );
os_log(OS_LOG_DEFAULT, "DebugBreak()");
}
/*
* (c) 2003-2006 Steve Checkoway
* All rights reserved.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
+2 -1
View File
@@ -2,7 +2,8 @@
#include <mach/thread_act.h>
#include <mach/mach_init.h>
#include <mach/mach_error.h>
#include "Backtrace.h"
#include "global.h"
#include "Backtrace.hpp"
bool SuspendThread( uint64_t threadHandle )
{
+1
View File
@@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h>
#include "ProductInfo.h"
#include "arch/ArchHooks/ArchHooks.h"
#include "StepMania.h"
@interface NSApplication (PrivateShutUpWarning)
- (void) setAppleMenu:(NSMenu *)menu;