CMake中使用常用C++库

下面给出的配置包含了loki,boost,boost logging,mongodb driver,cppdb等。


boost库在Ubuntu12.04下需要执行下面的安装命令:

apt-get install libboost-1.48-all-dev
apt-get install libboost-thread1.48-dev
apt-get install libboost-regex1.48-dev
apt-get install libboost-filesystem1.48-dev

cmake_minimum_required(VERSION 2.8)

set(Loki_HOME /usr/local/src/loki-0.1.7)
set(Loki_INCLUDE_DIR ${Loki_HOME}/include)
set(Loki_LIBRARY_DIR ${Loki_HOME}/lib)
set(Loki_LIBRARY ${Loki_HOME}/lib/libloki.so.0.1.7)

set(CPPDB_INCLUDE_DIR /usr/include/cppdb)
set(CPPDB_LIBRARY_DIR /usr/lib/)
set(CPPDB_LIBRARY /usr/lib/libcppdb.so)

set(PROJECT_INCLUDE_DIR /home/chenshu/work/CommonService/trunk/BatchService/include)
set(PROJECT_SOURCE_DIR /home/chenshu/work/CommonService/trunk/BatchService/src)

set(MONGODB_INCLUDE_DIR /usr/local/src/mongo-cxx-driver-v1.8/mongo)

add_definitions(-DBOOST_FILESYSTEM_VERSION=2)

find_package (Threads)
find_package(Boost COMPONENTS system filesystem thread log program_options REQUIRED)
message("--------------------------------------------")
message(${Boost_HOME})
message(${Loki_HOME})
message(${MONGODB_INCLUDE_DIR})
message("--------------------------------------------")
include_directories(${Boost_INCLUDE_DIR} ${Loki_INCLUDE_DIR} ${CPPDB_INCLUDE_DIR} ${PROJECT_INCLUDE_DIR} ${MONGODB_INCLUDE_DIR})

link_directories(${Loki_LIBRARY_DIR} ${CPPDB_LIBRARY_DIR})

add_executable(main ThreadFunction.cpp Application.cpp SqlSessionFactory.cpp VillageService.cpp ThreadManager.cpp main.cpp)
target_link_libraries(main mongoclient ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${Loki_LIBRARY} ${CPPDB_LIBRARY} )


你可能感兴趣的:(CMake中使用常用C++库)