find_package with CONFIG and FetchContent issue (Issue #23915)

271 views
Skip to first unread message

lszl84

unread,
Sep 29, 2023, 1:21:10 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915@github.com>

VZ

unread,
Sep 29, 2023, 1:26:54 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741253438@github.com>

lszl84

unread,
Sep 29, 2023, 1:36:02 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741264017@github.com>

lszl84

unread,
Sep 29, 2023, 1:38:06 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741266144@github.com>

Maarten

unread,
Sep 29, 2023, 1:47:11 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741275882@github.com>

Maarten

unread,
Sep 29, 2023, 2:38:09 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741331115@github.com>

lszl84

unread,
Sep 29, 2023, 4:30:20 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issue/23915/issue_event/10515140149@github.com>

lszl84

unread,
Sep 29, 2023, 4:30:21 PM9/29/23
to wx-...@googlegroups.com, Subscribed

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.Message ID: <wxWidgets/wxWidgets/issues/23915/1741454402@github.com>

Reply all
Reply to author
Forward
0 new messages