File: wxwidgets.cmake

package info (click to toggle)
audacity 3.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 125,252 kB
  • sloc: cpp: 358,238; ansic: 75,458; lisp: 7,761; sh: 3,410; python: 1,503; xml: 1,385; perl: 854; makefile: 122
file content (187 lines) | stat: -rw-r--r-- 5,552 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Expose only the GUI-less subset of full wxWidgets
# Also prohibit use of some other headers by pre-defining their include guards
# wxUSE_GUI=0 doesn't exclude all of wxCore dependency, and the application
# object and event loops are in wxBase, but we want to exclude their use too
set ( WXBASE_RESTRICTIONS
   "wxUSE_GUI=0"

   # Don't use app.h
   _WX_APP_H_BASE_

   # Don't use evtloop.h
   _WX_EVTLOOP_H_

   # Don't use image.h
   _WX_IMAGE_H

   # Don't use colour.h
   _WX_COLOUR_H_BASE_

   # Don't use brush.h
   _WX_BRUSH_H_BASE_

   # Don't use pen.h
   _WX_PEN_H_BASE_
)

function( apply_wxbase_restrictions target )
   target_compile_definitions( ${target} PRIVATE ${WXBASE_RESTRICTIONS} )
endfunction()


# Make the wxBase interface target which exposes a limited view of wxWidgets --
# only the subset of wxBase consistent with "toolkit neutrality"
function(make_wxBase old)
   make_interface_library(wxBase ${old})

   get_target_property(defs wxBase INTERFACE_COMPILE_DEFINITIONS)

   string(REPLACE "wxUSE_GUI=1;" "" defs "${defs}")
   string(REPLACE ";wxUSE_GUI=1" "" defs "${defs}")
   string(REPLACE "wxUSE_GUI=1" "" defs "${defs}")

   set_property(TARGET wxBase PROPERTY INTERFACE_COMPILE_DEFINITIONS ${defs})

   find_package( Threads QUIET )
   if( Threads_FOUND )
      target_link_libraries( wxBase INTERFACE Threads::Threads )
   endif()

   target_link_libraries( wxBase INTERFACE ${CMAKE_DL_LIBS} )

endfunction()

if( ${_OPT}use_wxwidgets STREQUAL "system" OR NOT ${_OPT}conan_enabled )
    # DV: find_package will be scoped, as FindwxWidgets.cmake is rather outdated.
    # Still - let's perform the sanity check first.
    if( NOT wxWidgets_FOUND )
        find_package( wxWidgets REQUIRED COMPONENTS adv base core html qa xml net )
    endif()

    if( NOT TARGET wxwidgets::wxwidgets )
        add_library( wxwidgets::wxwidgets INTERFACE IMPORTED GLOBAL)
    endif()

    if( NOT TARGET wxwidgets::base )
        add_library( wxwidgets::base ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::core )
        add_library( wxwidgets::core ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::html )
        add_library( wxwidgets::html ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::xml )
        add_library( wxwidgets::xml ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::xrc )
        add_library( wxwidgets::xrc ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::qa )
        add_library( wxwidgets::qa ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::aui )
        add_library( wxwidgets::aui ALIAS wxwidgets::wxwidgets )
    endif()

    if( NOT TARGET wxwidgets::adv )
        add_library( wxwidgets::adv ALIAS wxwidgets::wxwidgets )
    endif()

    if( wxWidgets_INCLUDE_DIRS_NO_SYSTEM )
        target_include_directories( wxwidgets::wxwidgets INTERFACE ${wxWidgets_INCLUDE_DIRS_NO_SYSTEM} )
    else()
        target_include_directories( wxwidgets::wxwidgets INTERFACE ${wxWidgets_INCLUDE_DIRS} )
    endif()

    target_compile_definitions( wxwidgets::wxwidgets INTERFACE
        ${wxWidgets_DEFINITIONS_GENERAL}
        $<$<CONFIG:Debug>:
            ${wxWidgets_DEFINITIONS_DEBUG}
        >
        $<$<NOT:$<CONFIG:Debug>>:
            ${wxWidgets_DEFINITIONS_OPTIMIZED}
        >
    )

    target_link_directories( wxwidgets::wxwidgets INTERFACE
        $<$<PLATFORM_ID:Windows>:
           ${wxWidgets_LIB_DIR}
        >
    )

    target_link_libraries( wxwidgets::wxwidgets INTERFACE
        ${wxWidgets_LIBRARIES}
        $<$<NOT:$<PLATFORM_ID:Windows>>:
           z
        >
    )

    if( NOT TARGET wxBase )
        # add_library( wxBase ALIAS wxwidgets::wxwidgets )
        make_wxBase(wxwidgets::wxwidgets)
    endif()

    set ( toolkit ${wxWidgets_LIBRARIES} )
else()
    set_target_properties(wxwidgets::base PROPERTIES IMPORTED_GLOBAL On)
    make_wxbase(wxwidgets::base)

    # Assume that Conan package is built with GTK2 for now
    # TODO: Find a way to autodetect the toolkit used by the Conan package
    set( toolkit "libwx_gtk2u_core-3.1.so" )
endif()

if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows|Darwin" )
    message(STATUS "Trying to retrieve GTK version from ${toolkit}")

    if( "${toolkit}" MATCHES ".*gtk2.*" )
       set( gtk gtk+-2.0 )
       set( glib glib-2.0 )
    elseif( "${toolkit}" MATCHES ".*gtk3.*" )
       set( gtk gtk+-3.0 )
       set( glib glib-2.0 )
    elseif( "${toolkit}" MATCHES ".*gtk4.*" )
       set( gtk gtk+-4.0 )
       set( glib glib-2.0 )
    endif()

    if( NOT DEFINED gtk )
       execute_process(
         COMMAND
           wx-config --query-toolkit
         OUTPUT_VARIABLE
            wx_config_toolkit
         OUTPUT_STRIP_TRAILING_WHITESPACE
       )

       message(STATUS "wx-config --query-toolkit --> ${wx_config_toolkit}")

       if( "${wx_config_toolkit}" STREQUAL "gtk2" )
          set( gtk gtk+-2.0 )
          set( glib glib-2.0 )
       elseif( "${wx_config_toolkit}" STREQUAL "gtk3" )
          set( gtk gtk+-3.0 )
          set( glib glib-2.0 )
       elseif( "${wx_config_toolkit}" STREQUAL "gtk4" )
          set( gtk gtk+-4.0 )
          set( glib glib-2.0 )
       endif()
    endif()

    if( NOT DEFINED gtk )
       message(FATAL_ERROR "Could not determine GTK version from ${toolkit}")
    endif()

    find_package(PkgConfig)

    pkg_check_modules( GTK REQUIRED IMPORTED_TARGET GLOBAL ${gtk} )
    pkg_check_modules( GLIB REQUIRED IMPORTED_TARGET GLOBAL ${glib} )
endif()