Compare commits
13 commits
af8b0d4a46
...
91a1cc00a6
| Author | SHA1 | Date | |
|---|---|---|---|
| 91a1cc00a6 | |||
| 54d11b31a5 | |||
| b361811b97 | |||
| c311577997 | |||
| 92c4cda97f | |||
| 76f5e4caca | |||
| bd8c2c4e13 | |||
| e57ba44ae7 | |||
| 50d3d32fc3 | |||
| 00025a66e4 | |||
| 49688b828f | |||
| e02ce241ec | |||
| b128c9314d |
6 changed files with 58 additions and 10 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,5 @@
|
|||
# emacs workspace config
|
||||
.projectile
|
||||
# lsp keeps state here
|
||||
.cache
|
||||
# typical build directory
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(xo_pyreflect VERSION 0.1)
|
||||
enable_language(CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(cmake/xo-bootstrap-macros.cmake)
|
||||
|
|
@ -17,9 +16,7 @@ set(PROJECT_CXX_FLAGS "")
|
|||
add_definitions(${PROJECT_CXX_FLAGS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# sources
|
||||
|
||||
# note: library=pyreflect (not xo_pyreflect) -> establishes pyreflectTargets
|
||||
add_subdirectory(src/pyreflect)
|
||||
#add_subdirectory(utest)
|
||||
|
||||
|
|
@ -27,3 +24,5 @@ add_subdirectory(src/pyreflect)
|
|||
# provide find_package() support
|
||||
|
||||
xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)
|
||||
|
||||
# end CMakeLists.txt
|
||||
|
|
|
|||
|
|
@ -1,14 +1,35 @@
|
|||
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)
|
||||
# ----------------------------------------------------------------
|
||||
# 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)
|
||||
message("-- CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
|
||||
message("-- CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
|
||||
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-project-macros)
|
||||
include(xo_macros/xo_cxx)
|
||||
|
||||
xo_cxx_bootstrap_message()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Share.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
set(SELF_LIB xo_pyreflect)
|
||||
set(SELF_SRCS pyreflect.cpp)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS})
|
||||
xo_pybind11_dependency(${SELF_LIB} reflect)
|
||||
xo_pybind11_dependency(${SELF_LIB} xo_pyutil)
|
||||
|
|
|
|||
|
|
@ -16,21 +16,44 @@
|
|||
namespace xo {
|
||||
using xo::time::utc_nanos;
|
||||
using xo::ref::unowned_ptr;
|
||||
using xo::ref::rp;
|
||||
using xo::rp;
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace reflect {
|
||||
PYBIND11_MODULE(PYREFLECT_MODULE_NAME(), m) {
|
||||
|
||||
m.doc() = "pybind11 plugin for xo-reflect";
|
||||
|
||||
py::enum_<Metatype>(m, "Metatype")
|
||||
.value("invalid", Metatype::mt_invalid)
|
||||
.value("atomic", Metatype::mt_atomic)
|
||||
.value("pointer", Metatype::mt_pointer)
|
||||
.value("vector", Metatype::mt_vector)
|
||||
.value("struct", Metatype::mt_struct)
|
||||
.value("function", Metatype::mt_function)
|
||||
;
|
||||
|
||||
/* note: possibly move this to pytime/ if/when we provide it */
|
||||
//py::class_<utc_nanos>(m, "utc_nanos");
|
||||
|
||||
//py::class_<TypeDescrImpl>(m, "TypeDescr");
|
||||
/* TypeDescrBase instances are created automatically at library load time
|
||||
* by static initializers. The reflection library (xo-reflect) is responsible
|
||||
* for lifetime of TypeDescrobjects. Under no circumstances should python
|
||||
* (or pybind11) directly destroy a TypeDescrImpl instance, hence use of
|
||||
* unowned_ptr<TypeDescrBase> here.
|
||||
*/
|
||||
py::class_<TypeDescrBase,
|
||||
unowned_ptr<TypeDescrBase>>(m, "TypeDescr")
|
||||
|
||||
.def_static("lookup_by_name", &TypeDescrBase::lookup_by_name)
|
||||
.def_static("print_reflected_types",
|
||||
[](){ TypeDescrBase::print_reflected_types(std::cout); })
|
||||
|
||||
.def_property_readonly("canonical_name", &TypeDescrBase::canonical_name)
|
||||
.def_property_readonly("short_name", &TypeDescrBase::short_name)
|
||||
.def_property_readonly("metatype", &TypeDescrBase::metatype)
|
||||
.def_property_readonly("complete_flag", &TypeDescrBase::complete_flag)
|
||||
.def("__repr__", &TypeDescrBase::display_string);
|
||||
|
||||
/* note: this means python will use
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue