CMake: Add method for specifying alternate package names

This commit is contained in:
Vicki Pfau 2020-12-13 17:34:25 -08:00
parent 346f5dc0b5
commit 9397eee606
2 changed files with 45 additions and 43 deletions

View File

@ -492,11 +492,11 @@ set(USE_CMOCKA ${BUILD_SUITE})
if(DEFINED VCPKG_TARGET_TRIPLET)
find_feature(USE_FFMPEG "FFMPEG")
if(FFMPEG_FOUND)
set(USE_LIBAVRESAMPLE OFF)
set(USE_LIBSWRESAMPLE ON)
set(LIBAVRESAMPLE_FOUND OFF)
set(LIBSWRESAMPLE_FOUND ON)
endif()
else()
find_feature(USE_FFMPEG "libavcodec;libavfilter;libavformat;libavutil;libswscale")
find_feature(USE_FFMPEG "libavcodec;libavfilter;libavformat;libavutil;libswscale;libswresample|libavresample")
endif()
find_feature(USE_ZLIB "ZLIB")
find_feature(USE_MINIZIP "minizip")
@ -504,17 +504,10 @@ find_feature(USE_PNG "PNG")
find_feature(USE_LIBZIP "libzip")
find_feature(USE_EPOXY "epoxy")
find_feature(USE_CMOCKA "cmocka")
find_feature(USE_SQLITE3 "sqlite3")
find_feature(USE_SQLITE3 "SQLite3|sqlite3")
find_feature(USE_ELF "libelf")
find_feature(ENABLE_PYTHON "PythonLibs")
if(USE_FFMPEG AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(USE_LIBAVRESAMPLE ON)
set(USE_LIBSWRESAMPLE ON)
find_feature(USE_LIBAVRESAMPLE "libavresample")
find_feature(USE_LIBSWRESAMPLE "libswresample")
endif()
# Features
add_subdirectory(src/debugger)
add_subdirectory(src/feature)
@ -540,7 +533,7 @@ source_group("Debugger" FILES ${DEBUGGER_SRC})
if(USE_FFMPEG)
list(APPEND FEATURES FFMPEG)
if(USE_LIBSWRESAMPLE)
if(LIBSWRESAMPLE_FOUND)
list(APPEND FEATURES LIBSWRESAMPLE)
else()
list(APPEND FEATURES LIBAVRESAMPLE)
@ -562,7 +555,7 @@ if(USE_FFMPEG)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavcodec${LIBAVCODEC_VERSION_MAJOR}|libavcodec-extra-${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg${LIBAVCODEC_VERSION_MAJOR}|libavcodec-ffmpeg-extra${LIBAVCODEC_VERSION_MAJOR}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavfilter${LIBAVFILTER_VERSION_MAJOR}|libavfilter-ffmpeg${LIBAVFILTER_VERSION_MAJOR}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libavformat${LIBAVFORMAT_VERSION_MAJOR}|libavformat-ffmpeg${LIBAVFORMAT_VERSION_MAJOR}")
if(USE_LIBSWRESAMPLE)
if(LIBSWRESAMPLE_FOUND)
string(REGEX MATCH "^[0-9]+" LIBSWRESAMPLE_VERSION_MAJOR ${libswresample_VERSION})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS},libswresample${LIBSWRESAMPLE_VERSION_MAJOR}|libswresample-ffmpeg${LIBSWRESAMPLE_VERSION_MAJOR}")
else()

View File

@ -7,41 +7,50 @@ function(find_feature FEATURE_NAME FEATURE_REQUIRES)
set(${FEATURE_NAME} OFF PARENT_SCOPE)
return()
endif()
foreach(REQUIRE ${FEATURE_REQUIRES})
if(NOT ${REQUIRE}_FOUND)
find_package(${REQUIRE} QUIET)
foreach(NAMES ${FEATURE_REQUIRES})
string(REPLACE "|" ";" NAMELIST "${NAMES}")
set(FOUND OFF)
foreach(REQUIRE ${NAMELIST})
if(NOT ${REQUIRE}_FOUND)
pkg_search_module(${REQUIRE} ${REQUIRE})
if (NOT ${REQUIRE}_FOUND)
message(WARNING "Requested module ${REQUIRE} missing for feature ${FEATURE_NAME}. Feature disabled.")
set(${FEATURE_NAME} OFF PARENT_SCOPE)
return()
find_package(${REQUIRE} QUIET)
if(NOT ${REQUIRE}_FOUND)
pkg_search_module(${REQUIRE} ${REQUIRE})
endif()
endif()
endif()
string(TOUPPER ${REQUIRE} UREQUIRE)
set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
set(${UREQUIRE}_VERSION_STRING ${${REQUIRE}_VERSION_STRING} PARENT_SCOPE)
if (APPLE)
set(IS_FRAMEWORK OFF)
set(LIBS)
foreach(LIB IN LISTS ${REQUIRE}_LIBRARIES)
if(LIB STREQUAL "-framework")
set(IS_FRAMEWORK ON)
elseif(IS_FRAMEWORK)
list(APPEND LIBS "-framework ${LIB}")
if(${REQUIRE}_FOUND)
string(TOUPPER ${REQUIRE} UREQUIRE)
set(${UREQUIRE}_CFLAGS_OTHER ${${REQUIRE}_CFLAGS_OTHER} PARENT_SCOPE)
set(${UREQUIRE}_FOUND ${${REQUIRE}_FOUND} PARENT_SCOPE)
set(${UREQUIRE}_INCLUDE_DIRS ${${REQUIRE}_INCLUDE_DIRS} PARENT_SCOPE)
set(${UREQUIRE}_VERSION_STRING ${${REQUIRE}_VERSION_STRING} PARENT_SCOPE)
if (APPLE)
set(IS_FRAMEWORK OFF)
set(LIBS)
foreach(LIB IN LISTS ${REQUIRE}_LIBRARIES)
if(LIB STREQUAL "-framework")
set(IS_FRAMEWORK ON)
elseif(IS_FRAMEWORK)
list(APPEND LIBS "-framework ${LIB}")
set(IS_FRAMEWORK OFF)
else()
list(APPEND LIBS ${LIB})
endif()
endforeach()
set(${UREQUIRE}_LIBRARIES ${LIBS} PARENT_SCOPE)
else()
list(APPEND LIBS ${LIB})
set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
endif()
endforeach()
set(${UREQUIRE}_LIBRARIES ${LIBS} PARENT_SCOPE)
else()
set(${UREQUIRE}_LIBRARIES ${${REQUIRE}_LIBRARIES} PARENT_SCOPE)
set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
set(FOUND ON)
break()
endif()
endforeach()
if (NOT FOUND)
message(WARNING "Requested module ${NAMES} missing for feature ${FEATURE_NAME}. Feature disabled.")
set(${FEATURE_NAME} OFF PARENT_SCOPE)
return()
endif()
set(${UREQUIRE}_LIBRARY_DIRS ${${REQUIRE}_LIBRARY_DIRS} PARENT_SCOPE)
set(${UREQUIRE}_LDFLAGS_OTHER ${${REQUIRE}_LDFLAGS_OTHER} PARENT_SCOPE)
endforeach()
endfunction()
endfunction()