Configure CMakeLists.txt for locally installed Protocol Buffers - c++

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

Related

How to include wxWidgets headers in CMake project

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

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.

How to compile Freetype (2) and Harfbuzz (with visual studio) to make them work together?

I have found good documentations on this known problem of compiling Freetype related to Harfbuzz: http://www.gregwessels.com/dev/2017/05/02/freetype-harfbuzz.html and here 44184890
But they seem obsolet nowadays: freetype-2.9 with harfbuzz-1.7.6
Here is my way compiling:
download Freetype tarball
extract the tarball...
open builds\windows\vc2010\freetype.sln
it should already Generate well (as a dll)
download Harfbuzz
extract the tarball next to freetype...
run cmake ./ at root level to obtain a .sln
it must already Generate well (as lib)
At this point you have 2 separate libs not working together which means:
Freetype will not open GSUB scripts of your fonts. (or maybe I am wrong)
To do so, I need help! I also need confirmations!!!
Is seems to be needed to enable the use of Harfbuzz in Freetype at compile time; I have found a precompiler directive called FT_CONFIG_OPTION_USE_HARFBUZZ
But when activating it, I have some compile link errors when using both libs in a third project:
autofit.obj : error LNK2019: external symbol not found _hb_ft_font_create referenced in function _af_face_globals_new
Good to know, hb_ft_font_create is an extern function in harfbuzz.
So it seems to be a cyclic extern problem... I certainly don't have the good config at a point, but I have browsed many docs and helps, found nothing...
-- edit --
After both pojects decompression, you have normaly to obtain such a tree:
.
├── freetype-2.9
│   ├── autogen.sh
│   ├── builds
│   │   ├── ...
│   │   └── windows
│ │ └── vc2010 <<<< The .sln to use is in here
│   ├── CMakeLists.txt <<<< It is also good to obtain proper sln
│   ├── configure
│   ├── devel
│   │   ├── ft2build.h
│   │   └── ftoption.h
│   ├── include
│   │   ├── freetype
│   │   └── ft2build.h
│   ├── ...
│   ├── objs
│   │   ├── freetype.dll
│   │   ├── freetype.lib
│   │   ├── README
│   │   └── Win32
│   ├── README
│   ├── README.git
│   └── src
└── harfbuzz-1.7.6
   ├── ...
   ├── cmake_install.cmake
   ├── CMakeLists.txt <<<< The cmake project to obtain proper sln is this one
   ├── compile
   ├── ...
   ├── COPYING
   ├── CTestTestfile.cmake
   ├── Debug
   │   ├── harfbuzz.lib
   │   ├── harfbuzz-subset.lib
   │   └── ...
   ├── depcomp
   ├── docs
   ├── gtk-doc.make
   ├── harfbuzz.sln
   ├── harfbuzz.vcxproj
   ├── ...
   ├── main.dir
   │   └── Debug
   ├── NEWS
   ├── README
   ├── README.python
   ├── RELEASING.md
   ├── replace-enum-strings.cmake
   ├── RUN_TESTS.vcxproj
   ├── RUN_TESTS.vcxproj.filters
   ├── src
   │   ├── *.hh
   │   └── *.cc
   ├── test
   ├── THANKS
   ├── TODO
   ├── util
   └── Win32
      └── Debug
Or configure harfbuzz like --with-freetype=no --with-fontconfig=no to avoid circular deps...I think so anyway...
Just use https://github.com/Microsoft/vcpkg/ to install both and don't look back :) Both HarfBuzz and Freetype have a port there and are well supported.
About the cyclic dependency, FreeType to HarfBuzz dependency is not a must think to have. vcpkg handles HarfBuzz to FreeType dependency and that is what most project will need.

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?