1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| cmake_minimum_required(VERSION 3.15.0) project(My_Project)
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -Werror -Wextra -pedantic -std=c++14") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -std=c++14 -O2")
add_executable(demo demo.cpp) add_library(common STATIC util1.cpp) add_library(common SHARED util2.cpp util3.cpp)
file(GLOB SRC_LIST "*.cpp" "protocal/*.cpp") add_library(demo ${SRC_LIST})
set(SRC_LIST main.cpp test.cpp) list(APPEND SRC_LIST test2.cpp) list(REMOVE_ITEM SRC_LIST test2.cpp)
aux_source_directory(. SRC_LIST) aux_source_directory(protocol SRC_PROTOCOL_LIST) add_library(demo ${SRC_LIST} ${SRC_PROTOCOL_LIST})
foreach(source ${srcs}) get_filename_component(name ${source} NAME/EXT/DIRECTORY/ABSOLUTE) add_executable(${name} ${source}) endforeach(source)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I ${CMAKE_CURRENT_SOURCE_DIR}") link_libraries("/include/util.so")
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_CURRENT_SOURCE_DIR}/libs")
find_package(Protobuf REQUIRED) target_link_libraries(demo lib.a ${CMAKE_CURRENT_SOURCE_DIR}/libs/lib.so)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/proto) include_directories(${PROJECT_BINARY_DIR}/src/proto)
message(${PROJECT_SOURCE_DIR}) message("build with debug mode") message(WARNING "this is warnning message") message(FATAL_ERROR "this build has many error")
|