多目录工程 - 直接编译
目录结构
CMakeLists.txt
# Set the minimum version of CMake that can be used
cmake_minimum_required(VERSION 3.0)
#project name
project(SWAP)
#head file pat
include_directories(include)
#add executable file
add_executable(main_cmake main.cpp src/swap.cpp)
vim CMakeLists.txt
#外部构建
mkdir build
cd build
cmake ..
make
./main_cmake
【实战】使用VSCode进行完整项目开发
目录结构
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(SOLDIERFIRE)
#g++ -g main.cpp src/Gun.cpp src/Soldier.cpp -o my_cmake_exe -g -O2 -Wall
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -Wall")
include_directories(${CMAKE_SOURCE_DIR}/include)
add_executable(my_cmake_exe main.cpp src/Gun.cpp src/Soldier.cpp)
VSCode 远程连接linux,运行结果