build: simplify find modules

With this patch I've deleted a few find modules that are now unused
since the vcpkg transition, as the CMake code now forces CONFIG mode for
Catch2, fmt and nlohmann_json.

I've then simplified the lz4, opus, and zstd modules by exclusively
using pkg-config. They were using it already, but were ignoring the
result. Also, I believe that manually looking for libraries was required
for Conan to work, and it is thus not needed anymore.

Lastly, I believe that there is no platform that ships these system libs
without pkg-config/pkgconf, so requiring it should be fine.
This commit is contained in:
Andrea Pappacoda 2022-07-28 16:44:52 +02:00
parent 250c3d555e
commit 064625ef58
No known key found for this signature in database
GPG Key ID: 4A9208A2455077A7
6 changed files with 34 additions and 307 deletions

View File

@ -1,51 +0,0 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_Catch2 QUIET Catch2)
find_path(Catch2_INCLUDE_DIR
NAMES catch.hpp
PATHS ${PC_Catch2_INCLUDE_DIRS} ${CONAN_CATCH2_ROOT}
PATH_SUFFIXES catch2
)
if(Catch2_INCLUDE_DIR)
file(STRINGS "${Catch2_INCLUDE_DIR}/catch.hpp" _Catch2_version_lines
REGEX "#define[ \t]+CATCH_VERSION_(MAJOR|MINOR|PATCH)")
string(REGEX REPLACE ".*CATCH_VERSION_MAJOR +\([0-9]+\).*" "\\1" _Catch2_version_major "${_Catch2_version_lines}")
string(REGEX REPLACE ".*CATCH_VERSION_MINOR +\([0-9]+\).*" "\\1" _Catch2_version_minor "${_Catch2_version_lines}")
string(REGEX REPLACE ".*CATCH_VERSION_PATCH +\([0-9]+\).*" "\\1" _Catch2_version_patch "${_Catch2_version_lines}")
set(Catch2_VERSION "${_Catch2_version_major}.${_Catch2_version_minor}.${_Catch2_version_patch}")
unset(_Catch2_version_major)
unset(_Catch2_version_minor)
unset(_Catch2_version_patch)
unset(_Catch2_version_lines)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Catch2
FOUND_VAR Catch2_FOUND
REQUIRED_VARS
Catch2_INCLUDE_DIR
Catch2_VERSION
VERSION_VAR Catch2_VERSION
)
if(Catch2_FOUND)
set(Catch2_INCLUDE_DIRS ${Catch2_INCLUDE_DIR})
set(Catch2_DEFINITIONS ${PC_Catch2_CFLAGS_OTHER})
endif()
if(Catch2_FOUND AND NOT TARGET Catch2::Catch2)
add_library(Catch2::Catch2 UNKNOWN IMPORTED)
set_target_properties(Catch2::Catch2 PROPERTIES
IMPORTED_LOCATION "${Catch2_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_Catch2_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${Catch2_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
Catch2_INCLUDE_DIR
)

View File

@ -1,71 +0,0 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_fmt QUIET fmt)
find_path(fmt_INCLUDE_DIR
NAMES format.h
PATHS ${PC_fmt_INCLUDE_DIRS} ${CONAN_INCLUDE_DIRS_fmt}
PATH_SUFFIXES fmt
)
find_library(fmt_LIBRARY
NAMES fmt
PATHS ${PC_fmt_LIBRARY_DIRS} ${CONAN_LIB_DIRS_fmt}
)
if(fmt_INCLUDE_DIR)
set(_fmt_version_file "${fmt_INCLUDE_DIR}/core.h")
if(NOT EXISTS "${_fmt_version_file}")
set(_fmt_version_file "${fmt_INCLUDE_DIR}/format.h")
endif()
if(EXISTS "${_fmt_version_file}")
# parse "#define FMT_VERSION 60200" to 6.2.0
file(STRINGS "${_fmt_version_file}" fmt_VERSION_LINE
REGEX "^#define[ \t]+FMT_VERSION[ \t]+[0-9]+$")
string(REGEX REPLACE "^#define[ \t]+FMT_VERSION[ \t]+([0-9]+)$"
"\\1" fmt_VERSION "${fmt_VERSION_LINE}")
foreach(ver "fmt_VERSION_PATCH" "fmt_VERSION_MINOR" "fmt_VERSION_MAJOR")
math(EXPR ${ver} "${fmt_VERSION} % 100")
math(EXPR fmt_VERSION "(${fmt_VERSION} - ${${ver}}) / 100")
endforeach()
set(fmt_VERSION
"${fmt_VERSION_MAJOR}.${fmt_VERSION_MINOR}.${fmt_VERSION_PATCH}")
endif()
unset(_fmt_version_file)
unset(fmt_VERSION_LINE)
unset(fmt_VERSION_MAJOR)
unset(fmt_VERSION_MINOR)
unset(fmt_VERSION_PATCH)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(fmt
FOUND_VAR fmt_FOUND
REQUIRED_VARS
fmt_LIBRARY
fmt_INCLUDE_DIR
fmt_VERSION
VERSION_VAR fmt_VERSION
)
if(fmt_FOUND)
set(fmt_LIBRARIES ${fmt_LIBRARY})
set(fmt_INCLUDE_DIRS ${fmt_INCLUDE_DIR})
set(fmt_DEFINITIONS ${PC_fmt_CFLAGS_OTHER})
endif()
if(fmt_FOUND AND NOT TARGET fmt::fmt)
add_library(fmt::fmt UNKNOWN IMPORTED)
set_target_properties(fmt::fmt PROPERTIES
IMPORTED_LOCATION "${fmt_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_fmt_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${fmt_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
fmt_INCLUDE_DIR
fmt_LIBRARY
)

