Create Cmake file for WxWidgets project Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Taacoo
Experienced Solver
Experienced Solver
Posts: 61
Joined: Tue Dec 15, 2020 8:41 pm

Create Cmake file for WxWidgets project

Post by Taacoo »

Hi, I need to create a cmake file for my project written using wxwidgets.

I don't know how to do this, I checked over a dozen examples from the Internet and documentation - still errors.

I'm using those librares:

Code: Select all

<wx/button.h>
<wx/dialog.h>
<wx/filepicker.h>
<wx/sizer.h>
wx/wfstream.h"
<wx/zstream.h>
<wx/log.h>
<wx/stream.h>
<wx/progdlg.h>
<wx/dir.h>
<wx/tarstrm.h>
My files:

Code: Select all

Kompresja_GZIPMain.cpp
Kompresja_GZIPMain.h

Kompresja_GZIPApp.cpp
Kompresja_GZIPApp.h

FileCompress.cpp
FileCompress.h

FileDecompress.cpp
FileDecompress.h
Of course I have installed gcc/g++ compiler and cmake(I'm using cmake 3.19.1 GUI).

Thanks
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Create Cmake file for WxWidgets project

Post by ONEEYEMAN »

Hi,
Taacoo wrote: Wed Jan 06, 2021 10:20 pm Hi, I need to create a cmake file for my project written using wxwidgets.

I don't know how to do this, I checked over a dozen examples from the Internet and documentation - still errors.

I'm using those librares:

Code: Select all

<wx/button.h>
<wx/dialog.h>
<wx/filepicker.h>
<wx/sizer.h>
wx/wfstream.h"
<wx/zstream.h>
<wx/log.h>
<wx/stream.h>
<wx/progdlg.h>
<wx/dir.h>
<wx/tarstrm.h>
Those are not libraries - just a header files.
Taacoo wrote: Wed Jan 06, 2021 10:20 pm My files:

Code: Select all

Kompresja_GZIPMain.cpp
Kompresja_GZIPMain.h

Kompresja_GZIPApp.cpp
Kompresja_GZIPApp.h

FileCompress.cpp
FileCompress.h

FileDecompress.cpp
FileDecompress.h
Of course I have installed gcc/g++ compiler and cmake(I'm using cmake 3.19.1 GUI).

Thanks
Why not just simply compile you code with:

Code: Select all

g++ -o <binary_name> `<full/path/to/>wx-config --cxxflags --libs` *.cpp
That is if you are on Linux.

If you are on Windows - its a different story. It depends what flavor of gcc you have.

Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Create Cmake file for WxWidgets project

Post by PB »

I know very little about CMake but FWIW, here is my simple CMakeFile for a small application using wxWidgets (tested only on MSW and Linux). It uses only core and base wxWidgets libraries, so if any more are needed they need to be added in this line (and minimal required version of wxWidgets can be adjusted here as well):

Code: Select all

find_package(wxWidgets 3.1.0 COMPONENTS core base REQUIRED)
The file obviously needs to be adapted, in particular your actual header and source files must be set in

Code: Select all

set(SOURCES
statement. Other adjustments, such removing OpenCV libraries, changing the project name, etc must be done as well. Similarly, C++ standard needed can be changed. But all that should be very easy, considering the file is so short and its contents is quite self-descriptive.

If your application has its own resource file (it better does, if for just having an icon), change

Code: Select all

if (WIN32)
  list(APPEND SOURCES "${wxWidgets_ROOT_DIR}/include/wx/msw/wx.rc")
endif()
to add your own resource file instead, which should in turn include wx.rc file.

As always, CMake must be able to find wxWidgets, so on MSW either WXWIN system environment variable or CMake variables wxWidgets_LIB_DIR and wxWidgets_ROOT_DIR must be set correctly.
Post Reply