Hi!
To start using wxWidgets in Ubuntu 23.10, I compiled and built the minimum
sample : https://github.com/wxWidgets/wxWidgets/blob/master/samples/minimal/ with wx-config:
raphy@raohy:~/MyPrj$ g++ `wx-config --cxxflags` -o myprj ./src/*.cpp `wx-config --libs`
raphy@raohy:~/MyPrj$ ./myprj
Now I would like to convert this command-line compilation and building into a CMake one
I used the CMakeLists.txt file provided in the samples
code: https://github.com/wxWidgets/wxWidgets/blob/master/samples/minimal/CMakeLists.txt where I added these two lines:
set(wxBUILD_SAMPLES ON)
and
set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr/local/lib/wx)
:
cmake_minimum_required(VERSION 3.24)
if(APPLE AND NOT CMAKE_OSX_DEPLOYMENT_TARGET)
# If no deployment target has been set default to the minimum supported
# OS version (this has to be set before the first project() call)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0 CACHE STRING "iOS Deployment Target")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10 CACHE STRING "macOS Deployment Target")
endif()
endif()
# Name the project
project(minimal)
set(CMAKE_CXX_STANDARD 11 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(wxWidgets_CONFIG_OPTIONS --toolkit=base --prefix=/usr/local/lib/wx)
set(wxBUILD_SAMPLES ON)
# Request the required wxWidgets libs
find_package(wxWidgets 3.3 COMPONENTS core base REQUIRED CONFIG)
# Include the wxWidgets use file to initialize various settings
if(wxWidgets_USE_FILE)
include(${wxWidgets_USE_FILE})
endif()
# Define a variable containing a list of source files for the project
set(SRC_FILES
src/minimal.cpp
)
if(WIN32)
# Include a RC file for windows
list(APPEND SRC_FILES ./sample.rc)
elseif(APPLE)
# Add an icon for the apple .app file
list(APPEND SRC_FILES ./src/osx/carbon/wxmac.icns)
endif()
# Define the build target for the executable
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE ${SRC_FILES})
# Link required libraries to the executable
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
RESOURCE "./src/icons/wxmac.icns"
MACOSX_BUNDLE_ICON_FILE wxmac.icns
MACOSX_BUNDLE_COPYRIGHT "Copyright wxWidgets"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.wxwidgets.minimal"
)
endif()
But I get this error:
raphy@raohy:~/MyPrj$ cmake -B builddir
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:48 (find_package):
Could not find a package configuration file provided by "wxWidgets"
(requested version 3.3) 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!
How to make it work?