Skip to content

Commit

Permalink
vcpkg example
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Apr 21, 2024
1 parent 3f359b0 commit 485ba96
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.hrefs
.rtags
build/
**/#*#
dependencies/*
extern/*
tests/benchmarks_parameters.hpp
**/vcpkg_installed

# ides
.vscode/
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

cmake_minimum_required(VERSION 3.20)
cmake_policy(SET CMP0057 NEW)
project(YOMM2 VERSION 1.5.0)
project(YOMM2 LANGUAGES CXX VERSION 1.5.0)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
Expand Down
60 changes: 28 additions & 32 deletions examples/README.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Stroustrup.
- [Cross-cutting Concerns and the Expression Problem](#cross-cutting-concerns-and-the-expression-problem)
- [Multiple Dispatch](#multiple-dispatch)
- [Performance](#performance)
- [Building and Installing](#building-and-installing)
- [Installation](#installation)
- [Going Further](#going-further)
- [Roadmap](#roadmap)
Expand Down Expand Up @@ -194,71 +194,67 @@ unnoticeable.
[`virtual_ptr`](https://jll63.github.io/yomm2/reference/virtual_ptr.md), a fat
pointer class, can be used to make method dispatch even faster - three
instructions and two memory reads -, without sacrificing orthogonality.
instructions and two memory reads.
[Examples](ce/README.md) are available on Compiler Explorer.
## Building and Installing
## Installation
Make sure that you have the following dependencies:
YOMM2 is available as a `vcpkg` package. This is the easiest way of integrating
it in your project. Just add `yomm2` as a dependency in your `vcpkg.json` - see
[this example](`examples/vcpkg`).
* a C++17 capable compiler
YOMM2 can also be built and installed from the sources, using straight `cmake`.
* cmake version 3.20 or above
Clone the repository:
First clone the repository:
```
git clone https://github.com/jll63/yomm2.git
cd yomm2
```
Create a build directory and run cmake then make:
Run cmake:
```
mkdir build
cd build
cmake ..
make
cmake -S yomm2 -B build.yomm2
```
If you want to run the tests, specify it when running `cmake`:
```
cmake .. -DYOMM2_ENABLE_TESTS=1
make && ctest
cmake -S yomm2 -B build.yomm2 -DYOMM2_ENABLE_TESTS=1
ctest --test-dir build.yomm2
```
YOMM2 uses several Boost libraries:
1. Preprocessor, DynamicBitset, TypeTraits: included by YOMM2 headers
2. Boost.Test: only used to run the test suite
* Preprocessor, DynamicBitset, TypeTraits: included by YOMM2 headers
* Boost.Test: only used to run the test suite
If these libraries are already available on your machine, and they can be
found by `cmake`, they will be used. In this case, make sure that the
pre-installed libraries are at version 1.74 or above. If Boost is not found,
the latest version will be downloaded, and the Boost headers mentioned in
section (1) will be installed along YOMM2 (if you decide to `make install`).
If you also want to run the benchmarks (and in this case you really want a
release build):
If you want to run the benchmarks (and in this case you really want a release
build):
```
cmake -S yomm2 -B build.yomm2 -DYOMM2_ENABLE_TESTS=1 -DYOMM2_ENABLE_BENCHMARKS=1 -DCMAKE_BUILD_TYPE=Release
./build.yomm2/tests/benchmarks
```
The benchmarks use the [Google benchmark](https://github.com/google/benchmark)
library. Again, if it is not found, it will be built from its source.
If you like YOMM2, and you want to install it, either system-wide:
```
cmake .. -DYOMM2_ENABLE_TESTS=1 -DYOMM2_ENABLE_BENCHMARKS=1 -DCMAKE_BUILD_TYPE=Release
make && tests/benchmarks
sudo cmake --install build.yomm2
```
This will automatically download the dependency
[benchmark](https://github.com/google/benchmark), build it and finally install
it to `./extern` within the root directory of yomm2.
If you like YOMM2, and you want to install it:
...or to a specific directory:
```
# either:
sudo make install
# or:
make install DESTDIR=/path/to/my/libs
DESTDIR=/path/to/my/libs cmake --install build.yomm2
```
This will install the headers and a CMake package configuration. By default,
Expand Down
24 changes: 12 additions & 12 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Examples

* [accept_no_visitors](accept_no_visitors.cpp)
* [accept_no_visitors](accept_no_visitors.cpp)<br/>
Inspired by [a talk by Yuriy
Solodkyy](https://www.youtube.com/watch?v=QhJguzpZOrk&t=1467s), this example
shows how open methods are better than visitor at traversing ASTs.


* [adventure](adventure.cpp)
* [adventure](adventure.cpp)<br/>
Yes, YOMM2 methods can have more than two virtual parameters. This example is
inspired by a scene from[Colossal Cave
Adventure](https://en.wikipedia.org/wiki/Colossal_Cave_Adventure), where a
Expand All @@ -17,30 +17,30 @@ shows how open methods are better than visitor at traversing ASTs.
- CONGRATULATIONS! YOU HAVE JUST VANQUISHED A DRAGON WITH YOUR BARE HANDS!
(UNBELIEVABLE, ISN'T IT?)

* [cmakeyomm2](cmakeyomm2)
Demonstrates how to use YOMM2 in a cmake project.

* [asteroids](asteroids.cpp)
* [asteroids](asteroids.cpp)<br/>
Many explanations of multi-methods use the
[Asteroids](https://en.wikipedia.org/wiki/Asteroids_(video_game)) video game as
an example. Here is the YOMM2 version.

* [vcpkg](vcpkg)
Demonstrates how to use YOMM2 with vcpkg.

* [dl_main](dl_main.cpp), [dl_shared](dl_shared.cpp)
Demonstrates how to dynamically load new classes and method definitions.
* [cmakeyomm2](cmakeyomm2)<br/>
Demonstrates how to use YOMM2 in a cmake project.

* [dl_main](dl_main.cpp), [dl_shared](dl_shared.cpp)<br/>
Demonstrates how to dynamically load new classes and method definitions.

* [matrix](matrix.cpp)
* [matrix](matrix.cpp)<br/>
Another example of double dispatch.


* [next](next.cpp)
* [next](next.cpp)<br/>
Demonstrates how a method definition can call the next most specialised
definition. This is similar to a virtual function override calling the base
version of the function, or calling `super` in languages like Smalltalk or
Python.

* [synopsis](synopsis.cpp)
* [synopsis](synopsis.cpp)<br/>
A heavily annotated example, for people who prefer to learn by reading code,
not documentation. At the bottom of the file, the assembler code generated for
calling 1- and a 2-virtual argument methods is listed and commented.
11 changes: 11 additions & 0 deletions examples/vcpkg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)

project(adventure CXX)

find_package(YOMM2 CONFIG REQUIRED)

set(CMAKE_CXX_STANDARD 17)

add_executable(adventure adventure.cpp)

target_link_libraries(adventure PRIVATE YOMM2::yomm2)
1 change: 1 addition & 0 deletions examples/vcpkg/adventure.cpp
5 changes: 5 additions & 0 deletions examples/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"yomm2"
]
}

0 comments on commit 485ba96

Please sign in to comment.