cmake可见性和AppArmor示例
This commit is contained in:
parent
0eeb4a7bb6
commit
4b4b933e3d
19 changed files with 661 additions and 0 deletions
35
cmake/visibility/CMakeLists.txt
Normal file
35
cmake/visibility/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(visibility_demo CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# ============ color ============
|
||||
add_library(color
|
||||
color/src/color.cpp
|
||||
color/src/rgb_convert.cpp
|
||||
)
|
||||
target_include_directories(color
|
||||
PUBLIC color/public # 对外头目录:用户由此 #include <color/color.h>
|
||||
PRIVATE color/include # 内部头目录:rgb_convert.h 只有 color 自己可见
|
||||
)
|
||||
# 宏出现在公开头文件的 #ifdef 里,决定 API 形状。
|
||||
# 若只标 PRIVATE:color.cpp 编译出了 brightColorCode,
|
||||
# 但用户看到的头文件里该声明被预处理掉 → 库和用户对 API 的理解不一致。
|
||||
target_compile_definitions(color PUBLIC COLOR_ENABLE_BRIGHT)
|
||||
|
||||
# ============ timeutil ============
|
||||
add_library(timeutil timeutil/timeutil.cpp)
|
||||
target_include_directories(timeutil PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/timeutil)
|
||||
|
||||
# ============ printer ============
|
||||
add_library(printer printer/src/printer.cpp)
|
||||
target_include_directories(printer PUBLIC printer/public)
|
||||
target_link_libraries(printer
|
||||
PUBLIC color # printer.h 引用了 color/color.h → 契约的一部分
|
||||
PRIVATE timeutil # 只有 printer.cpp 用 → 实现细节
|
||||
)
|
||||
# 时间格式只影响 printer.cpp 的编译 → PRIVATE,不泄漏、改格式不触发下游重编
|
||||
target_compile_definitions(printer PRIVATE "PRINTER_TIME_FORMAT=\"%H:%M:%S\"")
|
||||
|
||||
# ============ app ============
|
||||
add_executable(app app/main.cpp)
|
||||
target_link_libraries(app PRIVATE printer)
|
||||
Loading…
Add table
Add a link
Reference in a new issue