diff --git a/CMake/SetupFfmpeg.cmake b/CMake/SetupFfmpeg.cmake index c8e2ceb25a..da9b758c94 100644 --- a/CMake/SetupFfmpeg.cmake +++ b/CMake/SetupFfmpeg.cmake @@ -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) diff --git a/CMake/SetupOggVorbis.cmake b/CMake/SetupOggVorbis.cmake new file mode 100644 index 0000000000..6c7f2ad575 --- /dev/null +++ b/CMake/SetupOggVorbis.cmake @@ -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") diff --git a/StepmaniaCore.cmake b/StepmaniaCore.cmake index 852dc3e440..87f82acabe 100644 --- a/StepmaniaCore.cmake +++ b/StepmaniaCore.cmake @@ -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}) diff --git a/extern/CMakeProject-cppformat.cmake b/extern/CMakeProject-cppformat.cmake new file mode 100644 index 0000000000..87a9d3bf37 --- /dev/null +++ b/extern/CMakeProject-cppformat.cmake @@ -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() + diff --git a/extern/CMakeProject-json.cmake b/extern/CMakeProject-json.cmake index 0b8fba9d88..37c18e32d8 100644 --- a/extern/CMakeProject-json.cmake +++ b/extern/CMakeProject-json.cmake @@ -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") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f521143d0b..dfb4fc9a34 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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}/$<$:Release>$<$:Debug>$<$:MinSizeRel>$<$:RelWithDebInfo>/libogg.a" + "${SM_VORBIS_ROOT}/lib/$<$:Release>$<$:Debug>$<$:MinSizeRel>$<$:RelWithDebInfo>/libvorbis.a" + "${SM_VORBIS_ROOT}/lib/$<$:Release>$<$:Debug>$<$:MinSizeRel>$<$: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() diff --git a/src/RageFileBasic.h b/src/RageFileBasic.h index 7f3a44f9e9..377d746999 100644 --- a/src/RageFileBasic.h +++ b/src/RageFileBasic.h @@ -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. */ diff --git a/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp b/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp index 9caf82c778..16eb0b55d6 100644 --- a/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp +++ b/src/arch/InputHandler/InputHandler_MacOSX_HID.cpp @@ -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 ) { diff --git a/src/arch/LoadingWindow/LoadingWindow.h b/src/arch/LoadingWindow/LoadingWindow.h index 63dcb963c4..09e65fc169 100644 --- a/src/arch/LoadingWindow/LoadingWindow.h +++ b/src/arch/LoadingWindow/LoadingWindow.h @@ -1,6 +1,8 @@ #ifndef LOADING_WINDOW_H #define LOADING_WINDOW_H +#include + struct RageSurface; /** @brief Opens and displays the loading banner. */ class LoadingWindow diff --git a/src/arch/Threads/Threads_Pthreads.cpp b/src/arch/Threads/Threads_Pthreads.cpp index b8611fa349..872d057f7f 100644 --- a/src/arch/Threads/Threads_Pthreads.cpp +++ b/src/arch/Threads/Threads_Pthreads.cpp @@ -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 #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 diff --git a/src/archutils/Darwin/Crash.cpp b/src/archutils/Darwin/Crash.cpp index 68c9521dc6..1ee8f26341 100644 --- a/src/archutils/Darwin/Crash.cpp +++ b/src/archutils/Darwin/Crash.cpp @@ -3,6 +3,7 @@ #include "ProductInfo.h" #include "arch/ArchHooks/ArchHooks.h" #include +#include #include #if defined(HAVE_UNISTD_H) #include @@ -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 diff --git a/src/archutils/Darwin/DarwinThreadHelpers.cpp b/src/archutils/Darwin/DarwinThreadHelpers.cpp index 756adcc514..1a426ff4e5 100644 --- a/src/archutils/Darwin/DarwinThreadHelpers.cpp +++ b/src/archutils/Darwin/DarwinThreadHelpers.cpp @@ -2,7 +2,8 @@ #include #include #include -#include "Backtrace.h" +#include "global.h" +#include "Backtrace.hpp" bool SuspendThread( uint64_t threadHandle ) { diff --git a/src/archutils/Darwin/SMMain.mm b/src/archutils/Darwin/SMMain.mm index 7d56a1dc27..e755b12924 100644 --- a/src/archutils/Darwin/SMMain.mm +++ b/src/archutils/Darwin/SMMain.mm @@ -7,6 +7,7 @@ #import #include "ProductInfo.h" #include "arch/ArchHooks/ArchHooks.h" +#include "StepMania.h" @interface NSApplication (PrivateShutUpWarning) - (void) setAppleMenu:(NSMenu *)menu;