Skip to content

Commit

Permalink
refactor: make external libraries optional (#1626)
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan authored Feb 7, 2025
1 parent f9b9b46 commit 78c63eb
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 53 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ option(USE_OPENGL "Use OpenGL" OFF)
# Enable Link Time Optimization?
option(WITH_LTO "Enable Link Time Optimization" OFF)

# Use LibSerialPort for serial port emulation?
option(USE_LIBSERIALPORT "Use LibSerialPort" ON)
# Use LibENET for network emulation?
option(USE_LIBENET "Use LibENET" ON)
# Use PortMidi for MIDI emulation?
option(USE_PORTMIDI "Use PortMidi" ON)
# Use LibMPEG2 for MPEG2 decoding (CD32 FMV)?
option(USE_LIBMPEG2 "Use LibMPEG2" ON)

## Determine proper semantic version
set(VERSION_MAJOR "7")
set(VERSION_MINOR "0")
Expand All @@ -38,7 +47,7 @@ set(PROJECT_COMPANY_NAMESPACE "com.blitterstudio") # Reverse domain name notati
include(GNUInstallDirs)

include(cmake/StandardProjectSettings.cmake)
include(cmake/Dependencies.cmake)
include(cmake/SourceFiles.cmake)
include(cmake/Dependencies.cmake)

add_subdirectory(packaging)
53 changes: 47 additions & 6 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,58 @@ find_package(FLAC REQUIRED)
find_package(mpg123 REQUIRED)
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
find_helper(LIBSERIALPORT libserialport libserialport.h serialport)
find_helper(PORTMIDI portmidi portmidi.h portmidi)
find_helper(LIBMPEG2_CONVERT libmpeg2convert mpeg2convert.h mpeg2convert)
find_helper(LIBMPEG2 libmpeg2 mpeg2.h mpeg2)
find_helper(LIBENET libenet enet/enet.h enet)

include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR} ${LIBENET_INCLUDE_DIRS})
if (USE_LIBSERIALPORT)
target_compile_definitions(${PROJECT_NAME} PRIVATE SERIAL_PORT)
find_helper(LIBSERIALPORT libserialport libserialport.h serialport)
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBSERIALPORT_LIBRARIES})
endif ()

if (USE_PORTMIDI)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PORTMIDI)
find_helper(PORTMIDI portmidi portmidi.h portmidi)
target_link_libraries(${PROJECT_NAME} PRIVATE ${PORTMIDI_LIBRARIES})
endif ()

if (USE_LIBMPEG2)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_LIBMPEG2)
find_helper(LIBMPEG2_CONVERT libmpeg2convert mpeg2convert.h mpeg2convert)
find_helper(LIBMPEG2 libmpeg2 mpeg2.h mpeg2)
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBMPEG2_LIBRARIES} ${LIBMPEG2_CONVERT_LIBRARIES})
endif ()

if (USE_LIBENET)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_LIBENET)
find_helper(LIBENET libenet enet/enet.h enet)
include_directories(${LIBENET_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBENET_LIBRARIES})
endif ()

include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${SDL2_TTF_INCLUDE_DIR})

set(libmt32emu_SHARED FALSE)
add_subdirectory(external/mt32emu)
add_subdirectory(external/floppybridge)
add_subdirectory(external/capsimage)
add_subdirectory(external/libguisan)

target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2
SDL2_image
SDL2_ttf
guisan
mt32emu
FLAC
png
MPG123::libmpg123
z
pthread
dl
)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(${PROJECT_NAME} PRIVATE rt)
endif ()

# Add dependencies to ensure external libraries are built
add_dependencies(${PROJECT_NAME} mt32emu floppybridge capsimage guisan)
26 changes: 0 additions & 26 deletions cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -442,32 +442,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
external/mt32emu/src
external/floppybridge/src
)
target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2
SDL2_image
SDL2_ttf
guisan
mt32emu
${DBUS_LIBRARIES}
FLAC
${PORTMIDI_LIBRARIES}
png
MPG123::libmpg123
${LIBMPEG2_LIBRARIES}
${LIBMPEG2_CONVERT_LIBRARIES}
${LIBSERIALPORT_LIBRARIES}
${LIBENET_LIBRARIES}
z
pthread
dl
)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(${PROJECT_NAME} PRIVATE rt)
endif ()

