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})