Debian Codegraph @

cmake-proxies/cmake-modules/dependencies/wxwidgets.cmake

raw
1 # Expose only the GUI-less subset of full wxWidgets
2 # Also prohibit use of some other headers by pre-defining their include guards
3 # wxUSE_GUI=0 doesn't exclude all of wxCore dependency, and the application
4 # object and event loops are in wxBase, but we want to exclude their use too
5 set ( WXBASE_RESTRICTIONS
6 "wxUSE_GUI=0"
7
8 # Don't use app.h
9 _WX_APP_H_BASE_
10
11 # Don't use evtloop.h
12 _WX_EVTLOOP_H_
13
14 # Don't use image.h
15 _WX_IMAGE_H
16
17 # Don't use colour.h
18 _WX_COLOUR_H_BASE_
19
20 # Don't use brush.h
21 _WX_BRUSH_H_BASE_
22
23 # Don't use pen.h
24 _WX_PEN_H_BASE_
25 )
26
27 function( apply_wxbase_restrictions target )
28 target_compile_definitions( ${target} PRIVATE ${WXBASE_RESTRICTIONS} )
29 endfunction()
30
31
32 # Make the wxBase interface target which exposes a limited view of wxWidgets --
33 # only the subset of wxBase consistent with "toolkit neutrality"
34 function(make_wxBase old)
35 make_interface_library(wxBase ${old})
36
37 get_target_property(defs wxBase INTERFACE_COMPILE_DEFINITIONS)
38
39 string(REPLACE "wxUSE_GUI=1;" "" defs "${defs}")
40 string(REPLACE ";wxUSE_GUI=1" "" defs "${defs}")
41 string(REPLACE "wxUSE_GUI=1" "" defs "${defs}")
42
43 set_property(TARGET wxBase PROPERTY INTERFACE_COMPILE_DEFINITIONS ${defs})
44
45 find_package( Threads QUIET )
46 if( Threads_FOUND )
47 target_link_libraries( wxBase INTERFACE Threads::Threads )
48 endif()
49
50 target_link_libraries( wxBase INTERFACE ${CMAKE_DL_LIBS} )
51
52 endfunction()
53
54 if( ${_OPT}use_wxwidgets STREQUAL "system" OR NOT ${_OPT}conan_enabled )
55 # DV: find_package will be scoped, as FindwxWidgets.cmake is rather outdated.
56 # Still - let's perform the sanity check first.
57 if( NOT wxWidgets_FOUND )
58 find_package( wxWidgets REQUIRED COMPONENTS adv base core html qa xml net )
59 endif()
60
61 if( NOT TARGET wxwidgets::wxwidgets )
62 add_library( wxwidgets::wxwidgets INTERFACE IMPORTED GLOBAL)
63 endif()
64
65 if( NOT TARGET wxwidgets::base )
66 add_library( wxwidgets::base ALIAS wxwidgets::wxwidgets )
67 endif()
68
69 if( NOT TARGET wxwidgets::core )
70 add_library( wxwidgets::core ALIAS wxwidgets::wxwidgets )
71 endif()
72
73 if( NOT TARGET wxwidgets::html )
74 add_library( wxwidgets::html ALIAS wxwidgets::wxwidgets )
75 endif()
76
77 if( NOT TARGET wxwidgets::xml )
78 add_library( wxwidgets::xml ALIAS wxwidgets::wxwidgets )
79 endif()
80
81 if( NOT TARGET wxwidgets::xrc )
82 add_library( wxwidgets::xrc ALIAS wxwidgets::wxwidgets )
83 endif()
84
85 if( NOT TARGET wxwidgets::qa )
86 add_library( wxwidgets::qa ALIAS wxwidgets::wxwidgets )
87 endif()
88
89 if( NOT TARGET wxwidgets::aui )
90 add_library( wxwidgets::aui ALIAS wxwidgets::wxwidgets )
91 endif()
92
93 if( NOT TARGET wxwidgets::adv )
94 add_library( wxwidgets::adv ALIAS wxwidgets::wxwidgets )
95 endif()
96
97 if( wxWidgets_INCLUDE_DIRS_NO_SYSTEM )
98 target_include_directories( wxwidgets::wxwidgets INTERFACE ${wxWidgets_INCLUDE_DIRS_NO_SYSTEM} )
99 else()
100 target_include_directories( wxwidgets::wxwidgets INTERFACE ${wxWidgets_INCLUDE_DIRS} )
101 endif()
102
103 target_compile_definitions( wxwidgets::wxwidgets INTERFACE
104 ${wxWidgets_DEFINITIONS_GENERAL}
105 $<$<CONFIG:Debug>:
106 ${wxWidgets_DEFINITIONS_DEBUG}
107 >
108 $<$<NOT:$<CONFIG:Debug>>:
109 ${wxWidgets_DEFINITIONS_OPTIMIZED}
110 >
111 )
112
113 target_link_directories( wxwidgets::wxwidgets INTERFACE
114 $<$<PLATFORM_ID:Windows>:
115 ${wxWidgets_LIB_DIR}
116 >
117 )
118
119 target_link_libraries( wxwidgets::wxwidgets INTERFACE
120 ${wxWidgets_LIBRARIES}
121 $<$<NOT:$<PLATFORM_ID:Windows>>:
122 z
123 >
124 )
125
126 if( NOT TARGET wxBase )
127 # add_library( wxBase ALIAS wxwidgets::wxwidgets )
128 make_wxBase(wxwidgets::wxwidgets)
129 endif()
130
131 set ( toolkit ${wxWidgets_LIBRARIES} )
132 else()
133 set_target_properties(wxwidgets::base PROPERTIES IMPORTED_GLOBAL On)
134 make_wxbase(wxwidgets::base)
135
136 # Assume that Conan package is built with GTK2 for now
137 # TODO: Find a way to autodetect the toolkit used by the Conan package
138 set( toolkit "libwx_gtk2u_core-3.1.so" )
139 endif()
140
141 if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin" )
142 message(STATUS "Trying to retrieve GTK version from ${toolkit}")
143
144 if( "${toolkit}" MATCHES ".*gtk2.*" )
145 set( gtk gtk+-2.0 )
146 set( glib glib-2.0 )
147 elseif( "${toolkit}" MATCHES ".*gtk3.*" )
148 set( gtk gtk+-3.0 )
149 set( glib glib-2.0 )
150 elseif( "${toolkit}" MATCHES ".*gtk4.*" )
151 set( gtk gtk+-4.0 )
152 set( glib glib-2.0 )
153 endif()
154
155 if( NOT DEFINED gtk )
156 execute_process(
157 COMMAND
158 wx-config --query-toolkit
159 OUTPUT_VARIABLE
160 wx_config_toolkit
161 OUTPUT_STRIP_TRAILING_WHITESPACE
162 )
163
164 message(STATUS "wx-config --query-toolkit --> ${wx_config_toolkit}")
165
166 if( "${wx_config_toolkit}" STREQUAL "gtk2" )
167 set( gtk gtk+-2.0 )
168 set( glib glib-2.0 )
169 elseif( "${wx_config_toolkit}" STREQUAL "gtk3" )
170 set( gtk gtk+-3.0 )
171 set( glib glib-2.0 )
172 elseif( "${wx_config_toolkit}" STREQUAL "gtk4" )
173 set( gtk gtk+-4.0 )
174 set( glib glib-2.0 )
175 endif()
176 endif()
177
178 if( NOT DEFINED gtk )
179 message(FATAL_ERROR "Could not determine GTK version from ${toolkit}")
180 endif()
181
182 find_package(PkgConfig)
183
184 pkg_check_modules( GTK REQUIRED IMPORTED_TARGET GLOBAL ${gtk} )
185 pkg_check_modules( GLIB REQUIRED IMPORTED_TARGET GLOBAL ${glib} )
186 endif()
187