From 2f908b7c3638bd66a926626a4d94c26b2f848752 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 15 Mar 2024 19:40:26 -0400 Subject: [PATCH] build: bugfix SELF_LIB consistency + streamline CMAKE_MODULE_PATH --- .gitignore | 2 +- CMakeLists.txt | 2 +- README.md | 26 +++++++++++++++++++++++++- cmake/xo-bootstrap-macros.cmake | 12 ++++++++++++ src/pyprocess/CMakeLists.txt | 2 +- src/pyprocess/pyprocess.hpp.in | 6 +++--- 6 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 cmake/xo-bootstrap-macros.cmake diff --git a/.gitignore b/.gitignore index f52f1311..53a9c92f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # lsp keeps state here .cache # typical build directory -build +.build* # lsp: symlink to file in build directory (established manually) compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 36786fb8..d53e2ca6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.10) project(xo_pyprocess VERSION 0.1) -include(xo_macros/xo-project-macros) +include(cmake/xo-bootstrap-macros.cmake) xo_cxx_toplevel_options() diff --git a/README.md b/README.md index 2ad68ffb..07725a19 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,17 @@ # python bindings for c++ stochastic process library (xo-process) -# build + install +## Getting Started + +### build + install dependencies + +- [github/Rconybea/xo-process](https://github.com/Rconybea/xo-process) +- [github/Rconybea/xo-reactor](https://github.com/Rconybea/xo-reactor) +- [github/Rconybea/xo-pyutil](https://github.com/Rconybea/xo-pyutil) +- [github/Rconybea/xo-pyreflect](https://github.com/Rconybea/xo-pyreflect) +- [github/Rconybea/xo-pyprintjson](https://github.com/Rconybea/xo-pyprintjson) +- [github/Rconybea/xo-pyreactor](https://github.com/Rconybea/xo-pyreactor) + +### build + install ``` $ cd xo-pyprocess $ mkdir build @@ -15,6 +26,19 @@ $ make install ``` (also see .github/workflows/main.yml) +## Examples + +Assumes `xo-pyprocess` installed to `~/local2/lib` +``` +PYTHONPATH=~/local2/lib:$PYTHONPATH python +>>> import xo_pyprocess +>>> dir(xo_pyprocess) +['BrownianMotion', 'ExpProcess', 'RealizationSource', 'RealizationTracer', 'StochasticProcess', 'UpxAdapterSink', 'UpxEvent', 'UpxEventStore', 'UpxToConsole', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'make_brownian_motion', 'make_exponential_brownian_motion', 'make_realization_printer', 'make_realization_source', 'make_tracer'] +>>> +``` + +## Development + # build for unit test coverage ``` $ cd xo-pyprocess diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake new file mode 100644 index 00000000..16644435 --- /dev/null +++ b/cmake/xo-bootstrap-macros.cmake @@ -0,0 +1,12 @@ +if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL "prefix")) + # default to typical install location for xo-project-macros + set(CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/share/cmake) +endif() + +message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") +message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") + +# 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-project-macros) diff --git a/src/pyprocess/CMakeLists.txt b/src/pyprocess/CMakeLists.txt index cf35ab2e..87a23e90 100644 --- a/src/pyprocess/CMakeLists.txt +++ b/src/pyprocess/CMakeLists.txt @@ -1,6 +1,6 @@ # xo_pyprocess/src/pyprocess/CMakeLists.txt -set(SELF_LIB pyprocess) +set(SELF_LIB xo_pyprocess) set(SELF_SRCS pyprocess.cpp) xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) diff --git a/src/pyprocess/pyprocess.hpp.in b/src/pyprocess/pyprocess.hpp.in index d2f5cec1..938bf0c9 100644 --- a/src/pyprocess/pyprocess.hpp.in +++ b/src/pyprocess/pyprocess.hpp.in @@ -8,18 +8,18 @@ * example: * PYBIND11_MODULE(PYPROCESS_MODULE_NAME(), m) { ... } */ -#define PYPROCESS_MODULE_NAME() @SELF_LIBRARY_NAME@ +#define PYPROCESS_MODULE_NAME() @SELF_LIB@ /* example: * py::module_::import(PYPROCESS_MODULE_NAME_STR) */ -#define PYPROCESS_MODULE_NAME_STR "@SELF_LIBRARY_NAME@" +#define PYPROCESS_MODULE_NAME_STR "@SELF_LIB@" /* example: * PYPROCESS_IMPORT_MODULE() * replaces * py::module_::import("pyprocess") */ -#define PYPROCESS_IMPORT_MODULE() py::module_::import("@SELF_LIBRARY_NAME@") +#define PYPROCESS_IMPORT_MODULE() py::module_::import("@SELF_LIB@") /* end pyprocess.hpp */