How to include wxWidgets headers in CMake project - c++

I am trying to run wxWidget example using cmake but unable to include the headers of wxWidgets in my C++ project(CMakeLists.txt). If i run the program using the command
g++ main.cpp `wx-config --cppflags --libs` -o wxTest
the program works and display the window. But how can i do that using CMakeLists.txt file. For example, usually i create a separate folder called external-libs and then inside it create a folder with the name whateverlibraryname and then inside it create a header and src and lib folder where i place the header files, any source files and .so files respectively. But in the case of wxWidgets i have several static library files and also inside the header there are many separate folders and i don't know how to include them all. They produce the error:
fatal error: wx/wx.h: No such file or directory
#include <wx/wx.h>
I am using Ubuntu 18.04 and my project directory structure is as follows:
├── build
└── source
├── CMakeLists.txt
├── external-libraries
│   └── wxWidgets
│   ├── headers
│   │   ├── msvc
│   │   │   └── wx
│   │   └── wx
│   │   ├── android
│   │   ├── aui
│   │   ├── dfb
│   │   ├── generic
│   │   ├── gtk
│   │   ├── gtk1
│   │   ├── html
│   │   ├── meta
│   │   ├── motif
│   │   ├── msw
│   │   ├── osx
│   │   ├── persist
│   │   ├── private
│   │   ├── propgrid
│   │   ├── protocol
│   │   ├── qt
│   │   ├── ribbon
│   │   ├── richtext
│   │   ├── stc
│   │   ├── univ
│   │   ├── unix
│   │   ├── x11
│   │   ├── xml
│   │   └── xrc
│   ├── lib  
├── libwx_baseu-3.1.a
│   │   ├── libwx_baseu_net-3.1.a
│   │   ├── libwx_baseu_xml-3.1.a
│   │   ├── libwx_gtk3u_adv-3.1.a
│   │   ├── libwx_gtk3u_aui-3.1.a
│   │   ├── libwx_gtk3u_core-3.1.a
│   │   ├── libwx_gtk3u_gl-3.1.a
│   │   ├── libwx_gtk3u_html-3.1.a
│   │   ├── libwx_gtk3u_propgrid-3.1.a
│   │   ├── libwx_gtk3u_qa-3.1.a
│   │   ├── libwx_gtk3u_ribbon-3.1.a
│   │   ├── libwx_gtk3u_richtext-3.1.a
│   │   ├── libwx_gtk3u_stc-3.1.a
│   │   ├── libwx_gtk3u_xrc-3.1.a
│   │   ├── libwxjpeg-3.1.a
│   │   ├── libwxregexu-3.1.a
│   │   ├── libwxscintilla-3.1.a
│   │   └── libwxtiff-3.1.a
│   └── src
├── main.cpp
Main.cpp has #include<wx/wx.h> at the top. I am using VSCode and when i ran the program using g++(command described above) it works but doesn't workwhen i run the same program using CMake. That is how to include the header folder and use the lib folder that contains all the wxWidgets headers and library files. What should be the contents of the CMakeLists.txt files and what are the other necessary things that i have to do to make this work.

CMake has first-party support for wxWidgets, here's an example:
cmake_minimum_required(VERSION 3.20)
project(wxTest)
find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net)
include(${wxWidgets_USE_FILE})
add_executable(wxTest main.cpp)
target_link_libraries(wxTest PRIVATE ${wxWidgets_LIBRARIES})
It's a bit unfortunate how legacy this module is. The above code would be much better off using imported targets and not need to do this weird dance with include(${wxWidgets_USE_FILE}), but alas. At least it's documented.
There are various variables you can set to help it find your wxWidgets installation. See the documentation for more details: https://cmake.org/cmake/help/latest/module/FindwxWidgets.html

Related

How should I organize a CMake project with lots of files?

I am completely new to CMake, and I have never used it before. I am trying to understand how to organize my files. Right now, I have this structure:
.
├── cli
│   ├── cli.cpp
│   ├── cli.h
│   ├── interactive.cpp
│   ├── interactive.h
│   ├── web.cpp
│   └── web.h
├── core
│   ├── Job.cpp
│   ├── Job.h
│   ├── Settings.cpp
│   ├── Settings.h
│   ├── Utils.cpp
│   └── Utils.h
└── ui
├── img
│   └── appicon.xpm
├── main.cpp
├── main.h
├── MainHeader.cpp
├── MainHeader.h
├── MainWindow.cpp
├── MainWindow.h
├── SettingsPanel.cpp
└── SettingsPanel.h
How should I rearrange these files and what would a basic CMakeLists.txt look like?
Thank you.

Virtualenv for a project with multiple modules

I am trying to build a project from scratch in python 2, it has structure shown below. In past I have created projects with a single hierarchy, so there would be single virtualenv, but this project has multiple subpackages, what is the best practice to be followed: there should be a single virtualenv inside project_root directory shared by all subpackages in it, or there should be separate virtualenv for each subpackage?
project_root/
├── commons
│   ├── hql_helper.py
│   ├── hql_helper.pyc
│   ├── __init__.py
│   └── sample_HQL.hql
├── fl_wtchr
│   ├── fl_wtchr_test.py
│   ├── fl_wtchr_test.pyc
│   ├── __init__.py
│   ├── meta_table.hql
│   ├── requirements.txt
│   ├── sftp_tmp
│   ├── sql_test.py
│   └── sql_test.pyc
├── qry_exec
│   ├── act_qry_exec_script.py
│   ├── hive_db.logs
│   ├── params.py
│   └── params.pyc
├── sqoop_a
│   ├── __init__.py
│   └── sqoop.py
└── test.py
A case could be made for creating separate virtual environments for each module; but fundamentally, you want and expect all this code to eventually be able to run without a virtualenv at all. All your modules should be able to run with whatever you install into the top-level virtual environment and so that's what you should primarily be testing against.

