diff --git a/.gitignore b/.gitignore index 9546300..78f7148 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1,4 @@ # These are directories used by IDEs for storing settings .idea/ .vscode/ - -# These are common build directory names -build*/ -docs/build -docs/source/_build -docs/doxyoutput -docs/source/api -*-build-*/ -_build/ -Debug/ -Release/ - -# Users commonly store their specific CMake settings in a toolchain file -toolchain.cmake - -# Users often install under the root directory -install/ \ No newline at end of file +*.zip \ No newline at end of file diff --git a/README.md b/README.md index e72624d..8f36dd1 100644 --- a/README.md +++ b/README.md @@ -4,41 +4,54 @@ Plugin Template This repository is intended to be used as a quickstart for writing a plugin library consistent with [PluginPlay](https://github.com/NWChemEx/PluginPlay). -The primary contents of this repo are as follows: -- `README.md` - This file. -- `setup_new_plugin.sh` - The main component of this repo, used to generate the - starting files for the new plugin. More on this below. -- `cmake/get_cmaize.cmake` - A CMake function to retrieve and include the - [CMaize](https://github.com/CMakePP/CMaize) library. -- `CMakeLists.txt` - The CMakeLists file for the new plugin produced by the - running `setup_new_plugin.sh`. - ## Generating the New Plugin -After cloning this repo, the first step is to run `setup_new_plugin.sh`. The -name of the new plugin (`plugin_name`) can either be passed as an argument when -the script is called or you will be prompted for the name when the script runs. -After running the script, eight files should be produced: -- `plugin_name.txt` - Holds the name of the plugin. Used by `CMakeLists.txt`. + +This template is generated with the +[Cookiecutter](https://github.com/cookiecutter/cookiecutter) package: + +```bash +# Install cookiecutter, if not already +$ pip install cookiecutter +# Generate the template +$ cookiecutter https://github.com/NWChemEx/PluginTemplate.git +``` +Follow the resulting to prompts to generate your plugin. The resulting directory +will contain the following: - `version.txt` - Holds the version of the plugin. Used by `CMakeLists.txt`. -- `toolchain.cmake` - A simple CMake toolchain. Ignored by Git. +- `default_toolchain.cmake` - A simple CMake toolchain. Ignored by Git. - `include/{plugin_name}/{plugin_name}.hpp` - An initial courtesy header file. -- `include/{plugin_name}/{plugin_name}_mm.hpp` - A header file declaring the -`load_modules` function of the plugin. -- `src/{plugin_name}/{plugin_name}_mm.cpp` - A source file defining the -`load_modules` function of the plugin. +- `include/{plugin_name}/{plugin_name}_mm.hpp` - A header file declaring the plugin. +- `src/{plugin_name}/{plugin_name}_mm.cpp` - A source file defining the the plugin. - `tests/unit_tests/test_main.cpp` - A main source file for a Catch2 test. -- `tests/unit_tests/test_load_modules.cpp` - A source file for a test of the -`load_modules` function. +- `tests/unit_tests/test_load_modules.cpp` - A source file for a test of the `load_modules` function. These files constitute a bare plugin library and a simple test for the -`load_modules` function. New modules and property types shoudl be added and -registered following the [PluginPlay tutorials](https://nwchemex.github.io/PluginPlay/tutorials/index.html). +`load_modules` function. New modules and property types can be added and +registered following the [PluginPlay tutorials](https://nwchemex.github.io/PluginPlay/tutorials/index.html).You can configure, build, and test the new plugin as follows: -## Clean-Up -Once the new plugin has been generated, the developers will want to change the -git `origin` associated with the repo to one corresponding to the new plugin. -This is accomplished with the command +```bash +$ cmake -Bbuild -H. -DCMAKE_TOOLCHAIN_FILE=./default_toolchain.cmake -DCMAKE_INSTALL_PREFIX=./install +$ cmake --build build --parallel 2 +$ cd build +$ ctest -VV ``` -git remote set-url origin {your_url_here} + +At this point, you can initialize git and set up remotes: + +```bash +$ git init +$ git add . +$ git commit -m "Initial State" +$ git remote add origin {Your Remote Repo} +$ git push -u origin master ``` -Also, this markdown file should be modified to represent the new plugin. \ No newline at end of file + +# Contributing + +- [Contributor Guidelines](https://github.com/NWChemEx/.github/blob/1a883d64519f62da7c8ba2b28aabda7c6f196b2c/.github/CONTRIBUTING.md) +- [Contributor License Agreement](https://github.com/NWChemEx/.github/blob/master/.github/CONTRIBUTING.md#contributor-license-agreement-cla) +- [Code of Conduct](https://github.com/NWChemEx/.github/blob/master/.github/CODE_OF_CONDUCT.md) + +# Acknowledgments + +Add... \ No newline at end of file diff --git a/cookiecutter.json b/cookiecutter.json new file mode 100644 index 0000000..1188dc6 --- /dev/null +++ b/cookiecutter.json @@ -0,0 +1,4 @@ +{ + "project_name": "New Plugin", + "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '_') }}" +} \ No newline at end of file diff --git a/setup_new_plugin.sh b/setup_new_plugin.sh deleted file mode 100755 index d9ea0ee..0000000 --- a/setup_new_plugin.sh +++ /dev/null @@ -1,126 +0,0 @@ -#!/bin/sh - -# This script sets up a new plugin with the input name -# -# Usage: -# setup_new_plugin.sh [plugin_name] -# - -################### -## Plugin Basics ## -################### -set -e # Exit with error if any command fails - -if [ -z "$1" ] -then - read -p "Enter the plugin library name: " plugin_name -else - plugin_name=$1 -fi - -## plugin_name.txt -cat << EOF > plugin_name.txt -${plugin_name} -EOF - -## version.txt -cat << EOF > version.txt -0.0.0 -EOF - -## toolchain.cmake -cat << EOF > toolchain.cmake -set(BUILD_TESTING ON) -set(BUILD_SHARED_LIBS ON) -set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) -set(NWX_MODULE_DIRECTORY ./install/python) -EOF - -################### -## include files ## -################### -mkdir -p include/${plugin_name} - -## include/${plugin_name}/${plugin_name}_mm.hpp -cat << EOF > include/${plugin_name}/${plugin_name}_mm.hpp -#pragma once -#include - -namespace ${plugin_name} { - -/** @brief Loads the modules contained in the plugin into the provided - * ModuleManager instance. - */ -void load_modules(pluginplay::ModuleManager& mm); - -} // namespace ${plugin_name} -EOF - -## include/${plugin_name}/${plugin_name}.hpp -cat << EOF > include/${plugin_name}/${plugin_name}.hpp -#pragma once - -#include "${plugin_name}_mm.hpp" -EOF - -############### -## src files ## -############### -mkdir -p src/${plugin_name} - -## src/${plugin_name}/${plugin_name}_mm.cpp -cat << EOF > src/${plugin_name}/${plugin_name}_mm.cpp -#include "${plugin_name}/${plugin_name}_mm.hpp" - -namespace ${plugin_name} { - -inline void set_defaults(pluginplay::ModuleManager& mm) { - // Default submodules between collections can be set here -} - -void load_modules(pluginplay::ModuleManager& mm) { - // Add subcollection load calls here - - // Assign default submodules - set_defaults(mm); -} - -} // namespace ${plugin_name} -EOF - -################# -## tests files ## -################# -mkdir -p tests/unit_tests - -## tests/unit_tests/test_main.cpp -cat << EOF > tests/unit_tests/test_main.cpp -#define CATCH_CONFIG_RUNNER -#include - -int main(int argc, char* argv[]) { - int res = Catch::Session().run(argc, argv); - return res; -} -EOF - -## tests/unit_tests/test_load_modules.cpp -cat << EOF > tests/unit_tests/test_load_modules.cpp -#include -#include <${plugin_name}/${plugin_name}.hpp> -#include - -TEST_CASE("load_modules") { - pluginplay::ModuleManager mm; - ${plugin_name}::load_modules(mm); -} -EOF - -############ -## Finish ## -############ -echo "New plugin ${plugin_name} created." -echo "Configure, build, and test as follows:" -echo "cmake -Bbuild -H. -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake -DCMAKE_INSTALL_PREFIX=./install" -echo "cmake --build build" -echo "cd build && ctest -VV" \ No newline at end of file diff --git a/{{ cookiecutter.project_slug }}/.gitignore b/{{ cookiecutter.project_slug }}/.gitignore new file mode 100644 index 0000000..9546300 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/.gitignore @@ -0,0 +1,20 @@ +# These are directories used by IDEs for storing settings +.idea/ +.vscode/ + +# These are common build directory names +build*/ +docs/build +docs/source/_build +docs/doxyoutput +docs/source/api +*-build-*/ +_build/ +Debug/ +Release/ + +# Users commonly store their specific CMake settings in a toolchain file +toolchain.cmake + +# Users often install under the root directory +install/ \ No newline at end of file diff --git a/CMakeLists.txt b/{{ cookiecutter.project_slug }}/CMakeLists.txt similarity index 66% rename from CMakeLists.txt rename to {{ cookiecutter.project_slug }}/CMakeLists.txt index b07f876..282e8dc 100644 --- a/CMakeLists.txt +++ b/{{ cookiecutter.project_slug }}/CMakeLists.txt @@ -1,17 +1,16 @@ cmake_minimum_required(VERSION 3.14) ## Set Project and Version -file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/plugin_name.txt" PLUGIN_NAME) file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION) -project("${PLUGIN_NAME}" VERSION "${VERSION}" LANGUAGES CXX) +project({{ cookiecutter.project_slug }} VERSION "${VERSION}" LANGUAGES CXX) ## Get CMaize include(cmake/get_cmaize.cmake) ## Paths ## -set(PLUGIN_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") -set(PLUGIN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") -set(PLUGIN_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests") +set(${PROJECT_NAME}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") +set(${PROJECT_NAME}_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") +set(${PROJECT_NAME}_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests") ## Options ## cmaize_option_list( @@ -31,8 +30,8 @@ cmaize_find_or_build_dependency( ## Add libraries ## cmaize_add_library( ${PROJECT_NAME} - SOURCE_DIR "${PLUGIN_SOURCE_DIR}/${PROJECT_NAME}" - INCLUDE_DIRS "${PLUGIN_INCLUDE_DIR}/${PROJECT_NAME}" + SOURCE_DIR "${${PROJECT_NAME}_SOURCE_DIR}/${PROJECT_NAME}" + INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}" DEPENDS simde ) @@ -50,8 +49,8 @@ if("${BUILD_TESTING}") ## Add Tests ## cmaize_add_tests( test_${PROJECT_NAME} - SOURCE_DIR "${PLUGIN_TESTS_DIR}/unit_tests" - INCLUDE_DIRS "${PLUGIN_INCLUDE_DIR}/${PROJECT_NAME}" + SOURCE_DIR "${${PROJECT_NAME}_TESTS_DIR}/unit_tests" + INCLUDE_DIRS "${${PROJECT_NAME}_INCLUDE_DIR}/${PROJECT_NAME}" DEPENDS Catch2 ${PROJECT_NAME} ) diff --git a/{{ cookiecutter.project_slug }}/README.md b/{{ cookiecutter.project_slug }}/README.md new file mode 100644 index 0000000..2972bb3 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/README.md @@ -0,0 +1,4 @@ +{{ cookiecutter.project_name }} +=============== + +Describe the new plugin here. \ No newline at end of file diff --git a/cmake/get_cmaize.cmake b/{{ cookiecutter.project_slug }}/cmake/get_cmaize.cmake similarity index 100% rename from cmake/get_cmaize.cmake rename to {{ cookiecutter.project_slug }}/cmake/get_cmaize.cmake diff --git a/{{ cookiecutter.project_slug }}/default_toolchain.cmake b/{{ cookiecutter.project_slug }}/default_toolchain.cmake new file mode 100644 index 0000000..d91c46f --- /dev/null +++ b/{{ cookiecutter.project_slug }}/default_toolchain.cmake @@ -0,0 +1,4 @@ +set(BUILD_TESTING ON) +set(BUILD_SHARED_LIBS ON) +set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +set(NWX_MODULE_DIRECTORY ./install/python) diff --git a/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp new file mode 100644 index 0000000..f28db52 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "{{ cookiecutter.project_slug }}_mm.hpp" diff --git a/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp new file mode 100644 index 0000000..8e725d7 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/include/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp @@ -0,0 +1,11 @@ +#pragma once +#include + +namespace {{ cookiecutter.project_slug }} { + +/** @brief Loads the modules contained in the plugin into the provided + * ModuleManager instance. + */ +DECLARE_PLUGIN({{ cookiecutter.project_slug }}); + +} // namespace {{ cookiecutter.project_slug }} diff --git a/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp new file mode 100644 index 0000000..434a850 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/src/{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.cpp @@ -0,0 +1,16 @@ +#include "{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}_mm.hpp" + +namespace {{ cookiecutter.project_slug }} { + +inline void set_defaults(pluginplay::ModuleManager& mm) { + // Default submodules between collections can be set here +} + +DECLARE_PLUGIN({{ cookiecutter.project_slug }}) { + // Add subcollection load calls here + + // Assign default submodules + set_defaults(mm); +} + +} // namespace {{ cookiecutter.project_slug }} diff --git a/{{ cookiecutter.project_slug }}/tests/unit_tests/test_load_modules.cpp b/{{ cookiecutter.project_slug }}/tests/unit_tests/test_load_modules.cpp new file mode 100644 index 0000000..78020e6 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/tests/unit_tests/test_load_modules.cpp @@ -0,0 +1,7 @@ +#include +#include <{{ cookiecutter.project_slug }}/{{ cookiecutter.project_slug }}.hpp> + +TEST_CASE("load_modules") { + pluginplay::ModuleManager mm; + {{ cookiecutter.project_slug }}::load_modules(mm); +} diff --git a/{{ cookiecutter.project_slug }}/tests/unit_tests/test_main.cpp b/{{ cookiecutter.project_slug }}/tests/unit_tests/test_main.cpp new file mode 100644 index 0000000..0d2c460 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/tests/unit_tests/test_main.cpp @@ -0,0 +1,7 @@ +#define CATCH_CONFIG_RUNNER +#include + +int main(int argc, char* argv[]) { + int res = Catch::Session().run(argc, argv); + return res; +} diff --git a/{{ cookiecutter.project_slug }}/version.txt b/{{ cookiecutter.project_slug }}/version.txt new file mode 100644 index 0000000..bd52db8 --- /dev/null +++ b/{{ cookiecutter.project_slug }}/version.txt @@ -0,0 +1 @@ +0.0.0 \ No newline at end of file