From 2504bafc9eb7e42520ebd33a32d44203cb43bcce Mon Sep 17 00:00:00 2001 From: wqking Date: Fri, 2 Feb 2024 11:34:47 +0800 Subject: [PATCH] Extracted install instructions to separate document. Added Conan usage. --- doc/install.md | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 72 ++--------------------------- 2 files changed, 126 insertions(+), 67 deletions(-) create mode 100644 doc/install.md diff --git a/doc/install.md b/doc/install.md new file mode 100644 index 0000000..035ab5a --- /dev/null +++ b/doc/install.md @@ -0,0 +1,121 @@ +# Install and use eventpp in your project + +- [Install and use eventpp in your project](#install-and-use-eventpp-in-your-project) + - [Include the source code in your project directly](#include-the-source-code-in-your-project-directly) + - [Use CMake FetchContent](#use-cmake-fetchcontent) + - [Use Vcpkg package manager](#use-vcpkg-package-manager) + - [Use Conan package manager](#use-conan-package-manager) + - [Use Hunter package manager](#use-hunter-package-manager) + - [Install using CMake locally and use it in CMake](#install-using-cmake-locally-and-use-it-in-cmake) + +`eventpp` package is available in C++ package managers Vcpkg, Conan, and Hunter. +`eventpp` is header only and not requires building. There are various methods to use `eventpp`. +Here lists all possible methods to use `eventpp`. + +## Include the source code in your project directly + +eventpp is header only library. Just clone the source code, or use git submodule, then add the 'include' folder inside eventpp to your project include directory, then you can use the library. +You don't need to link to any source code. + +## Use CMake FetchContent + +Add below code to your CMake file + +``` +include(FetchContent) +FetchContent_Declare( + eventpp + GIT_REPOSITORY https://github.com/wqking/eventpp + GIT_TAG d2db8af2a46c79f8dc75759019fba487948e9442 # v0.1.3 +) +FetchContent_MakeAvailable(eventpp) +``` + +Then `eventpp` is available to your project. If `GIT_TAG` is omitted, the latest code on master branch will be used. + +## Use Vcpkg package manager + +``` +vcpkg install eventpp +``` + +Then in your CMake project CMakeLists.txt file, put below code, remember to replace ${TARGET} with your target, + +``` +find_package(eventpp CONFIG REQUIRED) +target_link_libraries(${TARGET} PRIVATE eventpp::eventpp) +find_path(EVENTPP_INCLUDE_DIR eventpp/eventqueue.h) +include_directories(${EVENTPP_INCLUDE_DIR}) +``` + +Then run cmake, note you need -DCMAKE_TOOLCHAIN_FILE to specify vcpkg, and replace -G with your generator +``` +cmake .. -DCMAKE_TOOLCHAIN_FILE=VCPKGDIR/vcpkg/scripts/buildsystems/vcpkg.cmake -G"MinGW Makefiles" +``` + +Note with vcpkg, only the released version can be used, which may be behind the latest update. You can't use the minor update on the master branch. + +## Use Conan package manager + +In your CMake project, add a conanlist.txt file that should contain, + +``` +[requires] +eventpp/0.1.3 + +[generators] +CMakeDeps +CMakeToolchain +``` + +Then in your CMakeLists, add, + +``` +find_package(eventpp CONFIG REQUIRED) +target_link_libraries(${TARGET} PRIVATE eventpp::eventpp) +``` + +Then run `conan install . --output-folder=build --build=missing` in your project folder (assuming the default conan profile exists and is okay). +Then cd into folder build, run `cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -G "Whatever generator you want" -DCMAKE_BUILD_TYPE=Release`, alternatively it can also use cmake presets instead of passing the toolchain file on cmake >=3.23 + +There are [more information here](https://github.com/wqking/eventpp/issues/70). + +## Use Hunter package manager + +You may follow the example code on [Hunter document](https://hunter.readthedocs.io/en/latest/packages/pkg/eventpp.html). Below is the code snippet from that document, + +``` +hunter_add_package(eventpp) +find_package(eventpp CONFIG REQUIRED) + +add_executable(main main.cpp) +target_link_libraries(main eventpp::eventpp) +include_directories(${EVENTPP_INCLUDE_DIR}) +``` + +## Install using CMake locally and use it in CMake + +Note: this is only an alternative, you should use the FetchContent method instead of this. +If you are going to use eventpp in CMake managed project, you can install eventpp then use it in CMake. +In eventpp root folder, run the commands, +``` +mkdir build +cd build +cmake .. +sudo make install +``` + +Then in the project CMakeLists.txt, +``` +# the project target is mytest, just for example +add_executable(mytest test.cpp) + +find_package(eventpp) +if(eventpp_FOUND) + target_link_libraries(mytest eventpp::eventpp) +else(eventpp_FOUND) + message(FATAL_ERROR "eventpp library is not found") +endif(eventpp_FOUND) +``` + +Note: when using the method 3 with MingW on Windows, by default CMake will install eventpp in system folder which is not writable. You should specify another folder to install. To do so, replace `cmake ..` with `cmake .. -DCMAKE_INSTALL_PREFIX="YOUR_NEW_LIB_FOLDER"`. diff --git a/readme.md b/readme.md index ccae83a..811a22e 100644 --- a/readme.md +++ b/readme.md @@ -88,73 +88,8 @@ In brief, MSVC, GCC, Clang that has well support for C++11, or released after 20 ### Use eventpp in your project -There are various methods to use eventpp - -1, Include the source code in your project directly. - -eventpp is header only library. Just clone the source code, then add the 'include' folder inside eventpp to your project include directory, then you can use the library. -You don't need to link to any source code. - -2, Or use vcpkg - -``` -vcpkg install eventpp -``` - -Then in your project CMakeLists.txt file, put below code, remember to replace ${TARGET} with your target, - -``` -find_package(eventpp CONFIG REQUIRED) -target_link_libraries(${TARGET} PRIVATE eventpp::eventpp) -find_path(EVENTPP_INCLUDE_DIR eventpp/eventqueue.h) -include_directories(${EVENTPP_INCLUDE_DIR}) -``` - -Then run cmake, note you need -DCMAKE_TOOLCHAIN_FILE to specify vcpkg, and replace -G with your generator -``` -cmake .. -DCMAKE_TOOLCHAIN_FILE=VCPKGDIR/vcpkg/scripts/buildsystems/vcpkg.cmake -G"MinGW Makefiles" -``` - -Note with vcpkg, only the released version can be used, which may be behind the latest update. You can't use the minor update on the master branch. - -3, Or install using CMake and use it in CMake - -If you are going to use eventpp in CMake managed project, you can install eventpp then use it in CMake. -In eventpp root folder, run the commands, -``` -mkdir build -cd build -cmake .. -sudo make install -``` - -Then in the project CMakeLists.txt, -``` -# the project target is mytest, just for example -add_executable(mytest test.cpp) - -find_package(eventpp) -if(eventpp_FOUND) - target_link_libraries(mytest eventpp::eventpp) -else(eventpp_FOUND) - message(FATAL_ERROR "eventpp library is not found") -endif(eventpp_FOUND) -``` - -Note: when using the method 3 with MingW on Windows, by default CMake will install eventpp in system folder which is not writable. You should specify another folder to install. To do so, replace `cmake ..` with `cmake .. -DCMAKE_INSTALL_PREFIX="YOUR_NEW_LIB_FOLDER"`. - -4, If you use Hunter package manager - -You may follow the example code on [Hunter document](https://hunter.readthedocs.io/en/latest/packages/pkg/eventpp.html). Below is the code snippet I grabbed from that link, - -``` -hunter_add_package(eventpp) -find_package(eventpp CONFIG REQUIRED) - -add_executable(main main.cpp) -target_link_libraries(main eventpp::eventpp) -include_directories(${EVENTPP_INCLUDE_DIR}) -``` +`eventpp` package is available in C++ package managers Vcpkg, Conan, and Hunter. There are various methods to use eventpp. +Please [read the document](doc/install.md) for details. ### Using CallbackList ```c++ @@ -209,6 +144,8 @@ queue.process(); ## Documentations +* Setup + * [Install and use eventpp in your project](doc/install.md) * Core classes and functions * [Overview](doc/introduction.md) * [Tutorials of CallbackList](doc/tutorial_callbacklist.md) @@ -321,6 +258,7 @@ Added CallbackList, EventDispatcher, EventQueue, CounterRemover, ConditionalRemo sr-treamsr-tream Drise13Drise13 iamzoneiamzone +RazielXYZRazielXYZ