如何通过以下make和pkg-config使clion工作? [英] How do I make clion work with following make and pkg-config?

查看:140
本文介绍了如何通过以下make和pkg-config使clion工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的C程序,它通知我Xfce在哪个工作区上.我可以成功地编译它并与命令一起使用

I have following simple C program which notifies me on which workspace I am in Xfce. I can successfully compile it and use it with a command

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wsnd pkg-config --cflags --libs libnotify --libs libwnck-1.0 wsn.c

但是我将如何设置Cmake配置文件,以便clion也可以对其进行编译?如何在Cmake中使用pkg-config?

But how would I set Cmake configuration file so clion would compile it also? How do I use pkg-config with Cmake?

#include <libnotify/notify.h>
#include <libwnck-3.0/libwnck/libwnck.h>

#define N_SUMMARY "Workspace Changed"
#define N_ICON    "dialog-information"
#define N_APPNAME "workspace switch notifier"
#define N_TIMEOUT 2000 /*2000ms = 2s */

static NotifyNotification * m_notification = NULL;

static void
on_active_workspace_changed (WnckScreen    *screen,
                             WnckWorkspace *space,
                             gpointer      data)
{

    WnckWorkspace * active_workspace = wnck_screen_get_active_workspace(screen);
    const char * w_name = wnck_workspace_get_name (active_workspace);

    notify_notification_update(m_notification, N_SUMMARY, w_name, N_ICON);
    notify_notification_show(m_notification, NULL);
}

int main(int argc, char ** argv)
{

    GMainLoop *loop;
    WnckScreen *screen;

    if (notify_init(N_APPNAME))
        m_notification = notify_notification_new(N_SUMMARY, "" , N_ICON);
    else
        fprintf(stderr, "Failed to init notifications\n");
    notify_notification_set_timeout(m_notification, N_TIMEOUT);

    gdk_init (&argc, &argv);

    loop = g_main_loop_new (NULL, FALSE);
    screen = wnck_screen_get_default();

    g_signal_connect (screen, "active-workspace-changed",
                      G_CALLBACK (on_active_workspace_changed), NULL);

    g_main_loop_run (loop);

    g_main_loop_unref (loop);

    return 0;
}

推荐答案

按照CMakeLists.txt进行配置即可.我现在也可以在源代码中跟踪函数调用.

Following CMakeLists.txt configuration made it work. I can follow function calls in source code now also.

cmake_minimum_required(VERSION 3.12)
project(xfce_workspace_notifier C)
add_compile_definitions(WNCK_I_KNOW_THIS_IS_UNSTABLE)

set(CMAKE_C_STANDARD 99)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIB_NOTIFY REQUIRED libnotify)
pkg_check_modules(LIB_WNCK1 REQUIRED libwnck-1.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0)

file(GLOB SRC "main.c")
add_executable(xfce_workspace_notifier ${SRC})

target_link_libraries(xfce_workspace_notifier PUBLIC ${GLIB_LIBRARIES})
target_include_directories(xfce_workspace_notifier PUBLIC ${GLIB_INCLUDE_DIRS})

target_link_libraries(xfce_workspace_notifier PUBLIC ${WNCK_LIBRARIES})
target_include_directories(xfce_workspace_notifier PUBLIC ${WNCK_INCLUDE_DIRS})

target_link_libraries(xfce_workspace_notifier PUBLIC ${NOTIFY_LIBRARIES})
target_include_directories(xfce_workspace_notifier PUBLIC ${NOTIFY_INCLUDE_DIRS})

这篇关于如何通过以下make和pkg-config使clion工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