View File

@ -1,56 +1,19 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_lz4 QUIET lz4)
find_package(PkgConfig)
find_path(lz4_INCLUDE_DIR
NAMES lz4.h
PATHS ${PC_lz4_INCLUDE_DIRS}
)
find_library(lz4_LIBRARY
NAMES lz4
PATHS ${PC_lz4_LIBRARY_DIRS}
)
if(lz4_INCLUDE_DIR)
file(STRINGS "${lz4_INCLUDE_DIR}/lz4.h" _lz4_version_lines
REGEX "#define[ \t]+LZ4_VERSION_(MAJOR|MINOR|RELEASE)")
string(REGEX REPLACE ".*LZ4_VERSION_MAJOR *\([0-9]*\).*" "\\1" _lz4_version_major "${_lz4_version_lines}")
string(REGEX REPLACE ".*LZ4_VERSION_MINOR *\([0-9]*\).*" "\\1" _lz4_version_minor "${_lz4_version_lines}")
string(REGEX REPLACE ".*LZ4_VERSION_RELEASE *\([0-9]*\).*" "\\1" _lz4_version_release "${_lz4_version_lines}")
set(lz4_VERSION "${_lz4_version_major}.${_lz4_version_minor}.${_lz4_version_release}")
unset(_lz4_version_major)
unset(_lz4_version_minor)
unset(_lz4_version_release)
unset(_lz4_version_lines)
if (PKG_CONFIG_FOUND)
pkg_search_module(liblz4 IMPORTED_TARGET GLOBAL liblz4)
if (liblz4_FOUND)
add_library(lz4::lz4 ALIAS PkgConfig::liblz4)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(lz4
FOUND_VAR lz4_FOUND
REQUIRED_VARS
lz4_LIBRARY
lz4_INCLUDE_DIR
VERSION_VAR lz4_VERSION
)
if(lz4_FOUND)
set(lz4_LIBRARIES ${lz4_LIBRARY})
set(lz4_INCLUDE_DIRS ${lz4_INCLUDE_DIR})
set(lz4_DEFINITIONS ${PC_lz4_CFLAGS_OTHER})
endif()
if(lz4_FOUND AND NOT TARGET lz4::lz4)
add_library(lz4::lz4 UNKNOWN IMPORTED)
set_target_properties(lz4::lz4 PROPERTIES
IMPORTED_LOCATION "${lz4_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_lz4_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${lz4_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
lz4_INCLUDE_DIR
lz4_LIBRARY
liblz4_LINK_LIBRARIES
liblz4_FOUND
VERSION_VAR liblz4_VERSION
)

View File

@ -1,51 +0,0 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_nlohmann_json QUIET nlohmann_json)
find_path(nlohmann_json_INCLUDE_DIR
NAMES json.hpp
PATHS ${PC_nlohmann_json_INCLUDE_DIRS}
PATH_SUFFIXES nlohmann
)
if(nlohmann_json_INCLUDE_DIR)
file(STRINGS "${nlohmann_json_INCLUDE_DIR}/json.hpp" _nlohmann_json_version_lines
REGEX "#define[ \t]+NLOHMANN_JSON_VERSION_(MAJOR|MINOR|PATCH)")
string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_MAJOR +\([0-9]+\).*" "\\1" _nlohmann_json_version_major "${_nlohmann_json_version_lines}")
string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_MINOR +\([0-9]+\).*" "\\1" _nlohmann_json_version_minor "${_nlohmann_json_version_lines}")
string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_PATCH +\([0-9]+\).*" "\\1" _nlohmann_json_version_patch "${_nlohmann_json_version_lines}")
set(nlohmann_json_VERSION "${_nlohmann_json_version_major}.${_nlohmann_json_version_minor}.${_nlohmann_json_version_patch}")
unset(_nlohmann_json_version_major)
unset(_nlohmann_json_version_minor)
unset(_nlohmann_json_version_patch)
unset(_nlohmann_json_version_lines)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(nlohmann_json
FOUND_VAR nlohmann_json_FOUND
REQUIRED_VARS
nlohmann_json_INCLUDE_DIR
nlohmann_json_VERSION
VERSION_VAR nlohmann_json_VERSION
)
if(nlohmann_json_FOUND)
set(nlohmann_json_INCLUDE_DIRS ${nlohmann_json_INCLUDE_DIR})
set(nlohmann_json_DEFINITIONS ${PC_nlohmann_json_CFLAGS_OTHER})
endif()
if(nlohmann_json_FOUND AND NOT TARGET nlohmann_json::nlohmann_json)
add_library(nlohmann_json::nlohmann_json UNKNOWN IMPORTED)
set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
IMPORTED_LOCATION "${nlohmann_json_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_nlohmann_json_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
nlohmann_json_INCLUDE_DIR
)

