Currently, the main target operating systems are GNU/Linux distributions.
There are, however, no platform-specific components in viren2d and all
dependencies and build tools are available for Unix, Mac and Windows.
Please let me know if you’ve set it up on any other platform, so I can update
the installation instructions accordingly.
Important
Windows: There is no official CMake package configuration for Cairo and
the one included withviren2d uses a hard-coded search path, i.e.${CMAKE_CURRENT_LIST_DIR}/libs/cairo-windows. You will have to adjust
this path or use your own FindCairo.cmake.
If you find a simple setup/build workflow for Windows, please drop me a line
or consider creating a PR
to update the installation instructions for future users.
Important
Ubuntu: If you run Ubuntu<=18.04, you need to install CMake via
Kitware’s APT repository. The default
software repository is stuck at CMake version 3.10.
From Ubuntu 20.04 on, everything works out-of-the-box. Note, however,
that tests are only run on the LTS versions.
Most internal dependencies are automatically set up by the library’s
CMake-based build pipeline. Nevertheless, the basic build environment, Cairo
and Eigen3 must be set up manually:
Currently, there are no viren2d packages - thus, you need the
Cairo development packages (-dev or -devel) for your system. For
example, on GNU/Linux distributions, you simply install Cairo via:
Additional requirements to build the optional Python bindings:
Python >= 3.6, along with its development
library, i.e. system package python3-dev on Linux/macOS.
On Windows, please follow the setup instructions of
pybind11.
If all requirements are installed, the simplest way to install viren2d is
to use the default package manager, pip, which supports installation
directly from the github repository:
Set up a virtual environment with up-to-date pip.
To verify the installation, you can optionally run the following copy-pastable
example. Note that this additionally requires Pillow package, which can be installed via:
1importnumpyasnp 2importviren2d 3fromPILimportImage 4 5# Set up a white canvas: 6width,height=400,50 7painter=viren2d.Painter(width=width,height=height,color='#1a1c1d') 8 9# Draw "Hello World":10text_style=viren2d.TextStyle(11family='sans-serif',size=35,color='#c0bab1',bold=True)1213bbox=painter.draw_text(14text=['Hello World!'],position=(width/2,height/2),15anchor='center',text_style=text_style)1617# Draw markers to the left & right:18marker_style=viren2d.MarkerStyle(19marker='5',size=30,filled=True,color='midnight-blue',20bg_border=2,bg_color='ivory')2122painter.draw_marker(23position=(bbox.cx-bbox.width/2-35,height/2),24marker_style=marker_style)25painter.draw_marker(26position=(bbox.cx+bbox.width/2+35,height/2),27marker_style=marker_style)2829# Display the image:30shared_canvas_np=np.array(painter.canvas,copy=False)31image=Image.fromarray(shared_canvas_np)32image.show()
The recommended way of integrating viren2d in your application is via
CMake’s FetchContent module,
as shown below:
Exemplary CMakeLists.txt to integrate viren2d via CMake’s FetchContent module.
1# viren2d requires at least C++14 2set(CMAKE_CXX_STANDARD14) 3 4# Let CMake download and set up the viren2d dependency 5include(FetchContent) 6FetchContent_Declare( 7viren2d 8GIT_REPOSITORYhttps://github.com/snototter/viren2d.git 9GIT_TAGmain)10FetchContent_MakeAvailable(viren2d)1112# Create the demo executable13add_executable(hello-world14${CMAKE_CURRENT_LIST_DIR}/hello_world.cpp)1516# Add the viren2d dependency (include paths will be set up automatically)17target_link_libraries(hello-worldPRIVATEviren2d++::viren2d++)
For the corresponding demo application, refer to the
C++ hello world example.
To build this standalone demo, only the C++ source file and the example’s
CMakeLists.txt are needed. FetchContent will download and set up all
dependencies as needed.
For example, if these two files are placed in a hello-world-example
folder, a classical CMake build would look like:
cd hello-world-examplemkdir && cd buildcmake ..cmake --build ../hello-world