Skip to content

Commit a3b894c

Browse files
committed
build: Enable CHD support via build option
1 parent 6a80efa commit a3b894c

File tree

12 files changed

+113
-56
lines changed

12 files changed

+113
-56
lines changed

desktop-ui/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ endif()
4747

4848
target_link_libraries(
4949
desktop-ui
50-
PRIVATE ares::ruby ares::hiro ares::ares mia chdr-static sljit
50+
PRIVATE ares::ruby ares::hiro ares::ares mia sljit
5151
)
5252

53+
if(ARES_ENABLE_CHD)
54+
target_link_libraries(desktop-ui PRIVATE chdr-static)
55+
endif()
56+
5357
set_target_properties(desktop-ui PROPERTIES OUTPUT_NAME ares)
5458

5559
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${desktop-ui_SOURCES})

mia/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ add_library(ares::mia ALIAS mia)
33

44
add_sourcery_command(mia resource)
55

6+
if(ARES_ENABLE_CHD)
7+
target_compile_definitions(mia PUBLIC ARES_ENABLE_CHD)
8+
endif()
9+
610
target_sources(
711
mia
812
PRIVATE

mia/medium/medium.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ auto CompactDisc::readDataSector(string pathname, u32 sectorID) -> vector<u8> {
171171
if(pathname.iendsWith(".cue")) {
172172
return readDataSectorCUE(pathname, sectorID);
173173
}
174+
#if defined(ARES_ENABLE_CHD)
174175
if(pathname.iendsWith(".chd")) {
175176
return readDataSectorCHD(pathname, sectorID);
176177
}
178+
#endif
177179
return {};
178180
}
179181

@@ -250,6 +252,7 @@ auto CompactDisc::readDataSectorCUE(string filename, u32 sectorID) -> vector<u8>
250252
return {};
251253
}
252254

255+
#if defined(ARES_ENABLE_CHD)
253256
auto CompactDisc::readDataSectorCHD(string filename, u32 sectorID) -> vector<u8> {
254257
Decode::CHD chd;
255258
if(!chd.load(filename)) return {};
@@ -277,3 +280,4 @@ auto CompactDisc::readDataSectorCHD(string filename, u32 sectorID) -> vector<u8>
277280

278281
return {};
279282
}
283+
#endif