View File

@ -1,44 +1,19 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_opus QUIET opus)
find_package(PkgConfig)
find_path(opus_INCLUDE_DIR
NAMES opus.h
PATHS ${PC_opus_INCLUDE_DIRS}
PATH_SUFFIXES opus
)
find_library(opus_LIBRARY
NAMES opus
PATHS ${PC_opus_LIBRARY_DIRS}
)
if (PKG_CONFIG_FOUND)
pkg_search_module(opus IMPORTED_TARGET GLOBAL opus)
if (opus_FOUND)
add_library(Opus::Opus ALIAS PkgConfig::opus)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(opus
FOUND_VAR opus_FOUND
REQUIRED_VARS
opus_LIBRARY
opus_INCLUDE_DIR
opus_LINK_LIBRARIES
opus_FOUND
VERSION_VAR opus_VERSION
)
if(opus_FOUND)
set(Opus_LIBRARIES ${opus_LIBRARY})
set(Opus_INCLUDE_DIRS ${opus_INCLUDE_DIR})
set(Opus_DEFINITIONS ${PC_opus_CFLAGS_OTHER})
endif()
if(opus_FOUND AND NOT TARGET Opus::Opus)
add_library(Opus::Opus UNKNOWN IMPORTED GLOBAL)
set_target_properties(Opus::Opus PROPERTIES
IMPORTED_LOCATION "${opus_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_opus_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${opus_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
opus_INCLUDE_DIR
opus_LIBRARY
)

View File

@ -1,57 +1,19 @@
# SPDX-FileCopyrightText: 2020 yuzu Emulator Project
# SPDX-FileCopyrightText: 2022 yuzu Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(PC_zstd QUIET libzstd)
find_package(PkgConfig)
find_path(zstd_INCLUDE_DIR
NAMES zstd.h
PATHS ${PC_zstd_INCLUDE_DIRS}
)
find_library(zstd_LIBRARY
NAMES zstd
PATHS ${PC_zstd_LIBRARY_DIRS}
)
if(zstd_INCLUDE_DIR)
file(STRINGS "${zstd_INCLUDE_DIR}/zstd.h" _zstd_version_lines
REGEX "#define[ \t]+ZSTD_VERSION_(MAJOR|MINOR|RELEASE)")
string(REGEX REPLACE ".*ZSTD_VERSION_MAJOR *\([0-9]*\).*" "\\1" _zstd_version_major "${_zstd_version_lines}")
string(REGEX REPLACE ".*ZSTD_VERSION_MINOR *\([0-9]*\).*" "\\1" _zstd_version_minor "${_zstd_version_lines}")
string(REGEX REPLACE ".*ZSTD_VERSION_RELEASE *\([0-9]*\).*" "\\1" _zstd_version_release "${_zstd_version_lines}")
set(zstd_VERSION "${_zstd_version_major}.${_zstd_version_minor}.${_zstd_version_release}")
unset(_zstd_version_major)
unset(_zstd_version_minor)
unset(_zstd_version_release)
unset(_zstd_version_lines)
if (PKG_CONFIG_FOUND)
pkg_search_module(libzstd IMPORTED_TARGET GLOBAL libzstd)
if (libzstd_FOUND)
add_library(zstd::zstd ALIAS PkgConfig::libzstd)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(zstd
FOUND_VAR zstd_FOUND
REQUIRED_VARS
zstd_LIBRARY
zstd_INCLUDE_DIR
zstd_VERSION
VERSION_VAR zstd_VERSION
)
if(zstd_FOUND)
set(zstd_LIBRARIES ${zstd_LIBRARY})
set(zstd_INCLUDE_DIRS ${zstd_INCLUDE_DIR})
set(zstd_DEFINITIONS ${PC_zstd_CFLAGS_OTHER})
endif()
if(zstd_FOUND AND NOT TARGET zstd::zstd)
add_library(zstd::zstd UNKNOWN IMPORTED)
set_target_properties(zstd::zstd PROPERTIES
IMPORTED_LOCATION "${zstd_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_zstd_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
zstd_INCLUDE_DIR
zstd_LIBRARY
libzstd_LINK_LIBRARIES
libzstd_FOUND
VERSION_VAR libzstd_VERSION
)