cmake_minimum_required (VERSION 2.6) set(myname wecho) project(${myname}) set(LIB_NAMES pthread) set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(NET_DIR ${SRC_DIR}/net) set(NET_SRC ${NET_DIR}/CBaseSocket.cpp ${NET_DIR}/CEpollServer.cpp ${NET_DIR}/CHostAddress.cpp ${NET_DIR}/CTcpServer.cpp ${NET_DIR}/CUdpServer.cpp ${NET_DIR}/CConnection.cpp) set(APP_DIR ${SRC_DIR}/app) set(APP_SRC ${APP_DIR}/CApp.cpp) set(source_files ${SRC_DIR}/main.cpp ${NET_SRC} ${APP_SRC}) set(source_dir ${SRC_DIR}/../ ${SRC_DIR} ${NET_DIR} ${APP_DIR}) set(CMAKE_SYSTEM_NAME Linux) add_definitions(-std=gnu++11) #这种操作报的警告,似乎添加这个无效,因为不是C++编译器?*one=GROUP__INIT; set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-gc-sections") include_directories(${source_dir} ${MYSQL_LIB}) add_executable(${myname} ${source_files}) target_link_libraries(${myname} ${LIB_NAMES})