CMake Help
系列基于CMake Tutorial
本文基于Step 3: Adding Usage Requirements for a Library
Adding Usage Requirements for a Library
使用INTERFACE
修改library/CMakeLists.txt
1 | # 为静态库MathFunctions库添加文件mySqrt.cpp |
修改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。
1 | if(USE_MYMATH) |
以及
1 | target_include_directories(target1 PUBLIC |
这里我们无需额外告知库的头文件的位置了,我们把关于EXTRA_INCLUDES
都删除了。
Notice that with this technique, the only thing our executable target does to use our library is call target_link_libraries() with the name of the library target. In larger projects, the classic method of specifying library dependencies manually becomes very complicated very quickly.