Skip to content

Commit

Permalink
chore: update cmake usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Groveer committed Feb 6, 2024
1 parent 529f7c2 commit f7d7000
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/blog/cmake-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ endif()
# 若目标库安装了.cmake文件,则可以直接使用find_package
#find_package(PkgConfig REQUIRED)
# 若目标库未安装.cmake文件,但是安装了.pc文件,则可以使用pkgconfig
#pkg_search_module(XCB REQUIRED xcb)
#pkg_check_modules(PolkitQt REQUIRED IMPORTED_TARGET polkit-qt5-1)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
Expand Down Expand Up @@ -129,10 +129,12 @@ set_target_properties(${LIB_NAME} PROPERTIES
# Qt 从5.15版本开始,可以直接使用Qt::Core,而不需要加版本号,但为了兼容性,把版本号加上为好
target_include_directories(${BIN_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
#PkgConfig::PolkitQt
)
target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
#PkgConfig::PolkitQt
)
# 指定安装目录,一般常用有3个: TARGETS(编译出来的目标二进制)、FILES(指定路径的文件,通常是配置文件或服务文件)、DIRECTORY(一般是配置文件较多时使用)。
Expand Down
8 changes: 6 additions & 2 deletions docs/blog/cmake-basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ endif()
# 若目标库安装了.cmake文件,则可以直接使用find_package
#find_package(PkgConfig REQUIRED)
# 若目标库未安装.cmake文件,但是安装了.pc文件,则可以使用pkgconfig
#pkg_search_module(XCB REQUIRED xcb)
#pkg_check_modules(PolkitQt REQUIRED IMPORTED_TARGET polkit-qt5-1)
# 建议对不同的模块进行分类,可使用通配符,可指定具名文件
file(GLOB_RECURSE SRCS
Expand All @@ -94,9 +94,11 @@ add_executable(${BIN_NAME}
# )
target_include_directories(${BIN_NAME} PUBLIC
#PkgConfig::PolkitQt
)
target_link_libraries(${BIN_NAME} PRIVATE
#PkgConfig::PolkitQt
)
# 指定安装目录,一般常用有3个: TARGETS(编译出来的目标二进制)、FILES(指定路径的文件,通常是配置文件或服务文件)、DIRECTORY(一般是配置文件较多时使用)。
Expand Down Expand Up @@ -175,7 +177,7 @@ endif()
# 若目标库安装了.cmake文件,则可以直接使用find_package
#find_package(PkgConfig REQUIRED)
# 若目标库未安装.cmake文件,但是安装了.pc文件,则可以使用pkgconfig
#pkg_search_module(XCB REQUIRED xcb)
#pkg_check_modules(PolkitQt REQUIRED IMPORTED_TARGET polkit-qt5-1)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
Expand All @@ -201,10 +203,12 @@ add_executable(${BIN_NAME}
# Qt 从5.15版本开始,可以直接使用Qt::Core,而不需要加版本号,但为了兼容性,把版本号加上为好
target_include_directories(${BIN_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
#PkgConfig::PolkitQt
)
target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
#PkgConfig::PolkitQt
)
# 指定安装目录,一般常用有3个: TARGETS(编译出来的目标二进制)、FILES(指定路径的文件,通常是配置文件或服务文件)、DIRECTORY(一般是配置文件较多时使用)。
Expand Down

0 comments on commit f7d7000

Please sign in to comment.