更新时间:2021-12-12 02:52:59
您需要使用CMake目标及其属性:
You need to make use of the CMake targets and their properties:
MainProj / CMakeLists.txt:
MainProj/CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(MainProj)
# Add sub-directories
add_subdirectory(ProjLib)
add_subdirectory(ProjExec)
b $ b
ProjLib / CMakeLists.txt
ProjLib/CMakeLists.txt
add_library(ProjLib SHARED src/proj_lib.cc)
target_include_directories(ProjLib PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
ProjExec / CMakeLists.txt
ProjExec/CMakeLists.txt
add_executable(ProjExec src/proj_exec.cc)
target_include_directories(ProjExec PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(ProjExec ProjLib)
target_link_libraries
目标,其依赖项的PUBLIC和INTERFACE包括目录将被适当地使用。
target_link_libraries
makes sure that when building a target, its dependencies' PUBLIC and INTERFACE include directories will be used appropriately.