From 7c51ccb7f30f4c9fdfe0a172e7bcd5b2c135ad7b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 1 May 2024 07:12:29 -0500 Subject: [PATCH] xo-pyunit: initial commit --- CMakeLists.txt | 36 +++++++++++++++++++++++++++++++++ cmake/xo-bootstrap-macros.cmake | 35 ++++++++++++++++++++++++++++++++ cmake/xo_pyunitConfig.cmake.in | 4 ++++ src/pyunit/CMakeLists.txt | 9 +++++++++ src/pyunit/pyunit.cpp | 27 +++++++++++++++++++++++++ src/pyunit/pyunit.hpp.in | 25 +++++++++++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/xo-bootstrap-macros.cmake create mode 100644 cmake/xo_pyunitConfig.cmake.in create mode 100644 src/pyunit/CMakeLists.txt create mode 100644 src/pyunit/pyunit.cpp create mode 100644 src/pyunit/pyunit.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..7ac955b9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,36 @@ +# xo-pyunit/CMakeLists.txt + +cmake_minimum_required(VERSION 3.10) + +project(xo_pyunit VERSION 0.1) + +include(GNUInstallDirs) +include(cmake/xo-bootstrap-macros.cmake) + +xo_cxx_toplevel_options2() + +# ---------------------------------------------------------------- +# cmake -DCMAKE_BUILD_TYPE=coverage +xo_toplevel_coverage_config2() + +# ---------------------------------------------------------------- +# cmake -DCMAKE_BUILD_TYPE=debug +xo_toplevel_debug_config2() + +# ---------------------------------------------------------------- +# c++ settings (usually temporary) + +set(PROJECT_CXX_FLAGS "") +add_definitions(${PROJECT_CXX_FLAGS}) + +# ---------------------------------------------------------------- + +add_subdirectory(src/pyunit) +#add_subdirectory(utest) + +# ---------------------------------------------------------------- +# provide find_package() support + +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) + +# end CMakeLists.txt diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..aba31169 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,35 @@ +# ---------------------------------------------------------------- +# for example: +# $ PREFIX=/usr/local # for example +# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build +# +# will get +# CMAKE_MODULE_PATH +# from xo-cmake-config --cmake-module-path +# +# and expect .cmake macros in +# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake +# ---------------------------------------------------------------- + +find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED) + +if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND") + message(FATAL "could not find xo-cmake-config executable") +endif() + +message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}") + +if (NOT XO_SUBMODULE_BUILD) + if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix)) + # default to typical install location for xo-project-macros + execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH) + message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + endif() +endif() + +# needs to have been installed somewhere on CMAKE_MODULE_PATH, +# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX) +# +include(xo_macros/xo_cxx) + +xo_cxx_bootstrap_message() diff --git a/cmake/xo_pyunitConfig.cmake.in b/cmake/xo_pyunitConfig.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/xo_pyunitConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/src/pyunit/CMakeLists.txt b/src/pyunit/CMakeLists.txt new file mode 100644 index 00000000..c67d1d48 --- /dev/null +++ b/src/pyunit/CMakeLists.txt @@ -0,0 +1,9 @@ +# xo_pyunit/src/pyunit/CMakeLists.txt + +set(SELF_LIB pyunit) +set(SELF_SRCS pyunit.cpp) + +# ---------------------------------------------------------------- + +xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) +xo_pybind11_dependency(${SELF_LIB} xo_unit) diff --git a/src/pyunit/pyunit.cpp b/src/pyunit/pyunit.cpp new file mode 100644 index 00000000..21a4872c --- /dev/null +++ b/src/pyunit/pyunit.cpp @@ -0,0 +1,27 @@ +/* @file pyunit.cpp */ + +// note: need pyreflect/ here bc pyreflect.hpp is generated, located in build directory +#include "pyunit.hpp" +#include "xo/unit/xquantity.hpp" +#include "xo/pyutil/pyutil.hpp" +//#include +//#include +//#include +//#include + +namespace xo { + namespace py = pybind11; + + namespace qty { + PYBIND11_MODULE(PYUNIT_MODULE_NAME(), m) { + + py::class_(m, "Quantity") + .def("__repr__", + [](Quantity & x) + { + return tostr(x); + }) + py::arg("qty")); + } + } +} /*namespace xo*/ diff --git a/src/pyunit/pyunit.hpp.in b/src/pyunit/pyunit.hpp.in new file mode 100644 index 00000000..d2008d8a --- /dev/null +++ b/src/pyunit/pyunit.hpp.in @@ -0,0 +1,25 @@ +/* @file pyunit.hpp + * + * automatically generated from src/xo_pyunit/pyunit.hpp.in + * see src/xo_pyunit/CMakeLists.txt + */ + +/* python requires module name = library name + * example: + * PYBIND11_MODULE(PYUNIT_MODULE_NAME(), m) { ... } + */ +#define PYUNIT_MODULE_NAME() @SELF_LIB@ + +/* example: + * py::module_::import(PYUNIT_MODULE_NAME_STR) + */ +#define PYUNIT_MODULE_NAME_STR "@SELF_LIB@" + +/* example: + * PYUNIT_IMPORT_MODULE() + * replaces + * py::module_::import("pyunit") + */ +#define PYUNIT_IMPORT_MODULE() py::module_::import("@SELF_LIB@") + +/* end pyunit.hpp */