Skip to content

Commit

Permalink
Merge pull request #13179 from TellowKrinkle/ForceSystemLib
Browse files Browse the repository at this point in the history
CMake: Optional system library fixes
  • Loading branch information
AdmiralCurtiss authored Jan 10, 2025
2 parents 98a8023 + 613c959 commit 93fc5c0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions CMake/DolphinLibraryTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ function(dolphin_make_imported_target_if_missing target lib)
endif()
endfunction()

function(dolphin_optional_system_library library)
function(dolphin_optional_system_library out_use_system 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)
set(${out_use_system} AUTO PARENT_SCOPE)
else()
set(RESOLVED_USE_SYSTEM_${upperlib} ON PARENT_SCOPE)
set(${out_use_system} ON PARENT_SCOPE)
endif()
else()
set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_LIBS} PARENT_SCOPE)
set(${out_use_system} ${USE_SYSTEM_LIBS} PARENT_SCOPE)
endif()
else()
set(RESOLVED_USE_SYSTEM_${upperlib} ${USE_SYSTEM_${upperlib}} PARENT_SCOPE)
set(${out_use_system} ${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")
function(dolphin_add_bundled_library library use_system bundled_path)
if (${use_system} STREQUAL "AUTO")
message(STATUS "No system ${library} was found. Using static ${library} from Externals.")
else()
message(STATUS "Using static ${library} from Externals")
Expand All @@ -52,35 +51,35 @@ function(dolphin_add_bundled_library library bundled_path)
endfunction()

function(dolphin_find_optional_system_library library bundled_path)
dolphin_optional_system_library(${library})
dolphin_optional_system_library(use_system ${library})
string(TOUPPER ${library} upperlib)
if(RESOLVED_USE_SYSTEM_${upperlib})
if(use_system)
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"))
if((NOT ${prefix}_FOUND) AND (NOT ${use_system} 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})
dolphin_add_bundled_library(${library} ${use_system} ${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})
dolphin_optional_system_library(use_system ${library})
string(TOUPPER ${library} upperlib)
if(RESOLVED_USE_SYSTEM_${upperlib})
if(use_system)
pkg_search_module(${library} ${search} ${ARGN} IMPORTED_TARGET)
if((NOT ${library}_FOUND) AND (NOT ${RESOLVED_USE_SYSTEM_${upperlib}} STREQUAL "AUTO"))
if((NOT ${library}_FOUND) AND (NOT ${use_system} STREQUAL "AUTO"))
message(FATAL_ERROR "No system ${library} was found. Please install it or set USE_SYSTEM_${upperlib} to AUTO or OFF.")
endif()
endif()
Expand All @@ -89,7 +88,7 @@ function(dolphin_find_optional_system_library_pkgconfig library search alias bun
dolphin_alias_library(${alias} PkgConfig::${library})
set(${library}_TYPE "System" PARENT_SCOPE)
else()
dolphin_add_bundled_library(${library} ${bundled_path})
dolphin_add_bundled_library(${library} ${use_system} ${bundled_path})
set(${library}_TYPE "Bundled" PARENT_SCOPE)
endif()
endfunction()

0 comments on commit 93fc5c0

Please sign in to comment.