diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 46e8ca13d4..a9b44e623f 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -327,7 +327,13 @@ if (ENABLE_WEB_SERVICE) endif() # lodepng -add_subdirectory(lodepng) +if(USE_SYSTEM_LODEPNG) + add_library(lodepng INTERFACE) + find_package(lodepng REQUIRED) + target_link_libraries(lodepng INTERFACE lodepng::lodepng) +else() + add_subdirectory(lodepng) +endif() # (xperia64): Only use libyuv on Android b/c of build issues on Windows and mandatory JPEG if(ANDROID) diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake index 777a5d7fa1..28a1097f20 100644 --- a/externals/cmake-modules/CitraHandleSystemLibs.cmake +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -21,6 +21,7 @@ option(USE_SYSTEM_ZSTD "Use the system Zstandard library (instead of the bundled option(USE_SYSTEM_ENET "Use the system libenet (instead of the bundled one)" OFF) option(USE_SYSTEM_CRYPTOPP "Use the system cryptopp (instead of the bundled one)" OFF) option(USE_SYSTEM_CUBEB "Use the system cubeb (instead of the bundled one)" OFF) +option(USE_SYSTEM_LODEPNG "Use the system lodepng (instead of the bundled one)" OFF) # Qt and MoltenVK are handled separately CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_SDL2 "Disable system SDL2" OFF "USE_SYSTEM_LIBS" OFF) @@ -41,6 +42,7 @@ CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ZSTD "Disable system Zstandard" OFF "USE_S CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ENET "Disable system libenet" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CRYPTOPP "Disable system cryptopp" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_CUBEB "Disable system cubeb" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_LODEPNG "Disable system lodepng" OFF "USE_SYSTEM_LIBS" OFF) set(LIB_VAR_LIST SDL2 @@ -61,6 +63,7 @@ set(LIB_VAR_LIST ENET CRYPTOPP CUBEB + LODEPNG ) # First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS diff --git a/externals/cmake-modules/Findlodepng.cmake b/externals/cmake-modules/Findlodepng.cmake new file mode 100644 index 0000000000..1c163c029b --- /dev/null +++ b/externals/cmake-modules/Findlodepng.cmake @@ -0,0 +1,31 @@ +if(NOT LODEPNG_FOUND) + find_path(LODEPNG_INCLUDE_DIRS NAMES lodepng.h + PATHS + /usr/include + /usr/local/include + ) + + find_library(LODEPNG_LIBRARY_DIRS NAMES lodepng + PATHS + /usr/lib + /usr/local/lib + ) + + if(LODEPNG_INCLUDE_DIRS AND LODEPNG_LIBRARY_DIRS) + set(LODEPNG_FOUND TRUE CACHE INTERNAL "Found lodepng") + message(STATUS "Found lodepng: ${LODEPNG_LIBRARY_DIRS}, ${LODEPNG_INCLUDE_DIRS}") + else() + set(LODEPNG_FOUND FALSE CACHE INTERNAL "Found lodepng") + message(STATUS "Lodepng not found.") + endif() +endif() + +if(LODEPNG_FOUND AND NOT TARGET lodepng::lodepng) + add_library(lodepng::lodepng UNKNOWN IMPORTED) + set_target_properties(lodepng::lodepng PROPERTIES + INCLUDE_DIRECTORIES ${LODEPNG_INCLUDE_DIRS} + INTERFACE_LINK_LIBRARIES ${LODEPNG_LIBRARY_DIRS} + IMPORTED_LOCATION ${LODEPNG_LIBRARY_DIRS} + ) + +endif()