1
0
mirror of synced 2024-11-12 02:00:52 +01:00

build: Get rid of pkgconfig as much as possible (#1517)

This commit is contained in:
Nik 2024-01-26 12:13:22 +01:00 committed by GitHub
parent b2121b25c1
commit 6ae86ce906
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 218 additions and 31 deletions

View File

@ -529,8 +529,6 @@ macro(setUninstallTarget)
endmacro() endmacro()
macro(addBundledLibraries) macro(addBundledLibraries)
find_package(PkgConfig REQUIRED)
set(EXTERNAL_LIBS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/external") set(EXTERNAL_LIBS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/external")
set(THIRD_PARTY_LIBS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/third_party") set(THIRD_PARTY_LIBS_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/lib/third_party")
@ -552,14 +550,12 @@ macro(addBundledLibraries)
set(XDGPP_INCLUDE_DIRS "${THIRD_PARTY_LIBS_FOLDER}/xdgpp") set(XDGPP_INCLUDE_DIRS "${THIRD_PARTY_LIBS_FOLDER}/xdgpp")
set(FPHSA_NAME_MISMATCHED ON CACHE BOOL "") set(FPHSA_NAME_MISMATCHED ON CACHE BOOL "")
find_package(PkgConfig REQUIRED)
if(NOT USE_SYSTEM_FMT) if(NOT USE_SYSTEM_FMT)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/fmt EXCLUDE_FROM_ALL) add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/fmt EXCLUDE_FROM_ALL)
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(FMT_LIBRARIES fmt::fmt-header-only) set(FMT_LIBRARIES fmt::fmt-header-only)
else() else()
find_package(fmt 8.0.0 REQUIRED) find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt) set(FMT_LIBRARIES fmt::fmt)
endif() endif()
@ -571,8 +567,7 @@ macro(addBundledLibraries)
if (NOT EMSCRIPTEN) if (NOT EMSCRIPTEN)
# curl # curl
find_package(PkgConfig REQUIRED) find_package(CURL REQUIRED)
pkg_check_modules(LIBCURL REQUIRED IMPORTED_TARGET libcurl>=7.60.0)
# nfd # nfd
if (NOT USE_SYSTEM_NFD) if (NOT USE_SYSTEM_NFD)
@ -617,13 +612,7 @@ macro(addBundledLibraries)
set_target_properties(libpl PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(libpl PROPERTIES POSITION_INDEPENDENT_CODE ON)
find_package(mbedTLS 3.4.0 REQUIRED) find_package(mbedTLS 3.4.0 REQUIRED)
find_library(MAGIC 5.39 magic REQUIRED)
pkg_search_module(MAGIC libmagic>=5.39)
if(NOT MAGIC_FOUND)
find_library(MAGIC 5.39 magic REQUIRED)
else()
set(MAGIC_INCLUDE_DIRS ${MAGIC_INCLUDEDIR})
endif()
if (NOT IMHEX_DISABLE_STACKTRACE) if (NOT IMHEX_DISABLE_STACKTRACE)
if (WIN32) if (WIN32)

View File

@ -0,0 +1,8 @@
find_path(CAPSTONE_INCLUDE_DIR capstone.h PATH_SUFFIXES capstone)
find_library(CAPSTONE_LIBRARY NAMES capstone)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Capstone DEFAULT_MSG CAPSTONE_LIBRARY CAPSTONE_INCLUDE_DIR)
mark_as_advanced(CAPSTONE_INCLUDE_DIR CAPSTONE_LIBRARY)

View File

