可以带这些用法的有如下函数:
以target_include_directories()的INTERFACE用法为例,
将上一文章中的MathFunctions库为例,
MathFunctions文件夹中的CMakeLists.txt与文件夹外的CMakeLists.txt变化如下,
- 文件夹内CMakeLists.txt
add_library(MathFunctions mysqrt.cxx)
target_include_directories(MathFunctions
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)
- 文件夹外CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
#set the project name and version
project(Tutorial VERSION 1.0)
#specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(USE_MYMATH "Use tutorial provided math implementation" ON)
configure_file(TutorialConfig.h.in TutorialConfig.h)
if(USE_MYMATH)
#add the MathFunctions Library
add_subdirectory(MathFunctions)
list(APPEND EXTRA_LIBS MathFunctions)
endif()
#add the executable
add_executable(Tutorial tutorial.cxx)
target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
)