# Add dependencies to ensure external libraries are built
add_dependencies(${PROJECT_NAME} mt32emu floppybridge capsimage guisan)

# Install the executable
install(TARGETS ${PROJECT_NAME}
Expand Down
3 changes: 3 additions & 0 deletions external/floppybridge/src/SerialIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ DEFINE_GUID(GUID_DEVINTERFACE_COMPORT,0x86e0d1e0, 0x8089, 0x11d0, 0x9c, 0xe4, 0x
#include <sys/ioctl.h>
#include <errno.h>
#include <cstring>
#include <limits.h>
#include <time.h>
#include <sys/select.h>
#include <linux/serial.h>

#endif
Expand Down
4 changes: 2 additions & 2 deletions external/floppybridge/src/SuperCardProInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ SCPErr SCPInterface::writeCurrentTrackPrecomp(const unsigned char* mfmData, cons

writeheader header;
header.ramOffset = 0;
header.transferLength = htonl((u_long)outputBuffer.size() * 2UL);
header.transferLength = htonl((unsigned long)outputBuffer.size() * 2UL);

// Write the above to the RAM on the SCP
SCPResponse response;
Expand All @@ -519,7 +519,7 @@ SCPErr SCPInterface::writeCurrentTrackPrecomp(const unsigned char* mfmData, cons
selectDrive(true);

unsigned char buffer[5];
header.transferLength = htonl((u_long)outputBuffer.size());
header.transferLength = htonl((unsigned long)outputBuffer.size());
memcpy(buffer, &header.transferLength, 4);
buffer[4] = FLAGS_BITSIZE_16BIT | (writeFromIndexPulse ? BIT_READ_FROM_INDEX : 0);

Expand Down
3 changes: 3 additions & 0 deletions src/cd32_fmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "cda_play.h"
#include "archivers/mp2/kjmp2.h"

#ifdef USE_LIBMPEG2
#if (!defined _WIN32 && !defined ANDROID)
extern "C" {
#include "mpeg2dec/mpeg2.h"
Expand Down Expand Up @@ -1597,3 +1599,4 @@ addrbank *cd32_fmv_init (struct autoconfig_info *aci)

return &fmv_rom_bank;
}
#endif
2 changes: 2 additions & 0 deletions src/devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ void devices_update_sound(float clk, float syncadjust)
void devices_update_sync(float svpos, float syncadjust)
{
#ifdef CD32
#ifdef USE_LIBMPEG2
cd32_fmv_set_sync(svpos, syncadjust);
#endif
#endif
}

void virtualdevice_free(void)
Expand Down
2 changes: 2 additions & 0 deletions src/expansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,12 @@ static void REGPARAM2 expamemz3_lput (uaecptr addr, uae_u32 value)

static bool expamem_init_cd32fmv (struct autoconfig_info *aci)
{
#ifdef USE_LIBMPEG2
expamem_init_clear ();
load_rom_rc(aci->rc, ROMTYPE_CD32CART, 262144, 0, expamem, 128, 0);
memcpy(aci->autoconfig_raw, expamem, sizeof aci->autoconfig_raw);
expamem_map = cd32_fmv_init;
#endif
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include "uae/types.h"

#ifdef AMIBERRY
#ifdef USE_LIBSERIALPORT
#include <libserialport.h>
extern int check(sp_return result);
#endif
#endif

extern void serial_init (void);
extern void serial_exit (void);
Expand Down
2 changes: 0 additions & 2 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <fstream>
#include <filesystem>

#include <algorithm>
#include <execinfo.h>
#include "sysdeps.h"
#include "options.h"
#include "audio.h"
Expand Down
2 changes: 1 addition & 1 deletion src/osdep/amiberry_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ int is_touch_lightpen()
return 0;
}

int is_tablet(void)
int is_tablet()
{
return 0;
//return (tablet) ? 1 : 0;
Expand Down
Loading

0 comments on commit 78c63eb

Please sign in to comment.