Extend cmake config files with deps, version, etc. (#2916)

This improves how the installed CutterConfig.cmake can be used for
native plugin development:
* Transitive dependencies are resolved automatically
* Version file is included
* Cutter_USER_PLUGINDIR is set to a path that plugins can use as a
  default install destination

src/plugins/sample-cpp/CMakeLists.txt is an example for how to use it.
Rizin was also updated to prevent an error with multiple
`find_package()` calls.
This commit is contained in:
Florian Märkl 2022-03-31 12:49:37 +02:00 committed by GitHub
parent 5e8aa4f993
commit 62d75c9391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 79 additions and 38 deletions

View File

@ -57,16 +57,14 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(QT_COMPONENTS Core Widgets Gui Svg Network)
if (CUTTER_QT6)
set(QT_PREFIX Qt6)
list(APPEND QT_COMPONENTS Core5Compat SvgWidgets OpenGLWidgets)
else()
set(QT_PREFIX Qt5)
endif()
find_package(${QT_PREFIX} REQUIRED COMPONENTS Core Widgets Gui Svg Network)
if (CUTTER_QT6)
find_package(${QT_PREFIX} REQUIRED COMPONENTS Core5Compat SvgWidgets OpenGLWidgets)
endif()
find_package(${QT_PREFIX} REQUIRED COMPONENTS ${QT_COMPONENTS})
if(CUTTER_ENABLE_PYTHON)
find_package(PythonInterp REQUIRED)

View File

@ -57,7 +57,8 @@ target_link_libraries(Rizin INTERFACE
${RZ_LIBS})
target_include_directories(Rizin INTERFACE
"$<BUILD_INTERFACE:${Rizin_INCLUDE_DIRS}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/librz>")
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/librz>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/librz/sdb>")
install(TARGETS Rizin EXPORT CutterTargets)
if (WIN32)

View File

@ -1 +0,0 @@
include("${CMAKE_CURRENT_LIST_DIR}/CutterTargets.cmake")

View File

@ -0,0 +1,22 @@
@PACKAGE_INIT@
set(Cutter_RIZIN_BUNDLED @CUTTER_USE_BUNDLED_RIZIN@)
include(CMakeFindDependencyMacro)
find_dependency(@QT_PREFIX@ COMPONENTS @QT_COMPONENTS@)
find_dependency(Rizin COMPONENTS Core)
# Make a best guess for a user location from where plugins can be loaded.
# This can be used in Cutter plugins like
# set(CUTTER_INSTALL_PLUGDIR "${Cutter_USER_PLUGINDIR}" CACHE STRING "Directory to install Cutter plugin into")
# see https://doc.qt.io/qt-5/qstandardpaths.html under AppDataLocation
if(APPLE)
set(Cutter_USER_PLUGINDIR "$ENV{HOME}/Library/Application Support/rizin/cutter/plugins/native")
elseif(WIN32)
file(TO_CMAKE_PATH "$ENV{APPDATA}" Cutter_USER_PLUGINDIR)
set(Cutter_USER_PLUGINDIR "${Cutter_USER_PLUGINDIR}/rizin/cutter/plugins/native")
else()
set(Cutter_USER_PLUGINDIR "$ENV{HOME}/.local/share/rizin/cutter/plugins/native")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/CutterTargets.cmake")

View File

@ -20,4 +20,4 @@ else()
include(GNUInstallDirs)
set(CUTTER_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}/${CUTTER_DIR_NAME}" CACHE PATH "Resource installation directory")
endif()
set(ConfigPackageLocation "${CMAKE_INSTALL_LIBDIR}/Cutter" CACHE PATH "Cmake file install location")
set(CUTTER_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Cutter" CACHE PATH "CMake file install location")

2
rizin

@ -1 +1 @@
Subproject commit dd81b6629a45ec3d221042ed9729b50cd3c478c5
Subproject commit be48ddcd9f0c2023d0e64750426c0476a13d8589

View File

@ -558,17 +558,26 @@ install(TARGETS Cutter
EXPORT CutterTargets
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
BUNDLE DESTINATION "." # needs to be tested
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT Devel
)
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT Devel)
install(EXPORT CutterTargets
NAMESPACE Cutter::
DESTINATION "${ConfigPackageLocation}"
DESTINATION "${CUTTER_INSTALL_CONFIGDIR}"
COMPONENT Devel)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CutterConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CutterConfig.cmake"
INSTALL_DESTINATION "${CUTTER_INSTALL_CONFIGDIR}"
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CutterConfigVersion.cmake"
VERSION "${CUTTER_VERSION_FULL}"
COMPATIBILITY AnyNewerVersion)
install(FILES
../cmake/CutterConfig.cmake
DESTINATION ${ConfigPackageLocation}
COMPONENT Devel
)
"${CMAKE_CURRENT_BINARY_DIR}/CutterConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CutterConfigVersion.cmake"
DESTINATION ${CUTTER_INSTALL_CONFIGDIR}
COMPONENT Devel)
foreach(_file ${HEADER_FILES})
# Can't use target PUBLIC_HEADER option for installing due to multiple directories
get_filename_component(_header_dir "${_file}" DIRECTORY)
@ -576,8 +585,8 @@ foreach(_file ${HEADER_FILES})
endforeach()
if(UNIX AND NOT APPLE)
install (FILES "img/cutter.svg"
DESTINATION "share/icons/hicolor/scalable/apps/")
install(FILES "img/cutter.svg"
DESTINATION "share/icons/hicolor/scalable/apps/")
install(FILES "re.rizin.cutter.desktop"
DESTINATION "share/applications"
COMPONENT Devel)

