Skip to content

Commit

Permalink
Better cmake (facontidavide#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide authored Jul 30, 2022
1 parent 729e6a2 commit 0589417
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 77 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")



add_definitions(
-DPJ_MAJOR_VERSION=${PROJECT_VERSION_MAJOR}
-DPJ_MINOR_VERSION=${PROJECT_VERSION_MINOR}
Expand All @@ -30,6 +32,16 @@ include_directories( plotjuggler_base/src )

add_definitions( -DFMT_HEADER_ONLY )

if (EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.txt)
set(BUILDING_WITH_CONAN ON)
message(STATUS "BUILDING_WITH_CONAN")
endif()

if(VCPKG_TOOLCHAIN)
set(BUILDING_WITH_VCPKG ON)
message(STATUS "BUILDING_WITH_VCPKG")
endif()

# http://answers.ros.org/question/230877/optionally-build-a-package-with-catkin/
if( CATKIN_DEVEL_PREFIX OR catkin_FOUND OR CATKIN_BUILD_BINARY_PACKAGE)
set(COMPILING_WITH_CATKIN 1)
Expand Down Expand Up @@ -295,6 +307,8 @@ if(NOT COMPILING_WITH_AMENT AND NOT COMPILING_WITH_CATKIN)
COMPATIBILITY SameMajorVersion
)

message (STATUS "CMAKE_CURRENT_BINARY_DIR = ${CMAKE_CURRENT_BINARY_DIR}")

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
Expand Down
129 changes: 129 additions & 0 deletions COMPILE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Compile in Linux

On Ubuntu, the dependencies can be installed with the the command:

sudo apt -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev \
libqt5opengl5-dev libqt5x11extras5-dev libprotoc-dev libzmq-dev

On Fedora:

sudo dnf install qt5-qtbase-devel qt5-qtsvg-devel qt5-websockets-devel \
qt5-qtopendl-devel qt5-qtx11extras-devel

Clone the repository into **~/plotjuggler_ws*:

```
git clone https://github.com/facontidavide/PlotJuggler.git ~/plotjuggler_ws/src/PlotJuggler
cd ~/plotjuggler_ws
```

Then compile using cmake (qmake is NOT supported):

```
cmake -S src/PlotJuggler -B build/PlotJuggler -DCMAKE_INSTALL_PREFIX=install
cmake --build build/PlotJuggler --config RelWithDebInfo --parallel --target install
```

## Optional: build with Conan

If you want to use [conan](https://conan.io/) to manage the dependencies,
follow this instructions instead.

```
conan install src/PlotJuggler --install-folder build/PlotJuggler \
--build missing -pr:b=default
export CMAKE_TOOLCHAIN=$(pwd)/build/PlotJuggler/conan_toolchain.cmake
cmake -S src/PlotJuggler -B build/PlotJuggler \
-DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW
cmake --build build/PlotJuggler --config RelWithDebInfo --parallel --target install
```

## Deploy as an AppImage

Compile and install as described earlier.

Download (once) linuxdeploy:

```
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
wget https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage
chmod +x linuxdeploy*.AppImage
mkdir -p AppDir/usr/bin
```

Then:

```
cd src/PlotJuggler;export VERSION=$(git describe --abbrev=0 --tags);cd -
echo $VERSION
cp -v install/bin/* AppDir/usr/bin
./linuxdeploy-x86_64.AppImage --appdir=AppDir \
-d ./PlotJuggler/PlotJuggler.desktop \
-i ./PlotJuggler/plotjuggler.png \
--plugin qt --output appimage
```

# Compile in Windows

Dependencies in Windows are managed either using
[conan](https://conan.io/) or [vcpkg](https://vcpkg.io/en/index.html)

The rest of this section assumes that you installed
You need to install first [Qt](https://www.qt.io/download-open-source) and
[git](https://desktop.github.com/).

**Visual studio 2019 (16)**, that is part of the Qt 5.15.x installation,
will be used to compile PlotJuggler.

Start creating a folder called **plotjuggler_ws** and cloning the repo:

```
cd \
mkdir plotjuggler_ws
cd plotjuggler_ws
git clone https://github.com/facontidavide/PlotJuggler.git src/PlotJuggler
```

## Build with Conan

Note: the Arrow/Parque plugin is not supported in Conan. Use vcpkg instead, if you need
that specific plugin.

```
conan install src/PlotJuggler --install-folder build/PlotJuggler ^
--build=missing -pr:b=default
set CMAKE_TOOLCHAIN=%cd%/build/PlotJuggler/conan_toolchain.cmake
cmake -G "Visual Studio 16" ^
-S src/PlotJuggler -B build/PlotJuggler ^
-DCMAKE_TOOLCHAIN_FILE=%CMAKE_TOOLCHAIN% ^
-DCMAKE_INSTALL_PREFIX=%cd%/install ^
-DCMAKE_POLICY_DEFAULT_CMP0091=NEW
-D
cmake --build build/PlotJuggler --config Release --parallel --target install
```

## Build with vcpkg

Change the path where **vcpkg.cmake** can be found as needed.

```
set CMAKE_TOOLCHAIN=/path/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake -G "Visual Studio 16" ^
-S src/PlotJuggler -B build/PlotJuggler ^
-DCMAKE_TOOLCHAIN_FILE=%CMAKE_TOOLCHAIN% ^
-DCMAKE_INSTALL_PREFIX=%cd%/install
cmake --build build/PlotJuggler --config Release --parallel --target install
```
51 changes: 2 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,56 +91,9 @@ Install the debian packages using:

sudo apt install ros-$ROS_DISTRO-plotjuggler-ros

## How to build (Linux)
## How to build and deploy

The only binary dependency that you need installed in your system is Qt5.

On Ubuntu, the debians can be installed with the the command:

sudo apt -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev libqt5opengl5-dev libqt5x11extras5-dev libprotoc-dev libzmq-dev

On Fedora:

sudo dnf install qt5-qtbase-devel qt5-qtsvg-devel qt5-websockets-devel qt5-qtopendl-devel qt5-qtx11extras-devel

Clone the repository into **~/plotjuggler_ws*:

```
git clone https://github.com/facontidavide/PlotJuggler.git ~/plotjuggler_ws/src/PlotJuggler
cd ~/plotjuggler_ws
```

Then compile using cmake (qmake is NOT supported):

```
cmake -S src/PlotJuggler -B build/PlotJuggler -DCMAKE_INSTALL_PREFIX=install
cmake --build build/PlotJuggler --config RelWithDebInfo --parallel --target install
```

The main executable and the plugins will be installed in **~/plotjuggler_ws/install/bin**.

## How to build (Windows)

You need to install first [Qt](https://www.qt.io/download-open-source),
[git](https://desktop.github.com/) and [vcpkg](https://vcpkg.io/en/getting-started.html).

We will further assume that **vcpkg** is installed in **C:\vcpkg**.

Clone the repo into **C:\plotjuggler_ws**:

```
cd \
git clone https://github.com/facontidavide/PlotJuggler.git plotjuggler_ws/src/PlotJuggler
cd ~/plotjuggler_ws
```

Compile with cmake, using vcpkg to download and compile all the required dependencies:

```
cmake -S plotjuggler -B build/plotjuggler -DCMAKE_INSTALL_PREFIX="install"
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build/PlotJuggler --config RelWithDebInfo --parallel --target install
```
You can find build and installation instructions in [COMPILE.md](COMPILE.md).

## Note for ROS users

Expand Down
8 changes: 8 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[requires]
protobuf/3.21.1
mosquitto/2.0.14
zeromq/4.3.4

[generators]
CMakeDeps
CMakeToolchain
30 changes: 20 additions & 10 deletions plotjuggler_plugins/DataLoadParquet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
if(BUILDING_WITH_VCPKG)
message(STATUS "Finding Parquet with vcpkg")
set(PARQUET_LIBRARIES
re2::re2
arrow_shared
parquet_shared
arrow_bundled_dependencies)

set(CMAKE_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${CMAKE_MODULE_PATH} )
set(CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH} ${CMAKE_MODULE_PATH}")
find_package(arrow CONFIG QUIET)

find_package(Zstd QUIET)
set (ZSTD_LIB ${Zstd_LIBRARIES})
find_package(Arrow QUIET)
find_package(Parquet QUIET)
else()
message(STATUS "Finding Parquet without package managers")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")

find_package(Arrow CONFIG QUIET)
find_package(Parquet CONFIG QUIET)
endif()

if(ARROW_FOUND AND PARQUET_FOUND)

if(Arrow_FOUND)
message(STATUS "[Parquet] found")
include_directories( ../
${ARROW_INCLUDE_DIR}
${PARQUET_INCLUDE_DIR} )
Expand All @@ -25,14 +35,14 @@ if(ARROW_FOUND AND PARQUET_FOUND)
target_link_libraries(DataLoadParquet
${Qt5Widgets_LIBRARIES}
${Qt5Xml_LIBRARIES}
arrow
parquet
${PARQUET_LIBRARIES}
plotjuggler_base)


install(TARGETS DataLoadParquet DESTINATION ${PJ_PLUGIN_INSTALL_DIRECTORY} )

else()
message("[libparquet-dev] not found. Skipping plugin DataLoadParquet.")
message("[Parquet] not found. Skipping plugin DataLoadParquet.")
endif()


19 changes: 11 additions & 8 deletions plotjuggler_plugins/DataStreamMQTT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
cmake_minimum_required(VERSION 3.10.2)

find_package(mosquitto QUIET)

find_path(MOSQUITTO_INCLUDE_DIR mosquitto.h)
find_library(MOSQUITTO_LIBRARY NAMES libmosquitto mosquitto)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MOSQUITTO DEFAULT_MSG MOSQUITTO_LIBRARY MOSQUITTO_INCLUDE_DIR)
if(mosquitto_LIBRARIES)

if(MOSQUITTO_FOUND)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
find_package(mosquitto QUIET)
else()
set(mosquitto_FOUND True)
endif()

set(MOSQUITTO_LIBRARIES ${MOSQUITTO_LIBRARY})
if(mosquitto_FOUND)

message(STATUS "[MOSQUITTO] found.")
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)

Expand All @@ -28,9 +31,9 @@ if(MOSQUITTO_FOUND)

target_link_libraries(DataStreamMQTT_Mosquitto
${Qt5Widgets_LIBRARIES}
${MOSQUITTO_LIBRARIES}
Qt5::Network
Qt5::Svg
${MOSQUITTO_LIBRARIES}
plotjuggler_base
)
target_include_directories(DataStreamMQTT_Mosquitto
Expand All @@ -40,7 +43,7 @@ if(MOSQUITTO_FOUND)
DESTINATION ${PJ_PLUGIN_INSTALL_DIRECTORY} )

else()
message("[libmosquitto-dev] not found. Skipping plugin DataStreamMQTT.")
message("[MOSQUITTO] not found. Skipping plugin DataStreamMQTT.")
endif()


28 changes: 28 additions & 0 deletions plotjuggler_plugins/DataStreamMQTT/cmake/Findmosquitto.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# - Find libmosquitto
# Find the native libmosquitto includes and libraries
#
# mosquitto_INCLUDE_DIR - where to find mosquitto.h, etc.
# mosquitto_LIBRARIES - List of libraries when using libmosquitto.
# mosquitto_FOUND - True if libmosquitto found.

if (NOT mosquitto_INCLUDE_DIR)
find_path(mosquitto_INCLUDE_DIR mosquitto.h)
endif()

if (NOT mosquitto_LIBRARY)
find_library(
mosquitto_LIBRARY
NAMES mosquitto)
endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
MOSQUITTO DEFAULT_MSG
mosquitto_LIBRARY mosquitto_INCLUDE_DIR)

message(STATUS "libmosquitto include dir: ${MOSQUITTO_INCLUDE_DIR}")
message(STATUS "libmosquitto: ${MOSQUITTO_LIBRARY}")
set(mosquitto_LIBRARIES ${mosquitto_LIBRARY})

mark_as_advanced(mosquitto_INCLUDE_DIR mosquitto_LIBRARIES)
21 changes: 14 additions & 7 deletions plotjuggler_plugins/DataStreamZMQ/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(BUILDING_WITH_VCPKG)
message(STATUS "Finding ZeroMQ with vcpkg")
set(ZeroMQ_LIBRARIES libzmq libzmq-static)
elseif(BUILDING_WITH_CONAN)
message(STATUS "Finding ZeroMQ with conan")
set(ZeroMQ_LIBRARIES libzmq-static)
else()
message(STATUS "Finding ZeroMQ without package managers")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
endif()

find_package(ZeroMQ QUIET)

if(ZMQ_FOUND)
if(ZeroMQ_FOUND)

message(STATUS "ZMQ_FOUND")
message(STATUS "ZMQ_FOUND")
message(STATUS "[ZeroMQ] found")

include_directories(../ ${ZeroMQ_INCLUDE_DIR})

Expand All @@ -22,11 +29,11 @@ if(ZMQ_FOUND)
target_link_libraries(DataStreamZMQ
${Qt5Widgets_LIBRARIES}
plotjuggler_base
${ZeroMQ_LIBRARY}
${ZeroMQ_LIBRARIES}
)

install(TARGETS DataStreamZMQ DESTINATION ${PJ_PLUGIN_INSTALL_DIRECTORY} )
else()
message("[libzmq-dev] not found. Skipping plugin DataStreamZMQ.")
message("[ZeroMQ] not found. Skipping plugin DataStreamZMQ.")
endif()

Loading

0 comments on commit 0589417

Please sign in to comment.