Skip to content

Commit

Permalink
Cmaize refactor (#329)
Browse files Browse the repository at this point in the history
* slightly shorter

* backup

* backup

* updates for CMaize v1.0.1

* Committing clang-format changes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ryanmrichard and github-actions[bot] authored Dec 29, 2023
1 parent 1fe0b1f commit 982e2b0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
source_dir: 'include src tests'
compilers: '["gcc-11", "clang-11"]'
doc_target: 'pluginplay_cxx_api'
secrets: inherit
secrets: inherit
120 changes: 57 additions & 63 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -129,37 +125,27 @@ 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
BUILD_TARGET Catch2
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}
Expand All @@ -179,29 +165,37 @@ 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
# which live in the py_test_pluginplay library.
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()
Expand Down
31 changes: 31 additions & 0 deletions cmake/get_nwx_cmake.cmake
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions tests/python/unit_tests/tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 982e2b0

Please sign in to comment.