6.21. Using wxWidgets

This section describes the status of the wxWidgets libraries in the ports tree and its integration with the ports system.

6.21.1. Introduction

There are many versions of the wxWidgets libraries which conflict between them (install files under the same name). In the ports tree this problem has been solved by installing each version under a different name using version number suffixes.

The obvious disadvantage of this is that each application has to be modified to find the expected version. Fortunately, most of the applications call the wx-config script to determine the necessary compiler and linker flags. The script is named differently for every available version. Majority of applications respect an environment variable, or accept a configure argument, to specify which wx-config script to call. Otherwise they have to be patched.

6.21.2. Version Selection

To make the port use a specific version of wxWidgets there are two variables available for defining (if only one is defined the other will be set to a default value):

Table 6.30. Variables to Select wxWidgets Versions
VariableDescriptionDefault value
USE_WXList of versions the port can useAll available versions
USE_WX_NOTList of versions the port cannot useNone

The available wxWidgets versions and the corresponding ports in the tree are:

Table 6.31. Available wxWidgets Versions

The variables in Table 6.30, “Variables to Select wxWidgets Versions” can be set to one or more of these combinations separated by spaces:

Table 6.32. wxWidgets Version Specifications
Single version2.8
Ascending range2.8+
Descending range3.0-
Full range (must be ascending)2.8-3.0

There are also some variables to select the preferred versions from the available ones. They can be set to a list of versions, the first ones will have higher priority.

Table 6.33. Variables to Select Preferred wxWidgets Versions
NameDesigned for
WANT_WX_VERthe port
WITH_WX_VERthe user

6.21.3. Component Selection

There are other applications that, while not being wxWidgets libraries, are related to them. These applications can be specified in WX_COMPS. These components are available:

Table 6.34. Available wxWidgets Components
NameDescriptionVersion restriction
wxmain librarynone
contribcontributed librariesnone
pythonwxPython (Python bindings)2.8-3.0

The dependency type can be selected for each component by adding a suffix separated by a semicolon. If not present then a default type will be used (see Table 6.36, “Default wxWidgets Dependency Types”). These types are available:

Table 6.35. Available wxWidgets Dependency Types
buildComponent is required for building, equivalent to BUILD_DEPENDS
runComponent is required for running, equivalent to RUN_DEPENDS
libComponent is required for building and running, equivalent to LIB_DEPENDS

The default values for the components are detailed in this table:

Table 6.36. Default wxWidgets Dependency Types
ComponentDependency type

Example 6.26. Selecting wxWidgets Components

This fragment corresponds to a port which uses wxWidgets version 2.4 and its contributed libraries.

USE_WX=		2.8
WX_COMPS=	wx contrib

6.21.4. Detecting Installed Versions

To detect an installed version, define WANT_WX. If it is not set to a specific version then the components will have a version suffix. HAVE_WX will be filled after detection.

Example 6.27. Detecting Installed wxWidgets Versions and Components

This fragment can be used in a port that uses wxWidgets if it is installed, or an option is selected.

WANT_WX=	yes

.include <bsd.port.pre.mk>

.if defined(WITH_WX) || !empty(PORT_OPTIONS:MWX) || !empty(HAVE_WX:Mwx-2.8)
USE_WX=			2.8
CONFIGURE_ARGS+=	--enable-wx

This fragment can be used in a port that enables wxPython support if it is installed or if an option is selected, in addition to wxWidgets, both version 2.8.

USE_WX=		2.8
WANT_WX=	2.8

.include <bsd.port.pre.mk>

.if defined(WITH_WXPYTHON) || !empty(PORT_OPTIONS:MWXPYTHON) || !empty(HAVE_WX:Mpython)
WX_COMPS+=		python
CONFIGURE_ARGS+=	--enable-wxpython

6.21.5. Defined Variables

These variables are available in the port (after defining one from Table 6.30, “Variables to Select wxWidgets Versions”).

Table 6.37. Variables Defined for Ports That Use wxWidgets
WX_CONFIGThe path to the wxWidgets wx-config script (with different name)
WXRC_CMDThe path to the wxWidgets wxrc program (with different name)
WX_VERSIONThe wxWidgets version that is going to be used (for example, 2.6)

6.21.6. Processing in bsd.port.pre.mk

Define WX_PREMK to be able to use the variables right after including bsd.port.pre.mk.


When defining WX_PREMK, then the version, dependencies, components and defined variables will not change if modifying the wxWidgets port variables after including bsd.port.pre.mk.

Example 6.28. Using wxWidgets Variables in Commands

This fragment illustrates the use of WX_PREMK by running the wx-config script to obtain the full version string, assign it to a variable and pass it to the program.

USE_WX=		2.8

.include <bsd.port.pre.mk>

.if exists(${WX_CONFIG})
VER_STR!=	${WX_CONFIG} --release



The wxWidgets variables can be safely used in commands when they are inside targets without the need of WX_PREMK.

6.21.7. Additional configure Arguments

Some GNU configure scripts cannot find wxWidgets with just the WX_CONFIG environment variable set, requiring additional arguments. WX_CONF_ARGS can be used for provide them.

Table 6.38. Legal Values for WX_CONF_ARGS
Possible valueResulting argument
relative--with-wx=${LOCALBASE} --with-wx-config=${WX_CONFIG:T}

All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.