UsewxWidgets¶
该模块调用 include_directories()
和 link_directories()
,为当前目录设置编译定义,并在调用 find_package(wxWidgets)
后添加一些编译标志以使用 wxWidgets 库。
示例¶
在项目的 CMakeLists.txt
中包含 UsewxWidgets
模块
# Note that for MinGW users the order of libraries is important.
find_package(wxWidgets REQUIRED net gl core base)
# Above also sets the wxWidgets_USE_FILE variable that points to this module.
include(${wxWidgets_USE_FILE})
# Link wxWidgets libraries for each dependent executable/library target.
target_link_libraries(<ProjectTarget> ${wxWidgets_LIBRARIES})
从 CMake 3.27 开始,更好的方法是仅将 wxWidgets::wxWidgets
IMPORTED
目标链接到需要它的特定目标,而不是包含此模块。导入的目标通过仅将其应用于链接到的目标,从而避免不必要地传播到当前目录中的所有目标,从而更好地控制包使用属性,例如包含目录和编译标志。
# CMakeLists.txt
find_package(wxWidgets)
# Link the imported target for each dependent executable/library target.
target_link_libraries(<ProjectTarget> wxWidgets::wxWidgets)