linux下使用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