linux下使用cmake编译代码

1、安装cmake
yum install -y gcc gcc-c++ make automake
yum install cmake
2、cmake配置文件
1)编写代码根目录下的CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -rdynamic -Wno-deprecated -pg  -lmysqlcppconn -lcurl -luuid -
lutil -lpthread -lboost_thread -lboost_system  -lrt -ftest-coverage -fprofile-arcs -lssl  -lcrypto")
#set(SERVERX_INCLUDE_DIR "" CACHE FILEPATH "Path to casablanca include dir")
#include_directories (
#include
#"${SERVERX_INCLUDE_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
INCLUDE_DIRECTORIES(include)
add_subdirectory(src/common/tinyxml)
find_package(Boost COMPONENTS system REQUIRED)
find_package(OpenSSL REQUIRED)
SET(DIR_SRCS src/communication/server.cpp)  
ADD_EXECUTABLE(ServerX ${DIR_SRCS})       
target_link_libraries(ServerX ${Boost_SYSTEM_LIBRARY} ${OPENSSL_LIBRARIES})
target_link_libraries(ServerX tinyxml)
2)src/common/tinyxml下的CMakeLists.txt:
set (SOURCES_FILES  
    tinystr.cpp  
    tinyxml.cpp  
    tinyxmlerror.cpp  
    tinyxmlparser.cpp)
include_directories(../../../include)
ADD_LIBRARY(tinyxml STATIC ${SOURCES_FILES})
3、编译
1)工程根目录下 mkdir build.release
2)cd build.release
3)CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Release
4)make

你可能感兴趣的:(linux,C++)