summaryrefslogtreecommitdiff
path: root/CMake/DolphinLibraryTools.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'CMake/DolphinLibraryTools.cmake')
-rw-r--r--CMake/DolphinLibraryTools.cmake75
1 files changed, 75 insertions, 0 deletions
diff --git a/CMake/DolphinLibraryTools.cmake b/CMake/DolphinLibraryTools.cmake
index f1681306cb..37f439de54 100644
--- a/CMake/DolphinLibraryTools.cmake
+++ b/CMake/DolphinLibraryTools.cmake
@@ -18,3 +18,78 @@ function(dolphin_make_imported_target_if_missing target lib)
add_library(${target} ALIAS _${lib})
endif()
endfunction()
+
+function(dolphin_optional_system_library library)
+ string(TOUPPER ${library} upperlib)
+ set(USE_SYSTEM_${upperlib} "" CACHE STRING "Use system ${library} instead of bundled. ON - Always use system and fail if unavailable, OFF - Always use bundled, AUTO - Use system if available, otherwise use bundled, blank - Delegate to USE_SYSTEM_LIBS. Default is blank.")
+ if("${USE_SYSTEM_${upperlib}}" STREQUAL "")
+ if(APPROVED_VENDORED_DEPENDENCIES)
+ string(TOLOWER ${library} lowerlib)
+ if(lowerlib IN_LIST APPROVED_VENDORED_DEPENDENCIES)
+ set(RESOLVED_USE_SYSTEM_${upperlib} AUTO PARENT_SCOPE)
+ else()
+ set(RESOLVED_USE_SYSTEM_${upperlib} ON PARENT_SCOPE)
+ endif()
+ else()
+ set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_LIBS} PARENT_SCOPE)
+ endif()
+ else()
+ set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_${upperlib}} PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(dolphin_add_bundled_library library bundled_path)
+ string(TOUPPER ${library} upperlib)
+ if (${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO")
+ message(STATUS "No system ${library} was found. Using static ${library} from Externals.")
+ else()
+ message(STATUS "Using static ${library} from Externals")
+ endif()
+ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${bundled_path}/CMakeLists.txt")
+ message(FATAL_ERROR "No bundled ${library} was found. Did you forget to checkout submodules?")
+ endif()
+ add_subdirectory(${bundled_path} EXCLUDE_FROM_ALL)
+endfunction()
+
+function(dolphin_find_optional_system_library library bundled_path)
+ dolphin_optional_system_library(${library})
+ string(TOUPPER ${library} upperlib)
+ if(RESOLVED_USE_SYSTEM_${upperlib})
+ find_package(${library} ${ARGN})
+ # Yay for cmake packages being inconsistent
+ if(DEFINED ${library}_FOUND)
+ set(prefix ${library})
+ else()
+ set(prefix ${upperlib})
+ endif()
+ if((NOT ${found}) AND (NOT ${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO"))
+ message(FATAL_ERROR "No system ${library} was found. Please install it or set USE_SYSTEM_${upperlib} to AUTO or OFF.")
+ endif()
+ endif()
+ if(${prefix}_FOUND)
+ message(STATUS "Using system ${library}")
+ set(${prefix}_TYPE "System" PARENT_SCOPE)
+ else()
+ dolphin_add_bundled_library(${library} ${bundled_path})
+ set(${prefix}_TYPE "Bundled" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(dolphin_find_optional_system_library_pkgconfig library search alias bundled_path)
+ dolphin_optional_system_library(${library})
+ string(TOUPPER ${library} upperlib)
+ if(RESOLVED_USE_SYSTEM_${upperlib})
+ pkg_check_modules(${library} ${search} ${ARGN} IMPORTED_TARGET)
+ if((NOT ${library}_FOUND) AND (NOT ${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO"))
+ message(FATAL_ERROR "No system ${library} was found. Please install it or set USE_SYSTEM_${upperlib} to AUTO or OFF.")
+ endif()
+ endif()
+ if(${library}_FOUND)
+ message(STATUS "Using system ${library}")
+ dolphin_alias_library(${alias} PkgConfig::${library})
+ set(${library}_TYPE "System" PARENT_SCOPE)
+ else()
+ dolphin_add_bundled_library(${library} ${bundled_path})
+ set(${library}_TYPE "Bundled" PARENT_SCOPE)
+ endif()
+endfunction()