From 982e2b01ad5529c469df7ea46e0d7860767c78f9 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Fri, 29 Dec 2023 13:50:28 -0600 Subject: [PATCH] Cmaize refactor (#329) * slightly shorter * backup * backup * updates for CMaize v1.0.1 * Committing clang-format changes --------- Co-authored-by: github-actions[bot] --- .github/workflows/pull_request.yaml | 2 +- CMakeLists.txt | 120 +++++++++++++--------------- cmake/get_nwx_cmake.cmake | 31 +++++++ tests/python/unit_tests/tox.ini | 23 ++++++ 4 files changed, 112 insertions(+), 64 deletions(-) create mode 100644 cmake/get_nwx_cmake.cmake create mode 100644 tests/python/unit_tests/tox.ini diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 08814aba3..7e3972e80 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -28,4 +28,4 @@ jobs: source_dir: 'include src tests' compilers: '["gcc-11", "clang-11"]' doc_target: 'pluginplay_cxx_api' - secrets: inherit + secrets: inherit \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index cff0f482b..81287f048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,37 +13,35 @@ # limitations under the License. cmake_minimum_required(VERSION 3.14) -SET(VERSION 1.0.0) #TODO: get from git -project(pluginplay VERSION "${VERSION}" LANGUAGES CXX) -include(FetchContent) -FetchContent_Declare( - nwx_cmake - GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake -) -FetchContent_MakeAvailable(nwx_cmake) -set( - CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${nwx_cmake_SOURCE_DIR}/cmake" - CACHE STRING "" - FORCE -) +# Downloads common CMake modules used throughout NWChemEx +include(cmake/get_nwx_cmake.cmake) -include(get_cmaize) -include(nwx_versions) +#Sets the version to whatever git thinks it is +#include(get_version_from_git) +#get_version_from_git(pluginplay_version "${CMAKE_CURRENT_LIST_DIR}") +set(pluginplay_version 1.0.0) +project(pluginplay VERSION "${pluginplay_version}" LANGUAGES CXX) -### Options ### -option(BUILD_TESTING "Should we build the tests?" OFF) -option(BUILD_PYBIND11_PYBINDINGS "Use pybind11 to build Python3 bindings?" OFF) -option(BUILD_CPPYY_PYBINDINGS "Use Cppyy to build Python3 bindings?" OFF) -option(BUILD_ROCKSDB "Should we build the RocksDB backend?" OFF) +include(nwx_versions) +include(get_cmaize) -# Work out the project paths +# Work out full paths to the project's include/source dirs set(project_inc_dir "${CMAKE_CURRENT_LIST_DIR}/include/${PROJECT_NAME}") set(project_src_dir "${CMAKE_CURRENT_LIST_DIR}/src/${PROJECT_NAME}") +# Builds C++ API documentation include(nwx_cxx_api_docs) nwx_cxx_api_docs("README.md" "${project_inc_dir}" "${project_src_dir}") +### Options ### +cmaize_option_list( + BUILD_TESTING OFF "Should we build unit tests?" + BUILD_PYBIND11_PYBINDINGS OFF "Build Pybind11 Python bindings?" + BUILD_ROCKSDB OFF "Enable RocksDB backend of the cache?" +) + +### Dependendencies ### cmaize_find_or_build_dependency( utilities URL github.com/NWChemEx/utilities @@ -71,32 +69,27 @@ cmaize_find_or_build_dependency( CMAKE_ARGS BUILD_TESTING=${PARALLELZONE_BUILD_TESTING} ) +# CI doesn't like this +#cmaize_find_dependency( +# boost_container +# URL github.com/boostorg/container +# FIND_TARGET Boost::container +#) + find_package(Boost REQUIRED) -set(pluginplay_depends utilities parallelzone libfort Boost::boost) -set(ROCKSDB_TARGET "") -if("${BUILD_ROCKSDB}") - set(ROCKSDB_TARGET RocksDB::rocksdb-shared) - find_package(RocksDB REQUIRED) - # TODO: We need to do a superbuild for RocksDB - # cpp_find_or_build_dependency( - # RocksDB - # URL github.com/facebook/rocksdb - # VERSION ${NWX_ROCKSDB_VERSION} - # BUILD_TARGET rocksdb-shared - # FIND_TARGET ${ROCKSDB_TARGET} - # CMAKE_ARGS CMAKE_BUILD_TYPE=Release - # ROCKSDB_BUILD_SHARED=On - # WITH_BENCHMARK_TOOLS=Off - # WITH_GFLAGS=Off - # WITH_TOOLS=OFF - # JNI=OFF - # WITH_TESTS=OFF - # ) - target_compile_definitions(${ROCKSDB_TARGET} INTERFACE BUILD_ROCKS_DB) - list(APPEND pluginplay_depends ${ROCKSDB_TARGET}) -endif() +## Optional Dependencies ## +cmaize_find_optional_dependency( + RocksDB + BUILD_ROCKSDB + URL github.com/facebook/rocksdb + FIND_TARGET RocksDB::rocksdb-shared +) +set(pluginplay_depends utilities parallelzone libfort Boost::boost RocksDB) + +# As of 1.0.0 CMaize does not support multiple build or find targets. This will +# be fixed in a future feature release. For now we handle the if("${BUILD_PYBIND11_PYBINDINGS}") cmaize_find_or_build_dependency( pybind11 @@ -118,6 +111,9 @@ cmaize_add_library( INCLUDE_DIRS "${project_inc_dir}" DEPENDS "${pluginplay_depends}" ) + +# TODO: Update source to use BUILD_PYBIND11_PYBINDINGS, then goes away when +# CMaize supports mulitple targets if("${BUILD_PYBIND11_PYBINDINGS}") target_compile_definitions("${PROJECT_NAME}" PUBLIC BUILD_PYBIND11) endif() @@ -129,19 +125,12 @@ nwx_add_pybind11_module( DEPENDS "${PROJECT_NAME}" ) -include(nwx_python_mods) -cppyy_make_python_package( - PACKAGE pluginplay - NAMESPACES pluginplay - DEPPACKAGES parallelzone -) - if("${BUILD_TESTING}") set(cxx_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/cxx") - set(python_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/python") set(tests_src_dir "${cxx_test_dir}/unit_tests/${PROJECT_NAME}") set(examples_src_dir "${cxx_test_dir}/doc_snippets") + ### C++ Testing ### cmaize_find_or_build_dependency( Catch2 URL github.com/catchorg/Catch2 @@ -149,17 +138,14 @@ if("${BUILD_TESTING}") FIND_TARGET Catch2::Catch2 VERSION ${NWX_CATCH2_VERSION} ) + cmaize_add_library( ${PROJECT_NAME}_examples SOURCE_DIR ${examples_src_dir} INCLUDE_DIRS ${examples_src_dir} DEPENDS Catch2::Catch2 ${PROJECT_NAME} ) - cppyy_make_python_package( - PACKAGE ${PROJECT_NAME}_examples - NAMESPACES pluginplay_examples - DEPPACKAGES pluginplay - ) + cmaize_add_tests( test_unit_${PROJECT_NAME} SOURCE_DIR ${tests_src_dir} @@ -179,6 +165,13 @@ if("${BUILD_TESTING}") DEPENDS Catch2::Catch2 ${PROJECT_NAME} ) + ### Python Tests ### + set(python_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/python") + cmaize_find_or_build_dependency( + tox + PACKAGE_MANAGER pip + ) + # In the python tests we will pass Python into PluginPlay, we will then # need to know that C++ can handle those Python types. To this end we # create a series of Python bindings for unit testing this functionality @@ -186,22 +179,23 @@ if("${BUILD_TESTING}") nwx_add_pybind11_module( py_test_pluginplay INSTALL OFF - SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/tests/python/unit_tests" + SOURCE_DIR "${python_test_dir}/unit_tests" INCLUDE_DIRS "${project_inc_dir}" - DEPENDS ${PROJECT_NAME} + DEPENDS ${PROJECT_NAME} tox ) - nwx_pybind11_tests( - py_pluginplay ${python_test_dir}/unit_tests/test_pluginplay.py + nwx_tox_test( + py_pluginplay ${python_test_dir}/unit_tests SUBMODULES parallelzone ) nwx_add_pybind11_module( py_${PROJECT_NAME}_examples INSTALL OFF SOURCE_DIR "${python_test_dir}/doc_snippets" - DEPENDS parallelzone ${PROJECT_NAME} ${PROJECT_NAME}_examples + DEPENDS parallelzone ${PROJECT_NAME} ${PROJECT_NAME}_examples ) nwx_pybind11_tests( - py_${PROJECT_NAME}_docs "${python_test_dir}/doc_snippets/test_doc_snippets.py" + py_${PROJECT_NAME}_docs + "${python_test_dir}/doc_snippets/test_doc_snippets.py" SUBMODULES parallelzone ) endif() diff --git a/cmake/get_nwx_cmake.cmake b/cmake/get_nwx_cmake.cmake new file mode 100644 index 000000000..7d93fd5ee --- /dev/null +++ b/cmake/get_nwx_cmake.cmake @@ -0,0 +1,31 @@ +# Copyright 2022 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include_guard() + +macro(get_nwx_cmake) + include(FetchContent) + FetchContent_Declare( + nwx_cmake + GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake + ) + FetchContent_MakeAvailable(nwx_cmake) + set( + CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${nwx_cmake_SOURCE_DIR}/cmake" + CACHE STRING "" + FORCE + ) +endmacro() + +get_nwx_cmake() diff --git a/tests/python/unit_tests/tox.ini b/tests/python/unit_tests/tox.ini new file mode 100644 index 000000000..12e347848 --- /dev/null +++ b/tests/python/unit_tests/tox.ini @@ -0,0 +1,23 @@ +; Copyright 2023 NWChemEx-Project +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. + +[tox] +envlist = +skipsdist = True + +[testenv] +deps = +passenv = * +commands = + python test_pluginplay.py