Here's a relatively simple CMakeLists.txt for a single-file project using wxWidgets:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR) project(main LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(wxWidgets_USE_STATIC 1) set(wxBUILD_SHARED OFF) include(FetchContent) FetchContent_Declare( wxWidgets GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git GIT_TAG master ) FetchContent_MakeAvailable(wxWidgets) set(wxWidgets_DIR ${wxWidgets_BINARY_DIR}) message(STATUS "wxWidgets_DIR is ${wxWidgets_DIR}") find_package(wxWidgets COMPONENTS core base REQUIRED CONFIG) set(SRCS src/main.cpp) add_executable(main WIN32 ${SRCS}) target_link_libraries(main ${wxWidgets_LIBRARIES})
This produces an error when configuring via cmake -S. -Bbuild:
-- Configured wxWidgets 3.3.0 for Darwin-22.6.0
Min OS Version required at runtime: macOS
Which GUI toolkit should wxWidgets use? osx_cocoa
Should wxWidgets be compiled into single library? OFF
Should wxWidgets be linked as a shared library? OFF
Which wxWidgets API compatibility should be used? 3.2
-- wxWidgets_DIR is /Users/luke/Documents/Development/wx_cmake_fetchcontent/build/lib/
CMake Error at CMakeLists.txt:24 (find_package):
Could not find a package configuration file provided by "wxWidgets" with
any of the following names:
wxWidgetsConfig.cmake
wxwidgets-config.cmake
Add the installation prefix of "wxWidgets" to CMAKE_PREFIX_PATH or set
"wxWidgets_DIR" to a directory containing one of the above files. If
"wxWidgets" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
The same problem occurs when setting wxWidgets_DIR to wxWidgets_SOURCE_DIR.
When setting wxWidgets_DIR to the actual location of wxWidgetsConfig.cmake (which is build/_deps/wxwidgets-build/lib/), then CMake complains about missing wxWidgetsTargets.cmake
-- Configured wxWidgets 3.3.0 for Darwin-22.6.0
Min OS Version required at runtime: macOS
Which GUI toolkit should wxWidgets use? osx_cocoa
Should wxWidgets be compiled into single library? OFF
Should wxWidgets be linked as a shared library? OFF
Which wxWidgets API compatibility should be used? 3.2
-- wxWidgets_DIR is /Users/luke/Documents/Development/wx_cmake_fetchcontent/build/_deps/wxwidgets-build/lib/
CMake Error at build/_deps/wxwidgets-build/lib/wxWidgetsConfig.cmake:68 (include):
include could not find requested file:
/Users/luke/Documents/Development/wx_cmake_fetchcontent/build/_deps/wxwidgets-build/lib/wxWidgetsTargets.cmake
Call Stack (most recent call first):
CMakeLists.txt:24 (find_package)
CMake Error at CMakeLists.txt:24 (find_package):
Found package configuration file:
/Users/luke/Documents/Development/wx_cmake_fetchcontent/build/_deps/wxwidgets-build/lib/wxWidgetsConfig.cmake
but it set wxWidgets_FOUND to FALSE so package "wxWidgets" is considered to
be NOT FOUND.
-- Configuring incomplete, errors occurred!
This reproduces on all platforms (Mac, Windows, Linux).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Sorry, no idea about why does this break with FetchContent. Any help with fixing it is welcome, as always, but IMO the best way to use wxWidgets in a project using CMake is to just include it as a submodule and then just use add_subdirectory().
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
It would be great if wxWidgets worked with modern CMake features for multi-project configurations (FetchContent or ExternalProject). I can make it work with ExternalProject when using CMake's FindWxWidgets instead of CONFIG, but then I can't make Scintilla work, which apparently requires using wxWidgetsConfig: #23749
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Maybe @MaartenBent can shed some light on what's going on here? (I saw you were active in the linked issue)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Target files are only created when installing, I don't know if FetchContent does this or if it only builds the project.
But looking at FetchContent examples, like https://coderefinery.github.io/cmake-workshop/fetch-content/, you don't use find_package but you use the targets directly.
Note that in this case the target names will be like wx::wxbase and not wx::base. The latter are aliases that we create in the config file.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Ok, I got it to work, you can't use the namespace either. It has to be the actual target name.
I used your modified CMakeLists.txt for the minimal sample:
cmake_minimum_required(VERSION 3.6 FATAL_ERROR) project(main LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(wxBUILD_SHARED OFF) include(FetchContent) FetchContent_Declare( wxWidgets GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git GIT_TAG master ) FetchContent_MakeAvailable(wxWidgets)
add_executable(main WIN32 minimal.cpp) target_link_libraries(main wxcore)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #23915 as completed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thanks, this works! I still can't get wxScintilla to work on Windows with ExternalProject_Add, but that's another topic...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()