cmake的版本号说明:
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
# 指定编译 C++ 版本
set(CMAKE_CXX_STANDARD 17)
创建一个工程:
project(preprocess)
工程下创建一个项目:
SET(PROGRAM WorkStation)
include路径:
set (INCLUDE_PATH_common ${CMAKE_SOURCE_DIR}/common)
set (INCLUDE_PATH_MQ ${CMAKE_SOURCE_DIR}/rabbitmq-c)
set (INCLUDE_PATH_JSON ${CMAKE_SOURCE_DIR}/jsonDeal/rapidjson)
set (INCLUDE_PATH_LIB ${CMAKE_SOURCE_DIR}/libs)include_directories(${INCLUDE_PATH_common}${INCLUDE_PATH_MQ}${INCLUDE_PATH_JSON}${Boost_INCLUDE_DIRS}${GLOG_INCLUDE_DIRS})
附加库目录路径:备注:这个要在add_executable之前
link_directories(${Boost_LIBRARY_DIRS})
添加cpp文件:
set(${PROGRAM}_Src ${CMAKE_SOURCE_DIR}/common/utils.c${CMAKE_SOURCE_DIR}/cJSON.c${CMAKE_SOURCE_DIR}/rabbitmqConsumerTopic.cpp
)
add_executable(${PROGRAM} ${${PROGRAM}_Src})
链接到动态库,添加lib,vs工程属性里的附加依赖项:
target_link_libraries(${PROGRAM}
${INCLUDE_PATH_LIB}/librabbitmq.4.lib
${INCLUDE_PATH_LIB}/rabbitmq.4.lib
${Boost_LIBRARIES}
${GLOG_LIBRARIES}
)
集成boost、glog:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")#文件夹下有Findglog文件find_package(Boost REQUIRED)
message("Boost_FOUND , Boost_INCLUDE_DIRS:${Boost_INCLUDE_DIRS}")
message("Boost_FOUND , Boost_LIBRARY_DIRS:${Boost_LIBRARY_DIRS}")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")else()set(Boost_LIBRARIES"-lboost_system -lboost_filesystem -lboost_date_time -lpthread")
endif()
message("Boost_LIBRARIES is ${Boost_LIBRARIES}")find_package(glog REQUIRED)
if(GLOG_FOUND)message("GLOG_FOUND ... GLOG_LIBRARIES is ${GLOG_LIBRARIES} ,GLOG_INCLUDE_DIRS is ${GLOG_INCLUDE_DIRS},")add_definitions(-DUSE_GLOG=ON)add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES -DGOOGLE_GLOG_DLL_DECL=)
else()message("GLOG_NOT_FOUND ...")
endif()