Skip to content

Commit

Permalink
Merge pull request #490 from Antidote/relax-inih-requirement
Browse files Browse the repository at this point in the history
Don't strictly require inih
  • Loading branch information
Ghabry authored Jan 9, 2025
2 parents c359e1d + b7f3735 commit 34db541
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 12 deletions.
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include(MiscUtils)

# Compilation options
option(BUILD_SHARED_LIBS "Build shared library, disable for building the static library (default: ON)" ON)
option(LIBLCF_WITH_INI "INI parsing support (inih, required when building EasyRPG Player, default: ON)" ON)
option(LIBLCF_WITH_ICU "ICU encoding handling (when disabled only windows-1252 is supported, default: ON)" ON)
option(LIBLCF_WITH_XML "XML reading support (expat, default: ON)" ON)
option(LIBLCF_UPDATE_MIMEDB "Whether to run update-mime-database after install (default: ON)" ON)
Expand All @@ -30,7 +31,6 @@ set(LCF_SOURCES
src/dbarray.cpp
src/dbstring_struct.cpp
src/encoder.cpp
src/inireader.cpp
src/ldb_equipment.cpp
src/ldb_eventcommand.cpp
src/ldb_parameters.cpp
Expand Down Expand Up @@ -202,7 +202,6 @@ set(LCF_HEADERS
src/lcf/encoder.h
src/lcf/enum_tags.h
src/lcf/flag_set.h
src/lcf/inireader.h
src/lcf/ldb/reader.h
src/lcf/lmt/reader.h
src/lcf/lmu/reader.h
Expand Down Expand Up @@ -294,6 +293,17 @@ set(LCF_HEADERS
src/lcf/third_party/string_view.h
)

set(LCF_SUPPORT_INI 0)
if(LIBLCF_WITH_INI)
list(APPEND LCF_SOURCES
src/inireader.cpp
)
list(APPEND LCF_HEADERS
src/lcf/inireader.h
)
set(LCF_SUPPORT_INI 1)
endif()

add_library(lcf ${LCF_SOURCES} ${LCF_HEADERS})

# IDE source grouping
Expand Down Expand Up @@ -344,8 +354,12 @@ set_property(TARGET lcf PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
set_property(TARGET lcf PROPERTY EXPORT_NAME liblcf)

# inih
find_package(inih REQUIRED)
target_link_libraries(lcf inih::inih)
if (LCF_SUPPORT_INI)
find_package(inih REQUIRED)
target_link_libraries(lcf inih::inih)
else()
message(STATUS "inih is disabled. This component is required when building EasyRPG Player.")
endif ()

# icu
set(LCF_SUPPORT_ICU 0)
Expand Down
7 changes: 5 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ liblcf_la_SOURCES = \
src/dbarray.cpp \
src/dbstring_struct.cpp \
src/encoder.cpp \
src/inireader.cpp \
src/ldb_equipment.cpp \
src/ldb_eventcommand.cpp \
src/ldb_parameters.cpp \
Expand Down Expand Up @@ -219,7 +218,6 @@ lcfinclude_HEADERS = \
src/lcf/encoder.h \
src/lcf/enum_tags.h \
src/lcf/flag_set.h \
src/lcf/inireader.h \
src/lcf/log_handler.h \
src/lcf/reader_lcf.h \
src/lcf/reader_util.h \
Expand All @@ -231,6 +229,11 @@ lcfinclude_HEADERS = \
src/lcf/writer_lcf.h \
src/lcf/writer_xml.h

if SUPPORT_INI
liblcf_la_SOURCES += src/inireader.cpp
lcfinclude_HEADERS += src/lcf/inireader.h
endif

lcfldbinclude_HEADERS = \
src/lcf/ldb/reader.h \
src/generated/lcf/ldb/chunks.h
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Documentation is available at the documentation wiki: https://wiki.easyrpg.org

## Requirements

- [inih] for INI file reading. (required)
- [inih] for INI file reading. (required when building EasyRPG Player)
- [Expat] for XML reading support.
- [ICU] for character encoding detection and conversion (recommended).
- [ICU] for character encoding detection and conversion (recommended). When disabled only Windows-1252 is supported.


## Source code
Expand Down
4 changes: 3 additions & 1 deletion builds/cmake/liblcf-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ include(CMakeFindDependencyMacro)
# Required to find our installed Findinih.cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

find_dependency(inih REQUIRED)
if(@LCF_SUPPORT_INI@)
find_dependency(inih REQUIRED)
endif()

if(@LCF_SUPPORT_ICU@ EQUAL 1)
find_dependency(ICU COMPONENTS i18n uc data REQUIRED)
Expand Down
3 changes: 3 additions & 0 deletions builds/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

/* Enable XML reading support (expat) */
#define LCF_SUPPORT_XML @LCF_SUPPORT_XML@

/* Enable INI reading support (INIH) */
#define LCF_SUPPORT_INI @LCF_SUPPORT_INI@
9 changes: 7 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ LT_INIT([win32-dll])
AM_CONDITIONAL(CROSS_COMPILING,[test "x$cross_compiling" = "xyes"])

# Checks for libraries.
AX_PKG_CHECK_MODULES([INIH],[],[inih],[])

AC_SUBST([LCF_SUPPORT_ICU],[0])
AC_ARG_ENABLE([icu],[AS_HELP_STRING([--disable-icu],[Disable ICU encoding handling (only windows-1252 supported) [default=no]])])
AS_IF([test "x$enable_icu" != "xno"],[
Expand All @@ -36,6 +34,13 @@ AS_IF([test "x$enable_xml" != "xno"],[
])
AM_CONDITIONAL(SUPPORT_XML,[test $LCF_SUPPORT_XML == 1])

AC_SUBST([LCF_SUPPORT_INI],[0])
AC_ARG_ENABLE([ini],[AS_HELP_STRING([--disable-ini],[Disable INI reading support (inih) [default=no]])])
AS_IF([test "x$enable_ini" != "xno"],[
AX_PKG_CHECK_MODULES([INIH],[],[inih],[LCF_SUPPORT_INI=1])
])
AM_CONDITIONAL(SUPPORT_INI,[test $LCF_SUPPORT_INI == 1])

# Tools
AC_ARG_ENABLE([tools],[AS_HELP_STRING([--disable-tools],[Do not build and install the tools [default=no]])])
AM_CONDITIONAL(ENABLE_TOOLS,[test "x$enable_tools" != "xno"])
Expand Down
8 changes: 8 additions & 0 deletions src/reader_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,32 @@ std::vector<std::string> ReaderUtil::DetectEncodings(StringView string) {
}

std::string ReaderUtil::GetEncoding(StringView ini_file) {
#if LCF_SUPPORT_INI
INIReader ini(ToString(ini_file));
if (ini.ParseError() != -1) {
std::string encoding = ini.Get("EasyRPG", "Encoding", std::string());
if (!encoding.empty()) {
return ReaderUtil::CodepageToEncoding(atoi(encoding.c_str()));
}
}
#else
Log::Warning("Could not get encoding from ini file, disabled in this liblcf build.");
#endif
return {};
}

std::string ReaderUtil::GetEncoding(std::istream& filestream) {
#if LCF_SUPPORT_INI
INIReader ini(filestream);
if (ini.ParseError() != -1) {
std::string encoding = ini.Get("EasyRPG", "Encoding", std::string());
if (!encoding.empty()) {
return ReaderUtil::CodepageToEncoding(atoi(encoding.c_str()));
}
}
#else
Log::Warning("Could not get encoding from ini file, disabled in this liblcf build.");
#endif
return {};
}

Expand Down
2 changes: 1 addition & 1 deletion tools/lcf2xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char** argv)
std::cerr << "Usage: " << argv[0] << "[--2k] [--2k3] file1 [... fileN]" << std::endl;
std::cerr << "\t--2k: Treat files as RPG 2000" << std::endl;
std::cerr << "\t--2k3: Treat files as RPG 2003 (default)" << std::endl;
std::cerr << "\t--encoding N: Use encoding N as the file encoding" << std::endl;
std::cerr << "\t--encoding N: Use encoding N as the file encoding" << std::endl;

return 1;
}
Expand Down

0 comments on commit 34db541

Please sign in to comment.