cmake笔记

cmake总是接触但是不精通,记录一些以便以后用到时参考。

CC = gcc
all:

        $(CC) mainloop1.c -o mainloop1 `pkg-config --cflags --libs glib-2.0`

g_main_loop_new ()

GMainLoop *g_main_loop_new (GMainContext*context,gboolean is_running);

Creates a new GMainLoop structure.

Parameters

context    aGMainContext (if NULL, the default context will be used).         [allow-none]

is_running        setto TRUE to indicate that the loop is running. This is not very important sincecalling g_main_loop_run() will set this to TRUE anyway.

Returns

a new GMainLoop.

g_main_loop_run ()

void g_main_loop_run (GMainLoop *loop);

Runs a main loop until g_main_loop_quit()is called on the loop. If this is called for the thread of the loop'sGMainContext, it will process events from the loop, otherwise it will simplywait.

Parameters

loop aGMainLoop

g_main_loop_unref ()

void g_main_loop_unref (GMainLoop *loop);

Decreases the reference count on aGMainLoop object by one. If the result is zero, free the loop and free allassociated memory.

Parameters

Loop          aGMainLoop

g_main_loop_quit ()

void g_main_loop_quit (GMainLoop *loop);

Stops a GMainLoop from running. Any callsto g_main_loop_run() for the loop will return.

Note that sources that have already beendispatched when g_main_loop_quit() is called will still be executed.

Parameters

loop aGMainLoop

#include <glib.h>

#include <stdio.h>

#include <time.h>

GMainLoop *loop;

time_t start, end;

gboolean callback(gpointer arg)

{

       g_print("callback is called.\n");

       g_main_loop_quit(loop);

       return FALSE;

}

int main(int argc, char *argv[])

{

       g_print("g_main_loop_new\n");

       loop = g_main_loop_new(NULL, FALSE);

       g_timeout_add(3000, callback, NULL);

       g_print("g_main_loop_run\n");

       start = time(NULL);

       g_main_loop_run(loop);

       end = time(NULL);

       double totalT = difftime(end, start);

       g_print("g_main_loop_unref:%f\n", totalT);

       g_main_loop_unref(loop);

       return 0;

}

-----------------------------------

cmake_minimum_required(VERSION 2.8.9)
project (hello)

#find_package(PkgConfig)
include(FindPkgConfig)
pkg_check_modules(HelloLoop REQUIRED
        glib-2.0
)
if (HelloLoop_FOUND)
        message(${HelloLoop_INCLUDE_DIRS})
        include_directories(${HelloLoop_INCLUDE_DIRS})
        message(${HelloLoop_LIBRARIES})
endif(HelloLoop_FOUND)
set( EXTRA_CFLAGS "${EXTRA_CFLAGS} --cflag --libs")

add_executable(hello mainloop1.c)
target_link_libraries (
        hello
        ${HelloLoop_LIBRARIES}
)

#       pkg-config --cflags --libs glib-2.0
#add_executable(hello mainloop1.c)

---------------------------------------

cmake_minimum_required(VERSION 2.8.9)
project (mainloop)

find_package(PkgConfig)
#include(FindPkgConfig)
pkg_check_modules(HelloLoop REQUIRED
        glib-2.0
)
if (HelloLoop_FOUND)
        message("--------------"${HelloLoop_INCLUDE_DIRS})
        include_directories(${HelloLoop_INCLUDE_DIRS})
        message(${HelloLoop_LIBRARIES})
endif(HelloLoop_FOUND)


#set( EXTRA_CFLAGS "${EXTRA_CFLAGS} --cflag --libs")

add_executable( mainloop1 mainloop1.c)
target_link_libraries (
        mainloop1
        ${HelloLoop_LIBRARIES}
)

#       pkg-config --cflags --libs glib-2.0
#add_executable(hello mainloop1.c)

--------------------------------------------------


cmake_minimum_required(VERSION 2.8.9)
project (mainloop)

find_package(PkgConfig)
#include(FindPkgConfig)

pkg_check_modules(HelloLoop glib-2.0)

if (HelloLoop_FOUND)
        message("--------------"${HelloLoop_INCLUDE_DIRS})
        include_directories(${HelloLoop_INCLUDE_DIRS})
        message("--------------"${HelloLoop_LIBRARIES})
endif(HelloLoop_FOUND)


#set( EXTRA_CFLAGS "${EXTRA_CFLAGS} --cflag --libs")

add_executable( mainloop1 mainloop1.c)
target_link_libraries (
        mainloop1
        ${HelloLoop_LIBRARIES}
)

#       pkg-config --cflags --libs glib-2.0
#add_executable(hello mainloop1.c)

cmake_minimum_required(VERSION 3.5)

project(ThreadPool LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pthread")
# Import Threads
message(STATUS "Importing Threads")
find_package(Threads REQUIRED)
message(STATUS "    Package Threads found: ${Threads_FOUND}")

add_executable(ThreadPool main.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/CTPL)

install(TARGETS ThreadPool
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值