Package: cpplib
C++ and Python LibraryThis is a template repository used to create  C++/Python libraries. This is for individuals who want to write astandaloneC++ library that canalsobe bound to Python usingPybind11for better performance. This repository additionally takes care of the intricate world of buildingbinarywheels automatically and publishing to PyPI, including linux and windows. I have tried my best to use good tools and practices in this repo to provide a clean codebase for others to start their project on. What you see in this repo is not all my work, but lessons/code I have learned after observingothers work.Key FeaturesC++ Library is independent of Python Extension, i.e. can be dropped into pure C++ projects.Cross platform using Modern CMake.Benchmark (Nanobench) and Testing (doctest) built in.Good handling of thirdparty dependencies using CMakeFetchContent.Documentation for both C++ and Python created using Sphinx, Doxygen, Breathe, and Exhale. The documentation is unified into one website.Integration of CMake intosetup.pyso thatpip installworks for python users wanting to build manually (CMake must be installed still).Note that the C++ Library and even the python extension can still be built with standard CMake procedures, seeBuild with CMakeAutomatic building of pythonbinarywheels usinggithub actions, seeWorkflowThis repo relies upon using Modern CMake to build both the C++ and Python Extension libraries. I find that integrating it all in CMake leads to a much nicerdeveloperexperience. External usersbuildingthe library will need CMake installed which may be a consideration before using this template repo as a starting point. However, this repo has a github workflow setup to automatically build pythonbinarywheels for you and upload to PyPI for a variety of python versions/OS/architectures! Please seeworkflowsInstructions For Using Templategit clone https://github.com/JeremyBYU/cpp-pybind-skel.gitRename FilesYou will want to rename files and library names with a simplefind and replaceusing your IDE/editor. Lets say you named your projectSimpleImageFilterswith an associates short acronym ofSIF. Then simply find and replace in this repository the following (case sensitivity matters):CPPLib->SimpleImageFilters- C++ Top Namespace and CMake Project NameCPPLIB->SIMPLEIMAGEFILTERS- Same but uppercase, used in CMakeCPPL->SIF- Acronym used in CMake alias for projectcpplib->simpleimagefilters- Python Library Extension NameA helper python script,rename_project.pyis provided if desired. I would recommend using it because it saves a lot of time.Note: you don't have to use the naming convention proposed above and may use any you would like. I think the most important thing is simply that the Python extension target is different then C++ library target.Build Project ManuallyYou can build the project manually in two ways: one in pure CMake, the other using pythonsetup.py.Build Manually With CMakeBuilding happens entirely with CMake. This is meant really only for the library developers who are working on C++ and Python in an edit-compile cycle.C++ Librarymkdir cmake-build && cd cmake-buildcmake ..-  Note - For windows also add-DCMAKE_GENERATOR_PLATFORM=x64cmake --build . -j$(nproc) --config ReleaseBuild options:CPPL_BUILD_BENCHMARKS:BOOL=ON // CPPL - Build Benchmarks
CPPL_BUILD_EXAMPLES:BOOL=ON // CPPL - Build Examples
CPPL_BUILD_PYMODULE:BOOL=ON // CPPL -Build Python Module
CPPL_BUILD_TESTS:BOOL=ON // CPPL - Build Tests
CPPL_BUILD_WERROR:BOOL=OFF // CPPL - Add Werror flag to build (turns warnings into errors)
CPPL_WITH_OPENMP:BOOL=ON // CPPL - Build with OpenMP SupportPython ExtensionThis is meant for advanced python users who are actively developing the extension.Installcondaor create a python virtual environment (Why?). I recommend conda for Windows users.PerformCMakebuild as described abovecd cmake-build && cmake --build . --target python-package --config Releasecd lib/python_package &&  pip install -e .. This installs the library in develop/edit mode. To update the python extension in your python virtual environment all you need to do is run step 3 again.Note you can alternatively build usingPython setup.pyBuild Manually with PythonThe root directorysetup.pyfile has been modified to build with CMake. This is meant for python users that need to build manually (for some reason) but are not actively developing or changing the code.Installcondaor create a python virtual environment (Why?). I recommend conda for Windows users.pip install .- Call from root directoryThat should be it!Install with PythonIf you only care about installing the python extension you can install from the binary wheels generated by the github action workflows. The binary wheels are uploaded to PyPi. Therefore, after configuring the workflow and tagging a version, you can install as:pip install cpplib- Changecpplibto whatever your python extension will end up being.WorkflowsSeveral github action workflows are included in this repository. The first is the binary wheel creation and uploading to pypi.Binary WheelThisworkflow filegenerates the binary wheels and uploads to PyPI. You will need to configure your github repository with a token access to publish toPyPIandPyPITest. Please readhereabout what is expected. Note that this workflow only run on the master branch, and publishing only occurs on tagged releases.TestsAutomatic testing is also done using thistest workflow fileDocumentationC++ classes and functions are documented in their header files. Associated Python functions/classes which are bound with Pybind11 arere-documented. This is for two reasons:The function/class API might actually be slightly different in arguments and return types (e.g., list vs. std::vector) and more detail/nuance may be desired in one form of the other.I have no idea how to share them.For Python, I am using thismethodto inject further documentation into functions/classes which was developed byIntel at Open3D. They provide a function that can transform an inputmapof arg/description pairs and convert toGoogles Python Docstring format.Documentation Website GenerationDocumentation building has been taken from Open3D with some small modification. PythonandC++ documentation is generated usingSphinxinto thesamewebsite. The C++ API is actually integrated into sphinx usingbreathe/exhale. Please seedocs/builddocs.rst.Release StepsThese are the release steps that I perform to create a release.Make all necessary changespython scripts/manage_versions.py --bump patchpip install .cd src_docs && python make_docs.py && cd ..commit changespython scripts/manage_versions.py --taggit push origin dev --tagsFAQQ:ERROR: Could not install packages due to an EnvironmentErrorA:Remove thebuilddirectoryAcknowledgementsI have learned a lot by listening/watching/reading about C++. I can't list them all but the following links had the most influence in developing this repo.Open3D- Much of this repo comes from following their practices.  After having made many C++/Python projects I find this code structure to be the best for hybrid projects.Modern CMake- An invaluable resource which has taught me about CMake.Mapbox hpp-skel- A great starting point forheader-onlylibraries. Almost everything MapBox makes is gold to me.Parselmouth- A great resource on using github workflows!