From 956b0868fd2f2fe6e40c7db0e8eb8df3fc0249d8 Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Tue, 17 Oct 2023 03:31:56 +0100 Subject: [PATCH] externals: allow user to use system inih (#7073) --- CMakeLists.txt | 1 + externals/CMakeLists.txt | 8 +++- externals/cmake-modules/Findinih.cmake | 63 +++++++++++++++++++++++++ externals/inih/CMakeLists.txt | 2 +- src/android/app/src/main/jni/config.cpp | 2 +- src/citra/config.cpp | 2 +- 6 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 externals/cmake-modules/Findinih.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ac15f170..08cc24fdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,7 @@ option(USE_SYSTEM_JSON "Use the system JSON (nlohmann-json3) package (instead of option(USE_SYSTEM_DYNARMIC "Use the system dynarmic (instead of the bundled one)" OFF) option(USE_SYSTEM_FMT "Use the system fmt (instead of the bundled one)" OFF) option(USE_SYSTEM_XBYAK "Use the system xbyak (instead of the bundled one)" OFF) +option(USE_SYSTEM_INIH "Use the system inih (instead of the bundled one)" OFF) if (CITRA_USE_PRECOMPILED_HEADERS) message(STATUS "Using Precompiled Headers.") diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 7f3f44476..aeb53f619 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -126,7 +126,13 @@ set(BUILD_EXTERNAL OFF CACHE BOOL "") add_subdirectory(glslang) # inih -add_subdirectory(inih) +if(USE_SYSTEM_INIH) + find_package(inih REQUIRED COMPONENTS inih inir) + add_library(inih INTERFACE) + target_link_libraries(inih INTERFACE inih::inih inih::inir) +else() + add_subdirectory(inih) +endif() # MicroProfile add_library(microprofile INTERFACE) diff --git a/externals/cmake-modules/Findinih.cmake b/externals/cmake-modules/Findinih.cmake new file mode 100644 index 000000000..79f7e735f --- /dev/null +++ b/externals/cmake-modules/Findinih.cmake @@ -0,0 +1,63 @@ +if(NOT inih_FOUND) + # Inih includes both a base library and INIReader + # We must link against both to avoid linker errors. + + pkg_check_modules(INIR_TEMP INIReader) + pkg_check_modules(INIH_TEMP inih) + + + find_path(INIR_INCLUDE_DIR NAMES INIReader.h + PATHS + ${INIR_TEMP_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + + find_path(INIH_INCLUDE_DIR NAMES ini.h + PATHS + ${INIH_TEMP_INCLUDE_DIRS} + /usr/include + /use/local/include + ) + + find_library(INIR_LIBRARIES NAMES INIReader + PATHS + ${INIR_TEMP_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + find_library(INIH_LIBRARIES NAMES inih + PATHS + ${INIH_TEMP_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(INIR_INCLUDE_DIR AND INIH_INCLUDE_DIR AND INIR_LIBRARIES AND INIH_LIBRARIES) + set(inih_FOUND TRUE CACHE INTERNAL "Found inih library") + message(STATUS "Found inih ${INIR_INCLUDE_DIR} ${INIH_INCLUDE_DIR} ${INIR_LIBRARIES} ${INIH_LIBRARIES}") + else() + set(inih_FOUND FALSE CACHE INTERNAL "Found inih library") + message(STATUS "Inih not found.") + endif() + +endif() + +if(inih_FOUND AND NOT TARGET inih::inir OR NOT TARGET inih::inih) + add_library(inih::inir INTERFACE IMPORTED) + set_target_properties(inih::inir PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${INIR_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${INIR_LIBRARIES}" + IMPORTED_LOCATION "${INIR_LIBRARIES}" + ) + + add_library(inih::inih INTERFACE IMPORTED) + set_target_properties(inih::inih PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${INIH_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${INIH_LIBRARES}" + IMPORTED_LOCATION ${INIH_LIBRARIES} + ) + +endif() + \ No newline at end of file diff --git a/externals/inih/CMakeLists.txt b/externals/inih/CMakeLists.txt index 2a75852c2..044e68a8e 100644 --- a/externals/inih/CMakeLists.txt +++ b/externals/inih/CMakeLists.txt @@ -6,4 +6,4 @@ add_library(inih ) create_target_directory_groups(inih) -target_include_directories(inih INTERFACE .) +target_include_directories(inih INTERFACE ./inih/cpp) diff --git a/src/android/app/src/main/jni/config.cpp b/src/android/app/src/main/jni/config.cpp index e4c25fdf2..b4864a3fb 100644 --- a/src/android/app/src/main/jni/config.cpp +++ b/src/android/app/src/main/jni/config.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "common/file_util.h" #include "common/logging/backend.h" #include "common/logging/log.h" diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 9520a8f6d..1cbcf0262 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -6,8 +6,8 @@ #include #include #include +#include #include -#include #include "citra/config.h" #include "citra/default_ini.h" #include "common/file_util.h"