Skip to content

Commit

Permalink
windows: added vcpkg setup and updated cmake to build on Windows system
Browse files Browse the repository at this point in the history
  • Loading branch information
rxdu committed Dec 19, 2024
1 parent f93715b commit 7aab5f2
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# vcpkg
vcpkg_installed

# Build temporary files
**build

# Visual Studio
.vs
CMakeSettings.json

# VSCode
.vscode

Expand Down
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,22 @@ endif ()
# include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
set(USER_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${USER_CMAKE_PATH}/modules")
list(APPEND CMAKE_PREFIX_PATH "/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/cmake")

if(WIN32)
## Windows support
message(STATUS "Building on Windows")
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE not specified, e.g. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake")
message(FATAL_ERROR "For example: -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake")
else()
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
endif()
else()
# Linux support
message(STATUS "Building on Linux by default")
list(APPEND CMAKE_PREFIX_PATH "/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/cmake")
endif()
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")

## Set compiler to use c++ 17 features
set(CMAKE_CXX_STANDARD 17)
Expand Down
67 changes: 58 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

![GitHub Workflow Status](https://github.com/rxdu/quickviz/workflows/default/badge.svg)

This repository provides a C++ framework for creating data visualization and basic GUI for robotics applications. The
core of the framework is a library named "imview". imview is designed to be flexible and lightweight.
This repository provides a collection of C++ libraries for creating data visualization and basic UI applications, primarily focused on use cases in robotics.

The core component of this codebase is a library called "imview", which is designed to be both flexible and lightweight:

* For data visualization, imview provides a set of API functions to easily plot 2D time-series data, draw 2D primitives
and render 3D objects. It can be used to visualize data in real-time.
* For GUI applications, imview provides automatic layout management and commonly used UI widgets such as buttons,
sliders, and text boxes.
and render 3D objects in real-time.
* For UI design, imview includes automatic layout management and widgets such as buttons, sliders, and text boxes.

An app named "quickviz" is provided with commonly used data visualization functions (to support development
of [libxmotion](https://github.com/rxdu/libxmotion)). It also serves as an example of how to use the imview library.
Design of imview is documented in [docs/imview_design.md](docs/imview_design.md). If you are interested in using the
imview library in your own project, it's recommended to read this design document first.
The design of imview is documented in [docs/imview_design.md](docs/imview_design.md). If you are interested in using the imview library in your
own project, it's recommended to read this design document first. Additionally, an app named "quickviz" is included with commonly used
data visualization functions (to support development of [libxmotion](https://github.com/rxdu/libxmotion)). It also serves as an example to demonstrate
the usage of the imview library.

## Build

### Linux

The code in this repository should build on any recent linux distributions with a compiler supporting C++11/14/17. Note
that the yoga library for layout management requires certain C++20 features, and you will need to disable automatic
layout feature if you are using an older compiler (such as the gcc that comes with Ubuntu 20.04 or older).
Expand Down Expand Up @@ -62,6 +64,53 @@ $ cmake ..
$ make -j8
```

### Windows

(Windows support is experimental and may not be as stable as the Linux setup.)

On Windows, vcpkg is used to manage dependencies. The following instructions are tested on Windows 11 with Visual Studio 2022.

**Setup toolchain**

* Install Visual Studio (MinGW is not tested and may not work)
* Install [git](https://gitforwindows.org/)
* Install [cmake](https://cmake.org/download/)

Make sure both git and cmake are added to the system PATH. This should be done automatically for you if you use an installer
with default installation settings. Otherwise, you can add the paths manually if you prefer installing them with binary archives.

**Install vcpkg**

Refer to the [vcpkg documentation](https://learn.microsoft.com/en-us/vcpkg/get_started/get-started?pivots=shell-bash) for more details.

```
$ git clone https://github.com/microsoft/vcpkg.git
$ cd vcpkg
$ .\bootstrap-vcpkg.bat # if you are using powershell
```

Make sure the following two environment variables are set:

```
export VCPKG_ROOT=/path/to/vcpkg
export PATH=$VCPKG_ROOT:$PATH
```

You can add the two variables in "Environment Variables" in Windows settings to make them persistent. Note that you should use
`%VCPKG_ROOT%` instead of `$VCPKG_ROOT` when appending it to the PATH variable.

**Build package**

Depending on the IDE you use, the configuration steps may vary.

For Visual Studio, open "Build"-"Cmake Settings for quickfiz" and add the following line to "CMake command arguments":

```
-DCMAKE_TOOLCHAIN_FILE=<your-vcpkg-path>/scripts/buildsystems/vcpkg.cmake
```

Then you should be able to configure and build the project successfully.

## Reference

The library is built on top of a few third-party libraries, you can refer to their documentation for more details:
Expand Down
2 changes: 1 addition & 1 deletion src/cvdraw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target_include_directories(cvdraw PUBLIC
PRIVATE src)

# Add executables
if(BUILD_TESTS)
if(BUILD_TESTING)
add_subdirectory(test)
endif()

Expand Down
4 changes: 4 additions & 0 deletions src/cvdraw/src/cv_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <cmath>
#include <cassert>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

namespace quickviz {
using namespace cv;

Expand Down
8 changes: 4 additions & 4 deletions src/cvdraw/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

## tests
add_executable(test_image_rw test_image_rw.cpp)
target_link_libraries(test_image_rw cvdraw)
target_link_libraries(test_image_rw PUBLIC cvdraw)

add_executable(test_cv_canvas test_cv_canvas.cpp)
target_link_libraries(test_cv_canvas cvdraw)
target_link_libraries(test_cv_canvas PUBLIC cvdraw)

add_executable(test_cv_drawmode test_cv_drawmode.cpp)
target_link_libraries(test_cv_drawmode cvdraw)
target_link_libraries(test_cv_drawmode PUBLIC cvdraw)

add_executable(test_cv_drawfunc test_cv_drawfunc.cpp)
target_link_libraries(test_cv_drawfunc cvdraw)
target_link_libraries(test_cv_drawfunc PUBLIC cvdraw)
2 changes: 1 addition & 1 deletion src/imview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ add_library(imview
target_link_libraries(imview PUBLIC imcore
PkgConfig::Cairo PkgConfig::Fontconfig
Threads::Threads
OpenGL::OpenGL
OpenGL::GL
${AUTO_LAYOUT_LIBS}
${OpenCV_LIBS})
if (ENABLE_AUTO_LAYOUT)
Expand Down
4 changes: 4 additions & 0 deletions src/imview/src/component/cairo_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include <cmath>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

namespace quickviz {
void DrawPoint(cairo_t *cr, ImVec2 pos, double size, ImVec4 color) {
cairo_set_source_rgba(cr, color.x, color.y, color.z, color.w);
Expand Down
4 changes: 4 additions & 0 deletions src/imview/test/feature/test_cairo_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "imview/viewer.hpp"
#include "imview/widget/cairo_widget.hpp"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

using namespace quickviz;

void PaintUnifiedCoordinate(cairo_t* cr, float aspect_ratio) {
Expand Down
2 changes: 1 addition & 1 deletion src/third_party/glad/include/glad/glad.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void);

GLAPI int gladLoadGLLoader(GLADloadproc);

#include <KHR/khrplatform.h>
#include <glad/khrplatform.h>
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;
Expand Down
13 changes: 13 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dependencies": [
"pkgconf",
"glfw3",
"opengl",
"glm",
{
"name": "cairo",
"features": ["fontconfig"]
},
"opencv4"
]
}

0 comments on commit 7aab5f2

Please sign in to comment.