@ -0,0 +1,139 @@
#.rst:
# Find GLFW
# ---------
#
# Finds the GLFW library using its cmake config if that exists, otherwise
# falls back to finding it manually. This module defines:
#
# GLFW_FOUND - True if GLFW library is found
# GLFW::GLFW - GLFW imported target
#
# Additionally, in case the config was not found, these variables are defined
# for internal usage:
#
# GLFW_LIBRARY - GLFW library
# GLFW_DLL_DEBUG - GLFW debug DLL on Windows, if found
# GLFW_DLL_RELEASE - GLFW release DLL on Windows, if found
# GLFW_INCLUDE_DIR - Root include dir
#
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
# 2020, 2021, 2022 Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# GLFW installs cmake package config files which handles dependencies in case
# GLFW is built statically. Try to find first, quietly, so it doesn't print
# loud messages when it's not found, since that's okay. If the glfw target
# already exists, it means we're using it through a CMake subproject -- don't
# attempt to find the package in that case.
if(NOT TARGET glfw)
find_package(glfw3 CONFIG QUIET)
endif()
# If either a glfw config file was found or we have a subproject, point
# GLFW::GLFW to that and exit -- nothing else to do here.
if(TARGET glfw)
if(NOT TARGET GLFW::GLFW)
# Aliases of (global) targets are only supported in CMake 3.11, so we
# work around it by this. This is easier than fetching all possible
# properties (which are impossible to track of) and then attempting to
# rebuild them into a new target.
add_library(GLFW::GLFW INTERFACE IMPORTED)
set_target_properties(GLFW::GLFW PROPERTIES INTERFACE_LINK_LIBRARIES glfw)
endif()
# Just to make FPHSA print some meaningful location, nothing else
get_target_property(_GLFW_INTERFACE_INCLUDE_DIRECTORIES glfw INTERFACE_INCLUDE_DIRECTORIES)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("GLFW" DEFAULT_MSG
_GLFW_INTERFACE_INCLUDE_DIRECTORIES)
if(CORRADE_TARGET_WINDOWS)
# .dll is in LOCATION, .lib is in IMPLIB. Yay, useful!
get_target_property(GLFW_DLL_DEBUG glfw IMPORTED_LOCATION_DEBUG)
get_target_property(GLFW_DLL_RELEASE glfw IMPORTED_LOCATION_RELEASE)
endif()
return()
endif()
if(CORRADE_TARGET_WINDOWS)
if(MSVC)
if(MSVC_VERSION VERSION_LESS 1910)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2015)
elseif(MSVC_VERSION VERSION_LESS 1920)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2017)
elseif(MSVC_VERSION VERSION_LESS 1930)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2019)
elseif(MSVC_VERSION VERSION_LESS 1940)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-vc2022)
else()
message(FATAL_ERROR "Unsupported MSVC version")
endif()
elseif(MINGW)
set(_GLFW_LIBRARY_PATH_SUFFIX lib-mingw-w64)
else()
message(FATAL_ERROR "Unsupported compiler")
endif()
endif()
# In case no config file was found, try manually finding the library. Prefer
# the glfw3dll as it's a dynamic library.
find_library(GLFW_LIBRARY
NAMES glfw glfw3dll glfw3
PATH_SUFFIXES ${_GLFW_LIBRARY_PATH_SUFFIX})
if(CORRADE_TARGET_WINDOWS AND GLFW_LIBRARY MATCHES "glfw3dll.(lib|a)$")
# TODO: debug?
find_file(GLFW_DLL_RELEASE
NAMES glfw3.dll
PATH_SUFFIXES ${_GLFW_LIBRARY_PATH_SUFFIX})
endif()
# Include dir
find_path(GLFW_INCLUDE_DIR
NAMES GLFW/glfw3.h)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("GLFW" DEFAULT_MSG
GLFW_LIBRARY
GLFW_INCLUDE_DIR)
if(NOT TARGET GLFW::GLFW)
add_library(GLFW::GLFW UNKNOWN IMPORTED)
# Work around BUGGY framework support on macOS
# https://cmake.org/Bug/view.php?id=14105
if(CORRADE_TARGET_APPLE AND GLFW_LIBRARY MATCHES "\\.framework$")
set_property(TARGET GLFW::GLFW PROPERTY IMPORTED_LOCATION ${GLFW_LIBRARY}/GLFW)
else()
set_property(TARGET GLFW::GLFW PROPERTY IMPORTED_LOCATION ${GLFW_LIBRARY})
endif()
set_property(TARGET GLFW::GLFW PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${GLFW_INCLUDE_DIR})
endif()
mark_as_advanced(GLFW_LIBRARY GLFW_INCLUDE_DIR)

View File

@ -0,0 +1,4 @@
find_file(libyara.a YARA_LIBRARIES)
find_file(yara.h YARA_INCLUDE_DIRS)
mark_as_advanced(YARA_LIBRARIES YARA_INCLUDE_DIRS)

View File

@ -0,0 +1,41 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# - Try to find Facebook zstd library
# This will define
# ZSTD_FOUND
# ZSTD_INCLUDE_DIR
# ZSTD_LIBRARY
#
find_path(ZSTD_INCLUDE_DIR NAMES zstd.h)
find_library(ZSTD_LIBRARY_DEBUG NAMES zstdd zstd_staticd)
find_library(ZSTD_LIBRARY_RELEASE NAMES zstd zstd_static)
include(SelectLibraryConfigurations)
SELECT_LIBRARY_CONFIGURATIONS(ZSTD)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
ZSTD DEFAULT_MSG
ZSTD_LIBRARY ZSTD_INCLUDE_DIR
)
if (ZSTD_FOUND)
message(STATUS "Found Zstd: ${ZSTD_LIBRARY}")
endif()
mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)

View File

@ -84,13 +84,12 @@ setupCompilerFlags(libimhex)
include(GenerateExportHeader) include(GenerateExportHeader)
generate_export_header(libimhex) generate_export_header(libimhex)
target_include_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIR} ${MAGIC_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${LIBBACKTRACE_INCLUDE_DIRS}) target_include_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIR} ${MAGIC_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${LIBBACKTRACE_INCLUDE_DIRS})
target_link_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${MBEDTLS_LIBRARY_DIR} ${MAGIC_LIBRARY_DIRS}) target_link_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${MBEDTLS_LIBRARY_DIR} ${MAGIC_LIBRARY_DIRS})
if (NOT EMSCRIPTEN) if (NOT EMSCRIPTEN)
# curl is only used in non-emscripten builds # curl is only used in non-emscripten builds
target_include_directories(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${CURL_INCLUDE_DIRS}) target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${CURL_LIBRARIES})
target_link_libraries(libimhex ${LIBIMHEX_LIBRARY_TYPE} ${LIBCURL_LIBRARIES})
endif() endif()

