diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 69f4f3107..08aeffb7f 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -228,8 +228,14 @@ else() endif() # ENet -add_subdirectory(enet) -target_include_directories(enet INTERFACE ./enet/include) +if(USE_SYSTEM_ENET) + find_package(libenet REQUIRED) + add_library(enet INTERFACE) + target_link_libraries(enet INTERFACE libenet::libenet) +else() + add_subdirectory(enet) + target_include_directories(enet INTERFACE ./enet/include) +endif() # Cubeb if (ENABLE_CUBEB) diff --git a/externals/cmake-modules/CitraHandleSystemLibs.cmake b/externals/cmake-modules/CitraHandleSystemLibs.cmake index cbb80687d..13efe7eef 100644 --- a/externals/cmake-modules/CitraHandleSystemLibs.cmake +++ b/externals/cmake-modules/CitraHandleSystemLibs.cmake @@ -19,6 +19,7 @@ option(USE_SYSTEM_FDK_AAC_HEADERS "Use the system fdk-aac headers (instead of th option(USE_SYSTEM_FFMPEG_HEADERS "Use the system FFmpeg headers (instead of the bundled one)" OFF) option(USE_SYSTEM_GLSLANG "Use the system glslang and SPIR-V libraries (instead of the bundled ones)" OFF) option(USE_SYSTEM_ZSTD "Use the system Zstandard library (instead of the bundled one)" OFF) +option(USE_SYSTEM_ENET "Use the system libenet (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) @@ -37,6 +38,7 @@ CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FDK_AAC_HEADERS "Disable system fdk_aac" O CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_FFMPEG_HEADERS "Disable system ffmpeg" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_GLSLANG "Disable system glslang" OFF "USE_SYSTEM_LIBS" OFF) CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ZSTD "Disable system Zstandard" OFF "USE_SYSTEM_LIBS" OFF) +CMAKE_DEPENDENT_OPTION(DISABLE_SYSTEM_ENET "Disable system libenet" OFF "USE_SYSTEM_LIBS" OFF) set(LIB_VAR_LIST SDL2 @@ -55,6 +57,7 @@ set(LIB_VAR_LIST FFMPEG_HEADERS GLSLANG ZSTD + ENET ) # First, check that USE_SYSTEM_XXX is not used with USE_SYSTEM_LIBS diff --git a/externals/cmake-modules/Findlibenet.cmake b/externals/cmake-modules/Findlibenet.cmake new file mode 100644 index 000000000..2544fc2f9 --- /dev/null +++ b/externals/cmake-modules/Findlibenet.cmake @@ -0,0 +1,34 @@ +if(NOT libenet_FOUND) + pkg_check_modules(ENET_TMP libenet) + + find_path(libenet_INCLUDE_DIRS NAMES enet.h PATH_SUFFIXES enet + PATHS + ${ENET_TMP_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + + find_library(libenet_LIBRARY_DIRS NAMES enet + PATHS + ${ENET_TMP_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(libenet_INCLUDE_DIRS AND libenet_LIBRARY_DIRS) + set(libenet_FOUND TRUE CACHE INTERNAL "Found libenet") + message(STATUS "Found libenet ${libenet_LIBRARY_DIRS}, ${libenet_INCLUDE_DIRS}") + else() + set(libenet_FOUND FALSE CACHE INTERNAL "Found libenet") + message(STATUS "Libenet not found.") + endif() +endif() + +if(libenet_FOUND AND NOT TARGET libenet::libenet) + add_library(libenet::libenet UNKNOWN IMPORTED) + set_target_properties(libenet::libenet PROPERTIES + INCLUDE_DIRECTORIES ${libenet_INCLUDE_DIRS} + INTERFACE_LINK_LIBRARIES ${libenet_LIBRARY_DIRS} + IMPORTED_LOCATION ${libenet_LIBRARY_DIRS} + ) +endif()