From 84445e46733016fea33e4c327f7e7c9d5f6b015b Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Wed, 9 Aug 2023 17:34:13 +0200 Subject: [PATCH] Makefile, CMake and other build fixes for OpentMPT --- .circleci/config.yml | 13 +++++-- cmake/Modules/FindOPENMPT.cmake | 23 ++++++++++++ libs/DLL-README.txt | 3 ++ src/CMakeLists.txt | 24 +++++++++++- src/Makefile | 11 +++--- src/sdl/CMakeLists.txt | 8 ++++ src/sdl/mixer_sound.c | 65 ++++++++++++++++----------------- src/win32/Makefile.cfg | 17 ++++++--- 8 files changed, 115 insertions(+), 49 deletions(-) create mode 100644 cmake/Modules/FindOPENMPT.cmake diff --git a/.circleci/config.yml b/.circleci/config.yml index 59ba67528..2238d92b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,6 +25,13 @@ jobs: - run: name: Add i386 arch command: dpkg --add-architecture i386 + - run: + name: Add STJr PPA + command: | + apt-get -qq update + apt-get -qq -y install dirmngr + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0B1702D71499D9C25F986507F240F4449D3B0EC6 + echo "deb http://ppa.launchpad.net/stjr/srb2/ubuntu trusty main" >> /etc/apt/sources.list - run: name: Update APT listing command: apt-get -qq update @@ -36,7 +43,7 @@ jobs: - v1-SRB2-APT - run: name: Install SDK - command: apt-get -qq -y --no-install-recommends install git build-essential nasm libpng-dev:i386 libsdl2-mixer-dev:i386 libgme-dev:i386 libcurl4-openssl-dev:i386 gettext ccache wget gcc-multilib upx openssh-client + command: apt-get -qq -y --no-install-recommends install git build-essential nasm libpng-dev:i386 libsdl2-mixer-dev:i386 libgme-dev:i386 libcurl4-openssl-dev:i386 libopenmpt-dev:i386 gettext ccache wget gcc-multilib upx openssh-client - save_cache: key: v1-SRB2-APT paths: @@ -50,13 +57,13 @@ jobs: # command: make -C src LINUX=1 cleandep - run: name: rebuild depend - command: make -C src LINUX=1 NOOPENMPT=1 clean + command: make -C src LINUX=1 clean - restore_cache: keys: - v1-SRB2-{{ .Branch }}-{{ checksum "objs/Linux/SDL/Release/depend.dep" }} - run: name: Compile - command: make -C src LINUX=1 ERRORMODE=1 NOOPENMPT=1 -k + command: make -C src LINUX=1 ERRORMODE=1 -k - store_artifacts: path: /root/SRB2/bin/Linux/Release/ destination: bin diff --git a/cmake/Modules/FindOPENMPT.cmake b/cmake/Modules/FindOPENMPT.cmake new file mode 100644 index 000000000..2d334b6f0 --- /dev/null +++ b/cmake/Modules/FindOPENMPT.cmake @@ -0,0 +1,23 @@ +include(LibFindMacros) + +libfind_pkg_check_modules(OPENMPT_PKGCONF OPENMPT) + +find_path(OPENMPT_INCLUDE_DIR + NAMES libopenmpt.h + PATHS + ${OPENMPT_PKGCONF_INCLUDE_DIRS} + "/usr/include/libopenmpt" + "/usr/local/include/libopenmpt" +) + +find_library(OPENMPT_LIBRARY + NAMES openmpt + PATHS + ${OPENMPT_PKGCONF_LIBRARY_DIRS} + "/usr/lib" + "/usr/local/lib" +) + +set(OPENMPT_PROCESS_INCLUDES OPENMPT_INCLUDE_DIR) +set(OPENMPT_PROCESS_LIBS OPENMPT_LIBRARY) +libfind_process(OPENMPT) \ No newline at end of file diff --git a/libs/DLL-README.txt b/libs/DLL-README.txt index bbb6d3cd4..c44558666 100644 --- a/libs/DLL-README.txt +++ b/libs/DLL-README.txt @@ -7,6 +7,7 @@ Here are the required DLLs, per build. For each architecture, copy all the binar * libs\dll-binaries\[i686/x86_64] * libs\SDL2\[i686/x86_64]...\bin * libs\SDL2_mixer\[i686/x86_64]...\bin +* libs\libopenmpt\[x86/x86_64]...\bin\mingw and don't forget to build r_opengl.dll for srb2dd. @@ -18,6 +19,7 @@ and don't forget to build r_opengl.dll for srb2dd. * libs\dll-binaries\i686\mgwhelp.dll (depend for exchndl.dll) * libs\SDL2\i686-w64-mingw32\bin\SDL2.dll * libs\SDL2_mixer\i686-w64-mingw32\bin\*.dll (get everything) +* libs\libopenmpt\x86\bin\mingw\libopenmpt.dll ## srb2kart, 64-bit @@ -27,3 +29,4 @@ and don't forget to build r_opengl.dll for srb2dd. * libs\dll-binaries\x86_64\mgwhelp.dll (depend for exchndl.dll) * libs\SDL2\x86_64-w64-mingw32\bin\SDL2.dll * libs\SDL2_mixer\x86_64-w64-mingw32\bin\*.dll (get everything) +* libs\libopenmpt\x86_64\bin\mingw\libopenmpt.dll diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4eb9f134..88231fc03 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -231,6 +231,8 @@ set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL "Enable zlib support.") set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL "Enable GME support.") +set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL + "Enable OpenMPT support.") set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL "Enable Discord rich presence support.") set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL @@ -247,7 +249,7 @@ set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL ### use internal libraries? if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL - "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME).") + "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") endif() if(${SRB2_CONFIG_HAVE_BLUA}) @@ -389,6 +391,26 @@ if(${SRB2_CONFIG_HAVE_DISCORDRPC}) endif() endif() +if(${SRB2_CONFIG_HAVE_OPENMPT}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(OPENMPT_FOUND ON) + set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") + else() # 32-bit + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") + endif() + else() + find_package(OPENMPT) + endif() + if(${OPENMPT_FOUND}) + set(SRB2_HAVE_OPENMPT ON) + add_definitions(-DHAVE_OPENMPT) + else() + message(WARNING "You have specified that OpenMPT is available but it was not found.") + endif() +endif() + if(${SRB2_CONFIG_HAVE_ZLIB}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(ZLIB_FOUND ON) diff --git a/src/Makefile b/src/Makefile index 91bed3962..6825d5600 100644 --- a/src/Makefile +++ b/src/Makefile @@ -236,6 +236,10 @@ ifdef DJGPPDOS include djgppdos/Makefile.cfg endif +ifndef NOOPENMPT +HAVE_OPENMPT=1 +endif + ifdef MINGW include win32/Makefile.cfg endif #ifdef MINGW @@ -251,10 +255,6 @@ HAVE_LIBGME=1 endif endif -ifndef NOOPENMPT -HAVE_OPENMPT=1 -endif - ifdef SOLARIS UNIXCOMMON=1 endif @@ -406,8 +406,7 @@ CFLAGS+=$(LIBGME_CFLAGS) endif ifdef HAVE_OPENMPT -# make libopenmpt optional -OPTS+=-DHAVE_OPENMPT -DOPENMPT_DYNAMIC +OPTS+=-DHAVE_OPENMPT LIBOPENMPT_PKGCONFIG?=libopenmpt LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 67df4a646..ac52bd45d 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -257,6 +257,7 @@ if(${SDL2_FOUND}) ${SDL2_INCLUDE_DIRS} ${SDL2_MIXER_INCLUDE_DIRS} ${GME_INCLUDE_DIRS} + ${OPENMPT_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS} @@ -307,12 +308,14 @@ if(${SDL2_FOUND}) HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/x86_64 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/bin HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/x86_64-w64-mingw32/bin + HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86_64/mingw ) else() find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/i686 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/bin HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/i686-w64-mingw32/bin + HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86/mingw ) endif() else() @@ -321,12 +324,14 @@ if(${SDL2_FOUND}) HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/x86_64 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/lib/x64 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/lib/x64 + HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86_64/mingw ) else() find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/i686 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/lib/x86 HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/lib/x86 + HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86/mingw ) endif() endif() @@ -347,6 +352,9 @@ if(${SDL2_FOUND}) if(${SRB2_CONFIG_HAVE_GME}) getwinlib(libgme "libgme.dll") endif() + if(${SRB2_CONFIG_HAVE_OPENMPT}) + getwinlib(libopenmpt "libopenmpt.dll") + endif() if(${SRB2_CONFIG_HAVE_DISCORDRPC}) getwinlib(discord-rpc "discord-rpc.dll") diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 77118e8ed..8f33bfefb 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -343,7 +343,8 @@ void I_StartupSound(void) } #ifdef HAVE_OPENMPT - load_openmpt(); + CONS_Printf("libopenmpt version: %s\n", openmpt_get_string("library_version")); + CONS_Printf("libopenmpt build date: %s\n", openmpt_get_string("build")); #endif sound_started = true; @@ -370,8 +371,7 @@ void I_ShutdownSound(void) #endif #ifdef HAVE_OPENMPT if (mod) - openmpt.module_destroy(mod); - unload_openmpt(); + openmpt_module_destroy(mod); #endif } @@ -840,9 +840,9 @@ static void mix_openmpt(void *udata, Uint8 *stream, int len) (void)udata; - openmpt.module_set_render_param(mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, cv_modfilter.value); - openmpt.module_set_repeat_count(mod, -1); // Always repeat - openmpt.module_read_interleaved_stereo(mod, SAMPLERATE, BUFFERSIZE, (short *)stream); + openmpt_module_set_render_param(mod, OPENMPT_MODULE_RENDER_INTERPOLATIONFILTER_LENGTH, cv_modfilter.value); + openmpt_module_set_repeat_count(mod, -1); // Always repeat + openmpt_module_read_interleaved_stereo(mod, SAMPLERATE, BUFFERSIZE, (short *)stream); // apply volume to stream for (i = 0, p = (short *)stream; i < len/2; i++, p++) @@ -933,7 +933,7 @@ boolean I_SetSongSpeed(float speed) { char modspd[16]; sprintf(modspd, "%g", speed); - openmpt.module_ctl_set(mod, "play.tempo_factor", modspd); + openmpt_module_ctl_set(mod, "play.tempo_factor", modspd); return true; } #else @@ -982,7 +982,7 @@ UINT32 I_GetSongLength(void) #endif #ifdef HAVE_OPENMPT if (mod) - return (UINT32)(openmpt.module_get_duration_seconds(mod) * 1000.); + return (UINT32)(openmpt_module_get_duration_seconds(mod) * 1000.); else #endif if (!music || I_SongType() == MU_MOD || I_SongType() == MU_MID) @@ -1075,7 +1075,7 @@ boolean I_SetSongPosition(UINT32 position) { // This isn't 100% correct because we don't account for loop points because we can't get them. // But if you seek past end of song, OpenMPT seeks to 0. So adjust the position anyway. - openmpt.module_set_position_seconds(mod, (double)(get_adjusted_position(position)/1000.0L)); // returns new position + openmpt_module_set_position_seconds(mod, (double)(get_adjusted_position(position)/1000.0L)); // returns new position return true; } else @@ -1143,8 +1143,8 @@ UINT32 I_GetSongPosition(void) if (mod) // This will be incorrect if we adjust for length because we can't get loop points. // So return unadjusted. See note in SetMusicPosition: we adjust for that. - return (UINT32)(openmpt.module_get_position_seconds(mod)*1000.); - //return get_adjusted_position((UINT32)(openmpt.module_get_position_seconds(mod)*1000.)); + return (UINT32)(openmpt_module_get_position_seconds(mod)*1000.); + //return get_adjusted_position((UINT32)(openmpt_module_get_position_seconds(mod)*1000.)); else #endif if (!music || I_SongType() == MU_MID) @@ -1266,27 +1266,23 @@ boolean I_LoadSong(char *data, size_t len) { case MUS_MODPLUG: case MUS_MOD: - if (openmpt.loaded) + mod = openmpt_module_create_from_memory2(data, len, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + if (!mod) { - mod = openmpt.module_create_from_memory2(data, len, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - if (!mod) - { - mod_err = openmpt.module_error_get_last(mod); - mod_err_str = openmpt.error_string(mod_err); - CONS_Alert(CONS_ERROR, "openmpt_module_create_from_memory2: %s\n", mod_err_str); - Mix_FreeMusic(music); - music = NULL; - return false; - } - else - { - Mix_FreeMusic(music); - music = NULL; - return true; - } - break; + mod_err = openmpt_module_error_get_last(mod); + mod_err_str = openmpt_error_string(mod_err); + CONS_Alert(CONS_ERROR, "openmpt_module_create_from_memory2: %s\n", mod_err_str); + Mix_FreeMusic(music); + music = NULL; + return false; } - // else, fall through + else + { + Mix_FreeMusic(music); + music = NULL; + return true; + } + break; case MUS_WAV: case MUS_MID: case MUS_OGG: @@ -1298,6 +1294,7 @@ boolean I_LoadSong(char *data, size_t len) } #endif + // Find the OGG loop point. loop_point = 0.0f; song_length = 0.0f; @@ -1346,7 +1343,7 @@ void I_UnloadSong(void) #ifdef HAVE_OPENMPT if (mod) { - openmpt.module_destroy(mod); + openmpt_module_destroy(mod); mod = NULL; } #endif @@ -1377,7 +1374,7 @@ boolean I_PlaySong(boolean looping) #ifdef HAVE_OPENMPT if (mod) { - openmpt.module_select_subsong(mod, 0); + openmpt_module_select_subsong(mod, 0); current_subsong = 0; Mix_HookMusic(mix_openmpt, mod); return true; @@ -1522,9 +1519,9 @@ boolean I_SetSongTrack(int track) if (current_subsong == track) return false; SDL_LockAudio(); - if (track >= 0 && track < openmpt.module_get_num_subsongs(mod)) + if (track >= 0 && track < openmpt_module_get_num_subsongs(mod)) { - openmpt.module_select_subsong(mod, track); + openmpt_module_select_subsong(mod, track); current_subsong = track; SDL_UnlockAudio(); return true; diff --git a/src/win32/Makefile.cfg b/src/win32/Makefile.cfg index 30a27affb..2341a1494 100644 --- a/src/win32/Makefile.cfg +++ b/src/win32/Makefile.cfg @@ -10,18 +10,25 @@ ifdef MINGW64 HAVE_LIBGME=1 LIBGME_CFLAGS=-I../libs/gme/include LIBGME_LDFLAGS=-L../libs/gme/win64 -lgme + +ifdef HAVE_OPENMPT + LIBOPENMPT_CFLAGS?=-I../libs/libopenmpt/inc + LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86_64/mingw -lopenmpt +endif + SDL_CFLAGS?=-I../libs/SDL2/x86_64-w64-mingw32/include/SDL2 -I../libs/SDL2_mixer/x86_64-w64-mingw32/include/SDL2 -Dmain=SDL_main SDL_LDFLAGS?=-L../libs/SDL2/x86_64-w64-mingw32/lib -L../libs/SDL2_mixer/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows - HAVE_OPENMPT=1 - LIBOPENMPT_CFLAGS?=-I../libs/libopenmpt/inc - LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86_64 -llibopenmpt else HAVE_LIBGME=1 LIBGME_CFLAGS=-I../libs/gme/include LIBGME_LDFLAGS=-L../libs/gme/win32 -lgme - HAVE_OPENMPT=1 + + +ifdef HAVE_OPENMPT LIBOPENMPT_CFLAGS?=-I../libs/libopenmpt/inc - LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86 -llibopenmpt + LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86/mingw -lopenmpt +endif + SDL_CFLAGS?=-I../libs/SDL2/i686-w64-mingw32/include/SDL2 -I../libs/SDL2_mixer/i686-w64-mingw32/include/SDL2 -Dmain=SDL_main SDL_LDFLAGS?=-L../libs/SDL2/i686-w64-mingw32/lib -L../libs/SDL2_mixer/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows endif