View File

@ -14,6 +14,8 @@
* @brief Attempt to connect to a parent console and configure outputs.
*/
#ifdef Q_OS_WIN
#include <windows.h>
static void connectToConsole()
{
BOOL attached = AttachConsole(ATTACH_PARENT_PROCESS);

View File

@ -60,7 +60,7 @@ namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
class CUTTER_EXPORT MainWindow : public QMainWindow
{
Q_OBJECT

View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.12)
project(cutter-sample-plugin)
find_package(Cutter REQUIRED)
set(CUTTER_INSTALL_PLUGDIR "${Cutter_USER_PLUGINDIR}" CACHE STRING "Directory to install Cutter plugin into")
set(CMAKE_AUTOMOC ON)
add_library(sample_plugin MODULE
CutterSamplePlugin.h
CutterSamplePlugin.cpp)
target_link_libraries(sample_plugin PRIVATE Cutter::Cutter)
install(TARGETS sample_plugin DESTINATION "${CUTTER_INSTALL_PLUGDIR}")

View File

@ -4,9 +4,10 @@
#include <QAction>
#include "CutterSamplePlugin.h"
#include "common/TempConfig.h"
#include "common/Configuration.h"
#include "MainWindow.h"
#include <common/TempConfig.h>
#include <common/Configuration.h>
#include <MainWindow.h>
void CutterSamplePlugin::setupPlugin() {}
@ -56,9 +57,14 @@ void CutterSamplePluginWidget::on_seekChanged(RVA addr)
void CutterSamplePluginWidget::on_buttonClicked()
{
QString fortune = Core()->cmd("fo").replace("\n", "");
RzCoreLocked core(Core());
char *fortune = rz_core_fortune_get_random(core);
if (!fortune) {
return;
}
// cmdRaw can be used to execute single raw commands
// this is especially good for user-controlled input
QString res = Core()->cmdRaw("?E " + fortune);
QString res = Core()->cmdRaw("?E " + QString::fromUtf8(fortune));
text->setText(res);
rz_mem_free(fortune);
}

View File

@ -1,9 +1,9 @@
#ifndef CUTTERSAMPLEPLUGIN_H
#define CUTTERSAMPLEPLUGIN_H
#include <QObject>
#include <QtPlugin>
#include "CutterPlugin.h"
#include <CutterPlugin.h>
#include <QLabel>
class CutterSamplePlugin : public QObject, CutterPlugin
{
@ -26,7 +26,7 @@ class CutterSamplePluginWidget : public CutterDockWidget
Q_OBJECT
public:
explicit CutterSamplePluginWidget(MainWindow *main, QAction *action);
explicit CutterSamplePluginWidget(MainWindow *main);
private:
QLabel *text;

View File

@ -1,10 +0,0 @@
HEADERS += ../CutterSamplePlugin.h ../CutterPlugin.h
INCLUDEPATH += ../ ../../ ../../core ../../widgets
SOURCES += CutterSamplePlugin.cpp
QMAKE_CXXFLAGS += $$system("pkg-config --cflags rz_core")
TEMPLATE = lib
CONFIG += plugin
QT += widgets
TARGET = PluginSample

View File

@ -17,6 +17,7 @@
#include "WidgetShortcuts.h"
#ifdef Q_OS_WIN
# include <windows.h>
# include <io.h>
# define dup2 _dup2
# define dup _dup