cmake 编译 01

zhoulujun

关注

阅读 11

2024-11-03


cmake 编译 01_子目录

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(MyProject)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 如果顶层 CMakeLists.txt 文件中使用了 add_subdirectory() 命令,CMake 会进入指定的子目录,并处理该目录中的 CMakeLists.txt 文件
add_subdirectory(src/math)

add_executable(MyProject src/main.cpp)

target_link_libraries(MyProject PRIVATE MathLibrary)

math/CMakeLists.txt

add_library(MathLibrary add.cpp)

target_include_directories(MathLibrary PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

cd build
cmake ..
cmake build .  
# or 
cmake build . --config Release


精彩评论(0)

0 0 举报