Configure CMakeLists.txt for locally installed Protocol Buffers

I downloaded the Protocol Buffers source from GitHub. I don't want to install it globally and just want to use it in my ROS package. I found cmake files here but not sure how to use them in my project.
Below is the content of my CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(local_protobuf_ros_example)
find_package(catkin REQUIRED COMPONENTS roscpp)
find_package(Protobuf REQUIRED)
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS})
add_library(addressbook_protobuf include/addressbook.pb.cc)
add_executable(main src/main.cpp)
target_link_libraries(main ${catkin_LIBRARIES} addressbook_protobuf ${PROTOBUF_LIBRARIES})
Below is the file structure of ROS Package:
├── CMakeLists.txt
├── include
│   ├── addressbook.pb.cc
│   ├── addressbook.pb.h
│   └── addressbook.proto
├── lib
│   ├── protobuf-3.5.0
│   │   ├── cmake
│   │   │   ├── CMakeLists.txt
│   │   │   ├── examples.cmake
│   │   │   ├── extract_includes.bat.in
│   │   │   ├── install.cmake
│   │   │   ├── libprotobuf.cmake
│   │   │   ├── libprotobuf-lite.cmake
│   │   │   ├── libprotoc.cmake
│   │   │   ├── protobuf-config.cmake.in
│   │   │   ├── protobuf-config-version.cmake.in
│   │   │   ├── protobuf-lite.pc.cmake
│   │   │   ├── protobuf-module.cmake.in
│   │   │   ├── protobuf-options.cmake
│   │   │   ├── protobuf.pc.cmake
│   │   │   ├── protoc.cmake
│   │   │   ├── README.md
│   │   │   └── tests.cmake
│   │   ├──SOME_FILES_ARE_NOT_BEING_SHOWN_HERE
│   └── protobuf-cpp-3.5.0.zip
├── package.xml
└── src
└── main.cpp
I want to know that how to configure above CMakeLists.txt so that it uses locally installed Protocol Buffers?
You can set CMAKE_MODULE_PATH when you configure your build directory to specify a custom location to search for packages. You are not required to modify your CMakeLists.txt, configure your build for example like this:
cmake -DCMAKE_MODULE_PATH=/path/to/protobuf/cmake/config /path/to/source

apache2: /etc/apache2/sites-available is missing on macos

I am trying to configure apache2 so that it communicates with django and I am unable to the 'sites-available' directory where I believe a 'defaults' directory should reside.
The following is my file structure under the 'etc/apache2/' directory:
├── extra
│   ├── httpd-autoindex.conf
│   ├── httpd-dav.conf
│   ├── httpd-default.conf
│   ├── httpd-info.conf
│   ├── httpd-languages.conf
│   ├── httpd-manual.conf
│   ├── httpd-mpm.conf
│   ├── httpd-multilang-errordoc.conf
│   ├── httpd-ssl.conf
│   ├── httpd-userdir.conf
│   ├── httpd-vhosts.conf
│   └── proxy-html.conf
├── httpd.conf
├── httpd.conf.bak
├── httpd.conf.pre-update
├── magic
├── mime.types
├── original
│   ├── extra
│   │   ├── httpd-autoindex.conf
│   │   ├── httpd-dav.conf
│   │   ├── httpd-default.conf
│   │   ├── httpd-info.conf
│   │   ├── httpd-languages.conf
│   │   ├── httpd-manual.conf
│   │   ├── httpd-mpm.conf
│   │   ├── httpd-multilang-errordoc.conf
│   │   ├── httpd-ssl.conf
│   │   ├── httpd-userdir.conf
│   │   ├── httpd-vhosts.conf
│   │   └── proxy-html.conf
│   └── httpd.conf
├── other
│   └── php5.conf
└── users
├── Guest.conf
├── aphexlog.conf
└── secops.conf
If anyone knows if there is a possibility of a alternative config file with the same properties or some other solution... maybe I am just being dumb but everything that I have found online indicates that I should have this properties file.
Any and all help is appreciated :)
sites-available is a concept from Debian-derived distributions of Linux. MacOS does not have it, and neither do most other Linux flavours.
Instead you need to put your configuration directly in httpd.conf.
(Note, it's unusual to run a production system on a Mac; if you're just doing this for development, you can use the built-in runserver rather than messing around with Apache.)

Cython / C++ any repos of good example?

Tried googling this morning - and found this
https://gist.github.com/cournape/1077528
But I ran python3 setup.py install - and that's not what I really wanted. I would like to wrap my c++ in python and not install locally.
So I see
├── build
│   ├── lib.linux-x86_64-3.4
│   │   ├── rectangle.cpython-34m.so
│   │   └── rect.cpython-34m.so
│   └── temp.linux-x86_64-3.4
│   ├── rectangle.o
│   ├── Rectangle.o
│   └── rect.o
├── rectangle.c
├── rectangle.cpp
├── Rectangle.cpp
├── Rectangle.h
├── rectangle.pyx
├── rect.cpp
├── rect.pyx
└── setup.py
Now I can use the module because it's installed - but how would I use it if it was compiled in place?