mia/medium/medium.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ struct Cartridge : Medium {
1919

2020
struct CompactDisc : Medium {
2121
auto type() -> string override { return "Compact Disc"; }
22-
auto extensions() -> vector<string> override { return {"cue", "chd"}; }
22+
auto extensions() -> vector<string> override {
23+
#if defined(ARES_ENABLE_CHD)
24+
return {"cue", "chd"};
25+
#else
26+
return {"cue"};
27+
#endif
28+
}
2329
auto manifestAudio(string location) -> string;
2430
auto readDataSector(string filename, u32 sectorID) -> vector<u8>;
2531
private:
2632
auto readDataSectorBCD(string filename, u32 sectorID) -> vector<u8>;
2733
auto readDataSectorCUE(string filename, u32 sectorID) -> vector<u8>;
34+
#if defined(ARES_ENABLE_CHD)
2835
auto readDataSectorCHD(string filename, u32 sectorID) -> vector<u8>;
36+
#endif
2937
};
3038

3139
struct FloppyDisk : Medium {

mia/medium/mega-cd.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
struct MegaCD : CompactDisc {
22
auto name() -> string override { return "Mega CD"; }
3-
auto extensions() -> vector<string> override { return {"cue", "chd"}; }
3+
auto extensions() -> vector<string> override {
4+
#if defined(ARES_ENABLE_CHD)
5+
return {"cue", "chd"};
6+
#else
7+
return {"cue"};
8+
#endif
9+
}
410
auto load(string location) -> LoadResult override;
511
auto save(string location) -> bool override;
612
auto analyze(string location) -> string;

mia/medium/pc-engine-cd.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
struct PCEngineCD : CompactDisc {
22
auto name() -> string override { return "PC Engine CD"; }
3-
auto extensions() -> vector<string> override { return {"cue", "chd"}; }
3+
auto extensions() -> vector<string> override {
4+
#if defined(ARES_ENABLE_CHD)
5+
return {"cue", "chd"};
6+
#else
7+
return {"cue"};
8+
#endif
9+
}
410
auto load(string location) -> LoadResult override;
511
auto save(string location) -> bool override;
612
auto analyze(string location) -> string;

mia/medium/playstation.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
struct PlayStation : CompactDisc {
22
auto name() -> string override { return "PlayStation"; }
3-
auto extensions() -> vector<string> override { return {"cue", "chd", "exe"}; }
3+
auto extensions() -> vector<string> override {
4+
#if defined(ARES_ENABLE_CHD)
5+
return {"cue", "chd", "exe"};
6+
#else
7+
return {"cue", "exe"};
8+
#endif
9+
}
410
auto load(string location) -> LoadResult override;
511
auto save(string location) -> bool override;
612
auto analyze(string location) -> string;

mia/mia.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <nall/vfs.hpp>
55
#include <nall/beat/single/apply.hpp>
66
#include <nall/decode/cue.hpp>
7+
#if defined(ARES_ENABLE_CHD)
78
#include <nall/decode/chd.hpp>
9+
#endif
810
#include <nall/decode/wav.hpp>
911
using namespace nall;
1012

nall/nall/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ add_library(ares::nall ALIAS nall)
33

44
include(cmake/sources.cmake)
55

6-
target_link_libraries(nall PUBLIC sljit chdr-static)
6+
target_link_libraries(nall PUBLIC sljit)
7+
if(ARES_ENABLE_CHD)
8+
target_link_libraries(nall PUBLIC chdr-static)
9+
target_compile_definitions(nall PUBLIC ARES_ENABLE_CHD)
10+
endif()
711
target_compile_definitions(nall PUBLIC CMAKE)
812
target_compile_options(
913
nall

nall/nall/cmake/headers.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
#include <nall/cd.hpp>
9999
#include <nall/ips.hpp>
100100
#include <nall/decode/cue.hpp>
101+
#if defined(ARES_ENABLE_CHD)
101102
#include <nall/decode/chd.hpp>
103+
#endif
102104
#include <nall/decode/wav.hpp>
103105
#include <nall/dsp/iir/one-pole.hpp>
104106
#include <nall/dsp/iir/biquad.hpp>

nall/nall/vfs/cdrom.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include <nall/file.hpp>
66
#include <nall/string.hpp>
77
#include <nall/decode/cue.hpp>
8+
#if defined(ARES_ENABLE_CHD)
89
#include <nall/decode/chd.hpp>
10+
#endif
911
#include <nall/decode/wav.hpp>
1012

1113
namespace nall::vfs {
@@ -18,7 +20,9 @@ struct cdrom : file {
1820
static auto open(const string& location) -> shared_pointer<cdrom> {
1921
auto instance = shared_pointer<cdrom>{new cdrom};
2022
if(location.iendsWith(".cue") && instance->loadCue(location)) return instance;
23+
#if defined(ARES_ENABLE_CHD)
2124
if(location.iendsWith(".chd") && instance->loadChd(location)) return instance;
25+
#endif
2226
return {};
2327
}
2428

@@ -184,7 +188,7 @@ struct cdrom : file {
184188

185189
return true;
186190
}
187-
191+
#if defined(ARES_ENABLE_CHD)
188192
auto loadChd(const string& location) -> bool {
189193
auto chd = shared_pointer<Decode::CHD>::create();
190194
if(!chd->load(location)) return false;
@@ -265,6 +269,7 @@ struct cdrom : file {
265269

266270
return true;
267271
}
272+
#endif
268273

269274
private:
270275
void loadSub(const string& location, const CD::Session& session) {

thirdparty/CMakeLists.txt

+55-49
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,59 @@ target_include_directories(sljit PUBLIC ../thirdparty)
44
target_compile_definitions(sljit PUBLIC SLJIT_HAVE_CONFIG_PRE=1 SLJIT_HAVE_CONFIG_POST=1)
55
target_compile_options(sljit PRIVATE $<$<COMPILE_LANG_AND_ID:C,AppleClang,Clang,GNU>:-Wno-conditional-uninitialized>)
66

7-
# lzma
8-
add_subdirectory(libchdr/deps/lzma-24.05 EXCLUDE_FROM_ALL)
9-
list(APPEND CHDR_LIBS lzma)
10-
list(APPEND CHDR_INCLUDES lzma)
7+
option(ARES_ENABLE_CHD "Enable CHD format support via libchdr" ON)
118

12-
if(OS_MACOS)
13-
option(WITH_SYSTEM_ZLIB "Use system zlib" ON)
14-
endif()
15-
# zlib
16-
if(WITH_SYSTEM_ZLIB)
17-
find_package(ZLIB REQUIRED)
18-
list(APPEND PLATFORM_LIBS ZLIB::ZLIB)
19-
else()
20-
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
21-
add_subdirectory(libchdr/deps/zlib-1.3.1 EXCLUDE_FROM_ALL)
22-
set_target_properties(
23-
zlibstatic
24-
PROPERTIES POSITION_INDEPENDENT_CODE ON FOLDER thirdparty PREFIX ""
25-
)
26-
list(APPEND CHDR_LIBS zlibstatic)
27-
endif()
9+
if(ARES_ENABLE_CHD)
10+
# lzma
11+
add_subdirectory(libchdr/deps/lzma-24.05 EXCLUDE_FROM_ALL)
12+
list(APPEND CHDR_LIBS lzma)
13+
list(APPEND CHDR_INCLUDES lzma)
2814

29-
# zstd
30-
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
31-
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
32-
add_subdirectory(libchdr/deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
33-
list(APPEND CHDR_LIBS libzstd_static)
34-
#--------------------------------------------------
35-
# chdr
36-
#--------------------------------------------------
15+
if(OS_MACOS)
16+
option(WITH_SYSTEM_ZLIB "Use system zlib" ON)
17+
endif()
18+
# zlib
19+
if(WITH_SYSTEM_ZLIB)
20+
find_package(ZLIB REQUIRED)
21+
list(APPEND PLATFORM_LIBS ZLIB::ZLIB)
22+
else()
23+
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
24+
add_subdirectory(libchdr/deps/zlib-1.3.1 EXCLUDE_FROM_ALL)
25+
set_target_properties(
26+
zlibstatic
27+
PROPERTIES POSITION_INDEPENDENT_CODE ON FOLDER thirdparty PREFIX ""
28+
)
29+
list(APPEND CHDR_LIBS zlibstatic)
30+
endif()
3731

38-
set(
39-
CHDR_SOURCES
40-
libchdr/src/libchdr_bitstream.c
41-
libchdr/src/libchdr_cdrom.c
42-
libchdr/src/libchdr_chd.c
43-
libchdr/src/libchdr_flac.c
44-
libchdr/src/libchdr_huffman.c
45-
)
32+
# zstd
33+
option(ZSTD_BUILD_SHARED "BUILD SHARED LIBRARIES" OFF)
34+
option(ZSTD_BUILD_PROGRAMS "BUILD PROGRAMS" OFF)
35+
add_subdirectory(libchdr/deps/zstd-1.5.6/build/cmake EXCLUDE_FROM_ALL)
36+
list(APPEND CHDR_LIBS libzstd_static)
37+
#--------------------------------------------------
38+
# chdr
39+
#--------------------------------------------------
4640

47-
list(APPEND CHDR_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/libchdr/include)
41+
set(
42+
CHDR_SOURCES
43+
libchdr/src/libchdr_bitstream.c
44+
libchdr/src/libchdr_cdrom.c
45+
libchdr/src/libchdr_chd.c
46+
libchdr/src/libchdr_flac.c
47+
libchdr/src/libchdr_huffman.c
48+
)
4849

49-
add_library(chdr-static STATIC ${CHDR_SOURCES})
50-
target_include_directories(chdr-static PUBLIC ${CHDR_INCLUDES} PUBLIC libchdr/include)
51-
target_link_libraries(chdr-static PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
52-
target_compile_options(
53-
chdr-static
54-
PRIVATE $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unreachable-code -Wno-unused-function>
55-
)
50+
list(APPEND CHDR_INCLUDES ${CMAKE_CURRENT_BINARY_DIR}/libchdr/include)
51+
52+
add_library(chdr-static STATIC ${CHDR_SOURCES})
53+
target_include_directories(chdr-static PUBLIC ${CHDR_INCLUDES} PUBLIC libchdr/include)
54+
target_link_libraries(chdr-static PRIVATE ${CHDR_LIBS} ${PLATFORM_LIBS})
55+
target_compile_options(
56+
chdr-static
57+
PRIVATE $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unreachable-code -Wno-unused-function>
58+
)
59+
endif()
5660

5761
add_library(
5862
tzxfile
@@ -100,10 +104,12 @@ target_compile_options(ymfm PRIVATE $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-u
100104

101105
set_target_properties(ymfm PROPERTIES FOLDER thirdparty PREFIX "")
102106
set_target_properties(tzxfile PROPERTIES FOLDER thirdparty PREFIX "")
103-
set_target_properties(chdr-static PROPERTIES FOLDER thirdparty PREFIX "")
104107
set_target_properties(sljit PROPERTIES FOLDER thirdparty PREFIX "")
105-
if(NOT WITH_SYSTEM_ZLIB)
106-
set_target_properties(zlib PROPERTIES FOLDER thirdparty PREFIX "")
108+
if(ARES_ENABLE_CHD)
109+
set_target_properties(chdr-static PROPERTIES FOLDER thirdparty PREFIX "")
110+
if(NOT WITH_SYSTEM_ZLIB)
111+
set_target_properties(zlib PROPERTIES FOLDER thirdparty PREFIX "")
112+
endif()
113+
set_target_properties(lzma PROPERTIES FOLDER thirdparty PREFIX "")
114+
set_target_properties(libzstd_static PROPERTIES FOLDER thirdparty PREFIX "")
107115
endif()
108-
set_target_properties(lzma PROPERTIES FOLDER thirdparty PREFIX "")
109-
set_target_properties(libzstd_static PROPERTIES FOLDER thirdparty PREFIX "")

0 commit comments

Comments
 (0)