-
更好的操作一个库或可执行的链接文件
target_compile_definitions(<target> <INTERFACE|PUBLIC|PRIVATE> [items1...] [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
Specifies compile definitions to use when compiling a given <target>
. The named <target>
must have been created by a command such as add_executable()
or add_library()
and must not be an ALIAS target.
名字要和上面两个命令里面指定的一致!
让我们用现代的CMake,对第二章节的代码进行重构
Remember INTERFACE
means things that consumers require but the producer doesn't.
这句话有点设计模式的味道,不翻译。下面是cmake.org的源代码
Add the following lines to the end of MathFunctions/CMakeLists.txt
:
修改MathFunctions目录下的CMakeLists.txt
target_include_directories(MathFunctions
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
)
Lesson03实际工程代码长这样
同样修改TopLevel的CMakeLists.txt
# Now that we've specified usage requirements for MathFunctions we can safely remove our uses of the EXTRA_INCLUDES variable from the top-level CMakeLists.txt, here:
if(USE_MYMATH)
add_subdirectory(MathFunctions)
list(APPEND EXTRA_LIBS MathFunctions)
endif()
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
)
下面是我实际工程的代码
全部再次编译
再用tree .查看
代码又演进了一步。