浏览代码

FindwxWidgets: Add an imported target

CheesyNacho10 2 年之前
父节点
当前提交
e36e455b7c

+ 1 - 0
.gitlab/ci/configure_debian10_aarch64_ninja.cmake

@@ -65,6 +65,7 @@ set(CMake_TEST_FindRuby "ON" CACHE BOOL "")
 set(CMake_TEST_FindSDL "ON" CACHE BOOL "")
 set(CMake_TEST_FindSQLite3 "ON" CACHE BOOL "")
 set(CMake_TEST_FindTIFF "ON" CACHE BOOL "")
+set(CMake_TEST_FindwxWidgets "ON" CACHE BOOL "")
 set(CMake_TEST_FindX11 "ON" CACHE BOOL "")
 set(CMake_TEST_FindXalanC "ON" CACHE BOOL "")
 set(CMake_TEST_FindXercesC "ON" CACHE BOOL "")

+ 1 - 0
.gitlab/ci/configure_debian10_ninja.cmake

@@ -71,6 +71,7 @@ set(CMake_TEST_FindRuby_RVM "ON" CACHE BOOL "")
 set(CMake_TEST_FindSDL "ON" CACHE BOOL "")
 set(CMake_TEST_FindSQLite3 "ON" CACHE BOOL "")
 set(CMake_TEST_FindTIFF "ON" CACHE BOOL "")
+set(CMake_TEST_FindwxWidgets "ON" CACHE BOOL "")
 set(CMake_TEST_FindX11 "ON" CACHE BOOL "")
 set(CMake_TEST_FindXalanC "ON" CACHE BOOL "")
 set(CMake_TEST_FindXercesC "ON" CACHE BOOL "")

+ 1 - 0
.gitlab/ci/configure_fedora37_makefiles.cmake

@@ -69,6 +69,7 @@ set(CMake_TEST_FindRuby_RVM "ON" CACHE BOOL "")
 set(CMake_TEST_FindSDL "ON" CACHE BOOL "")
 set(CMake_TEST_FindSQLite3 "ON" CACHE BOOL "")
 set(CMake_TEST_FindTIFF "ON" CACHE BOOL "")
+set(CMake_TEST_FindwxWidgets "ON" CACHE BOOL "")
 set(CMake_TEST_FindX11 "ON" CACHE BOOL "")
 set(CMake_TEST_FindXalanC "ON" CACHE BOOL "")
 set(CMake_TEST_FindXercesC "ON" CACHE BOOL "")

+ 4 - 0
Help/release/dev/FindwxWidgets-imported-target.rst

@@ -0,0 +1,4 @@
+FindwxWidgets-imported-target
+-----------------------------
+
+* The :module:`FindwxWidgets` module now provides an imported target.

+ 21 - 0
Modules/FindwxWidgets.cmake

@@ -113,6 +113,16 @@ If wxWidgets is required (i.e., not an optional part):
    include(${wxWidgets_USE_FILE})
    # and for each of your dependent executable/library targets:
    target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+.. versionadded:: 3.27
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``wxWidgets::wxWidgets``
+  An interface library providing usage requirements for the found components.
 #]=======================================================================]
 
 #
@@ -981,6 +991,17 @@ find_package_handle_standard_args(wxWidgets
   )
 unset(wxWidgets_HANDLE_COMPONENTS)
 
+if(wxWidgets_FOUND AND NOT TARGET wxWidgets::wxWidgets)
+  add_library(wxWidgets::wxWidgets INTERFACE IMPORTED)
+  target_link_libraries(wxWidgets::wxWidgets INTERFACE ${wxWidgets_LIBRARIES})
+  target_link_directories(wxWidgets::wxWidgets INTERFACE ${wxWidgets_LIBRARY_DIRS})
+  target_include_directories(wxWidgets::wxWidgets INTERFACE ${wxWidgets_INCLUDE_DIRS})
+  target_compile_options(wxWidgets::wxWidgets INTERFACE ${wxWidgets_CXX_FLAGS})
+  target_compile_definitions(wxWidgets::wxWidgets INTERFACE ${wxWidgets_DEFINITIONS})
+  # FIXME: Add "$<$<CONFIG:Debug>:${wxWidgets_DEFINITIONS_DEBUG}>"
+  # if the debug library variant is available.
+endif()
+
 #=====================================================================
 # Macros for use in wxWidgets apps.
 # - This module will not fail to find wxWidgets based on the code

+ 1 - 0
Tests/CMakeLists.txt

@@ -1484,6 +1484,7 @@ if(BUILD_TESTING)
       SQLite3
       TIFF
       Vulkan
+      wxWidgets
       X11
       XalanC
       XercesC

+ 10 - 0
Tests/FindwxWidgets/CMakeLists.txt

@@ -0,0 +1,10 @@
+add_test(NAME FindwxWidgets.Test COMMAND
+  ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+  --build-and-test
+  "${CMake_SOURCE_DIR}/Tests/FindwxWidgets/Test"
+  "${CMake_BINARY_DIR}/Tests/FindwxWidgets/Test"
+  ${build_generator_args}
+  --build-project TestFindwxWidgets
+  --build-options ${build_options}
+  --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+  )

+ 17 - 0
Tests/FindwxWidgets/Test/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.26)
+project(TestFindwxWidgets CXX)
+include(CTest)
+
+find_package(wxWidgets REQUIRED)
+
+add_executable(test_tgt main.cpp)
+target_link_libraries(test_tgt wxWidgets::wxWidgets)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.cpp)
+target_link_libraries(test_var PRIVATE ${wxWidgets_LIBRARIES})
+target_link_directories(test_var PRIVATE ${wxWidgets_LIBRARY_DIRS})
+target_include_directories(test_var PRIVATE ${wxWidgets_INCLUDE_DIRS})
+target_compile_options(test_var PRIVATE ${wxWidgets_CONFIG_OPTIONS})
+target_compile_definitions(test_var PRIVATE ${wxWidgets_DEFINITIONS})
+add_test(NAME test_var COMMAND test_var)

+ 7 - 0
Tests/FindwxWidgets/Test/main.cpp

@@ -0,0 +1,7 @@
+#include <wx/filefn.h>
+
+int main()
+{
+  wxGetCwd();
+  return 0;
+}