diff --git a/.gitignore b/.gitignore index 2140bbb5..f74a01fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ +.hrefs .rtags build/ **/#*# dependencies/* extern/* tests/benchmarks_parameters.hpp +**/vcpkg_installed # ides .vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 44235b6b..d44e66b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/examples/README.cpp b/examples/README.cpp index aa9bbf3d..1c39219f 100644 --- a/examples/README.cpp +++ b/examples/README.cpp @@ -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) @@ -194,46 +194,40 @@ 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 @@ -241,24 +235,26 @@ 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, diff --git a/examples/README.md b/examples/README.md index 5666ecb1..733b89d1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,12 +1,12 @@ # Examples -* [accept_no_visitors](accept_no_visitors.cpp) +* [accept_no_visitors](accept_no_visitors.cpp)
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)
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 @@ -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)
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)
+Demonstrates how to use YOMM2 in a cmake project. +* [dl_main](dl_main.cpp), [dl_shared](dl_shared.cpp)
+Demonstrates how to dynamically load new classes and method definitions. -* [matrix](matrix.cpp) +* [matrix](matrix.cpp)
Another example of double dispatch. - -* [next](next.cpp) +* [next](next.cpp)
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)
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. diff --git a/examples/vcpkg/CMakeLists.txt b/examples/vcpkg/CMakeLists.txt new file mode 100644 index 00000000..11e1aa77 --- /dev/null +++ b/examples/vcpkg/CMakeLists.txt @@ -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) diff --git a/examples/vcpkg/adventure.cpp b/examples/vcpkg/adventure.cpp new file mode 120000 index 00000000..aa26a623 --- /dev/null +++ b/examples/vcpkg/adventure.cpp @@ -0,0 +1 @@ +../adventure.cpp \ No newline at end of file diff --git a/examples/vcpkg/vcpkg.json b/examples/vcpkg/vcpkg.json new file mode 100644 index 00000000..f7d95f85 --- /dev/null +++ b/examples/vcpkg/vcpkg.json @@ -0,0 +1,5 @@ +{ + "dependencies": [ + "yomm2" + ] +}