From 048f6fac527cff53d32c2059f6b644a992a416a8 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Mon, 1 Aug 2022 17:35:22 -0500 Subject: [PATCH 1/2] CMake: Properly include zstd include directories --- CMake/DolphinLibraryTools.cmake | 10 ++++++++++ CMakeLists.txt | 13 +++++-------- Source/Core/DiscIO/CMakeLists.txt | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 CMake/DolphinLibraryTools.cmake diff --git a/CMake/DolphinLibraryTools.cmake b/CMake/DolphinLibraryTools.cmake new file mode 100644 index 0000000000..4f3a8df9f3 --- /dev/null +++ b/CMake/DolphinLibraryTools.cmake @@ -0,0 +1,10 @@ +# 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() diff --git a/CMakeLists.txt b/CMakeLists.txt index 163ea2c943..5ca704eb48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ include(CheckCCompilerFlag) include(CheckVendoringApproved) include(DolphinCompileDefinitions) include(DolphinDisableWarningsMSVC) +include(DolphinLibraryTools) include(RemoveCompileFlag) # Enable folders for IDE @@ -773,17 +774,13 @@ else() add_subdirectory(Externals/liblzma) endif() -pkg_check_modules(ZSTD QUIET libzstd>=1.4.0) -check_include_file(zstd.h HAVE_ZSTD_H) -if(ZSTD_FOUND AND HAVE_ZSTD_H) +pkg_check_modules(ZSTD QUIET libzstd>=1.4.0 IMPORTED_TARGET) +if(ZSTD_FOUND) message(STATUS "Using shared zstd version: " ${ZSTD_VERSION}) + dolphin_alias_library(zstd::zstd PkgConfig::ZSTD) else() check_vendoring_approved(zstd) - if(ZSTD_FOUND AND NOT HAVE_ZSTD_H) - message(STATUS "Shared zstd found but lacks headers, falling back to the static library") - else() - message(STATUS "Shared zstd not found, falling back to the static library") - endif() + message(STATUS "Shared zstd not found, falling back to the static library") add_subdirectory(Externals/zstd) endif() diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index 61790d89d8..eddfe9e2ff 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -71,7 +71,7 @@ PUBLIC core BZip2::BZip2 lzma - zstd + zstd::zstd PRIVATE fmt::fmt From 1bc133f3aed9254bf273a35a750bfc30f76e90f3 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Mon, 1 Aug 2022 17:35:34 -0500 Subject: [PATCH 2/2] CMake: Properly include lzma include directories --- CMake/DolphinLibraryTools.cmake | 10 ++++++++++ CMakeLists.txt | 11 ++++------- Source/Core/DiscIO/CMakeLists.txt | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMake/DolphinLibraryTools.cmake b/CMake/DolphinLibraryTools.cmake index 4f3a8df9f3..f1681306cb 100644 --- a/CMake/DolphinLibraryTools.cmake +++ b/CMake/DolphinLibraryTools.cmake @@ -8,3 +8,13 @@ function(dolphin_alias_library new old) endif() add_library(${new} ALIAS _alias_${library_no_namespace}) endfunction() + +# 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() diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ca704eb48..fb72407bd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -761,16 +761,13 @@ endif() # macOS ships with liblzma.dylib but no headers, so check for the headers too find_package(LibLZMA) -check_include_file(lzma.h HAVE_LZMA_H) -if(LIBLZMA_FOUND AND HAVE_LZMA_H) +if(LIBLZMA_FOUND) + # Imported target added in CMake 3.14 + dolphin_make_imported_target_if_missing(LibLZMA::LibLZMA LIBLZMA) message(STATUS "Using shared lzma") else() check_vendoring_approved(lzma) - if(LIBLZMA_FOUND AND NOT HAVE_LZMA_H) - message(STATUS "Shared lzma found but lacks headers, falling back to the static library") - else() - message(STATUS "Shared lzma not found, falling back to the static library") - endif() + message(STATUS "Shared lzma not found, falling back to the static library") add_subdirectory(Externals/liblzma) endif() diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index eddfe9e2ff..87bf6bea30 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -70,7 +70,7 @@ target_link_libraries(discio PUBLIC core BZip2::BZip2 - lzma + LibLZMA::LibLZMA zstd::zstd PRIVATE