View File

@ -17,16 +17,25 @@ target_link_libraries(imgui_custom PRIVATE imgui_includes)
set_property(TARGET imgui_custom PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET imgui_custom PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories(imgui_all_includes INTERFACE include) target_include_directories(imgui_all_includes INTERFACE include)
find_package(PkgConfig REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED) find_package(Freetype REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
# pkgsearch somehow reports the glfw3 library as glfw3dll in Release builds on MinGW which is not correct find_package(GLFW QUIET)
if (NOT GLFW_FOUND OR "${GLFW_LIBRARIES}" STREQUAL "")
find_package(glfw3 QUIET)
set(GLFW_INCLUDE_DIRS ${glfw3_INCLUDE_DIRS})
set(GLFW_LIBRARIES ${glfw3_LIBRARIES})
if (NOT glfw3_FOUND OR "${GLFW_LIBRARIES}" STREQUAL "")
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
endif ()
endif()
if ("${GLFW_LIBRARIES}" MATCHES ".+dll") if ("${GLFW_LIBRARIES}" MATCHES ".+dll")
set(GLFW_LIBRARIES "glfw3") set(GLFW_LIBRARIES "glfw3")
endif () endif ()
target_include_directories(imgui_custom PUBLIC ${FREETYPE_INCLUDE_DIRS} ${GLFW_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS}) target_include_directories(imgui_custom PUBLIC ${FREETYPE_INCLUDE_DIRS} ${OpenGL_INCLUDE_DIRS})
target_link_directories(imgui_custom PUBLIC ${FREETYPE_LIBRARY_DIRS} ${GLFW_LIBRARY_DIRS} ${OpenGL_LIBRARY_DIRS}) target_link_directories(imgui_custom PUBLIC ${FREETYPE_LIBRARY_DIRS} ${OpenGL_LIBRARY_DIRS})
target_link_libraries(imgui_custom PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES}) target_link_libraries(imgui_custom PUBLIC ${GLFW_LIBRARIES} ${OPENGL_LIBRARIES})

View File

@ -9,11 +9,10 @@ if (NOT USE_SYSTEM_CAPSTONE)
add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/capstone ${CMAKE_CURRENT_BINARY_DIR}/capstone EXCLUDE_FROM_ALL) add_subdirectory(${THIRD_PARTY_LIBS_FOLDER}/capstone ${CMAKE_CURRENT_BINARY_DIR}/capstone EXCLUDE_FROM_ALL)
set_target_properties(capstone PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(capstone PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(capstone PRIVATE -Wno-unused-function) target_compile_options(capstone PRIVATE -Wno-unused-function)
set(CAPSTONE_LIBRARIES "capstone") set(CAPSTONE_LIBRARY "capstone")
set(CAPSTONE_INCLUDE_DIRS ${THIRD_PARTY_LIBS_FOLDER}/capstone/include) set(CAPSTONE_INCLUDE_DIR ${THIRD_PARTY_LIBS_FOLDER}/capstone/include)
else() else()
find_package(PkgConfig REQUIRED) find_package(Capstone REQUIRED)
pkg_search_module(CAPSTONE 4.0.2 REQUIRED capstone)
endif() endif()
add_imhex_plugin( add_imhex_plugin(
@ -27,7 +26,8 @@ add_imhex_plugin(
source/content/pl_visualizers/disassembler.cpp source/content/pl_visualizers/disassembler.cpp
INCLUDES INCLUDES
include include
${CAPSTONE_INCLUDE_DIR}
LIBRARIES LIBRARIES
${CAPSTONE_LIBRARIES} ${CAPSTONE_LIBRARY}
ui ui
) )

View File

@ -7,8 +7,7 @@ if (NOT USE_SYSTEM_MINIAUDIO)
set_target_properties(miniaudio PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(miniaudio PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(MINIAUDIO_LIBRARIES miniaudio) set(MINIAUDIO_LIBRARIES miniaudio)
else() else()
find_package(PkgConfig REQUIRED) find_package(miniaudio REQUIRED)
pkg_check_modules(miniaudio REQUIRED IMPORTED_TARGET miniaudio)
endif() endif()
add_imhex_plugin( add_imhex_plugin(

View File

@ -7,8 +7,7 @@ if (NOT USE_SYSTEM_YARA)
set_target_properties(libyara PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(libyara PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(YARA_LIBRARIES libyara) set(YARA_LIBRARIES libyara)
else() else()
find_package(PkgConfig REQUIRED) find_package(Yara REQUIRED)
pkg_check_modules(YARA REQUIRED IMPORTED_TARGET yara)
endif() endif()
add_imhex_plugin( add_imhex_plugin(