2022-08-02 01:35:22 +03:00
# like add_library(new ALIAS old) but avoids add_library cannot create ALIAS target "new" because target "old" is imported but not globally visible. on older cmake
# This can be replaced with a direct alias call once our minimum is cmake 3.18
function ( dolphin_alias_library new old )
string ( REPLACE "::" "" library_no_namespace ${ old } )
if ( NOT TARGET _alias_ ${ library_no_namespace } )
add_library ( _alias_ ${ library_no_namespace } INTERFACE )
target_link_libraries ( _alias_ ${ library_no_namespace } INTERFACE ${ old } )
endif ( )
add_library ( ${ new } ALIAS _alias_ ${ library_no_namespace } )
endfunction ( )
2022-08-02 01:35:34 +03:00
# Makes an imported target if it doesn't exist. Useful for when find scripts from older versions of cmake don't make the targets you need
function ( dolphin_make_imported_target_if_missing target lib )
if ( ${ lib } _FOUND AND NOT TARGET ${ target } )
add_library ( _ ${ lib } INTERFACE )
target_link_libraries ( _ ${ lib } INTERFACE "${${lib}_LIBRARIES}" )
target_include_directories ( _ ${ lib } INTERFACE "${${lib}_INCLUDE_DIRS}" )
add_library ( ${ target } ALIAS _ ${ lib } )
endif ( )
endfunction ( )
2023-04-16 10:46:42 +03:00
2024-11-07 05:45:32 +02:00
function ( dolphin_optional_system_library out_use_system library )
2023-04-16 10:46:42 +03:00
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 )
2024-11-07 05:45:32 +02:00
set ( ${ out_use_system } AUTO PARENT_SCOPE )
2023-04-16 10:46:42 +03:00
else ( )
2024-11-07 05:45:32 +02:00
set ( ${ out_use_system } ON PARENT_SCOPE )
2023-04-16 10:46:42 +03:00
endif ( )
else ( )
2024-11-07 05:45:32 +02:00
set ( ${ out_use_system } ${ USE_SYSTEM_LIBS } PARENT_SCOPE )
2023-04-16 10:46:42 +03:00
endif ( )
else ( )
2024-11-07 05:45:32 +02:00
set ( ${ out_use_system } ${ USE_SYSTEM_${upperlib } } PARENT_SCOPE )
2023-04-16 10:46:42 +03:00
endif ( )
endfunction ( )
2024-11-07 05:45:32 +02:00
function ( dolphin_add_bundled_library library use_system bundled_path )
if ( ${ use_system } STREQUAL "AUTO" )
2023-04-16 10:46:42 +03:00
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 )
2024-11-07 05:45:32 +02:00
dolphin_optional_system_library ( use_system ${ library } )
2023-04-16 10:46:42 +03:00
string ( TOUPPER ${ library } upperlib )
2024-11-07 05:45:32 +02:00
if ( use_system )
2023-04-16 10:46:42 +03:00
find_package ( ${ library } ${ ARGN } )
# Yay for cmake packages being inconsistent
if ( DEFINED ${ library } _FOUND )
set ( prefix ${ library } )
else ( )
set ( prefix ${ upperlib } )
endif ( )
2024-11-07 05:45:32 +02:00
if ( ( NOT ${ prefix } _FOUND ) AND ( NOT ${ use_system } STREQUAL "AUTO" ) )
2023-04-16 10:46:42 +03:00
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 ( )
2024-11-07 05:45:32 +02:00
dolphin_add_bundled_library ( ${ library } ${ use_system } ${ bundled_path } )
2023-04-16 10:46:42 +03:00
set ( ${ prefix } _TYPE "Bundled" PARENT_SCOPE )
endif ( )
endfunction ( )
function ( dolphin_find_optional_system_library_pkgconfig library search alias bundled_path )
2024-11-07 05:45:32 +02:00
dolphin_optional_system_library ( use_system ${ library } )
2023-04-16 10:46:42 +03:00
string ( TOUPPER ${ library } upperlib )
2024-11-07 05:45:32 +02:00
if ( use_system )
2024-05-07 07:00:56 +03:00
pkg_search_module ( ${ library } ${ search } ${ ARGN } IMPORTED_TARGET )
2024-11-07 05:45:32 +02:00
if ( ( NOT ${ library } _FOUND ) AND ( NOT ${ use_system } STREQUAL "AUTO" ) )
2023-04-16 10:46:42 +03:00
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 ( )
2024-11-07 05:45:32 +02:00
dolphin_add_bundled_library ( ${ library } ${ use_system } ${ bundled_path } )
2023-04-16 10:46:42 +03:00
set ( ${ library } _TYPE "Bundled" PARENT_SCOPE )
endif ( )
endfunction ( )