diff --git a/CMakeLists.txt b/CMakeLists.txt index 427a56b..3231179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/xo-bootstrap-macros.cmake b/cmake/xo-bootstrap-macros.cmake index 9659221..aba3116 100644 --- a/cmake/xo-bootstrap-macros.cmake +++ b/cmake/xo-bootstrap-macros.cmake @@ -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() diff --git a/src/pyreflect/CMakeLists.txt b/src/pyreflect/CMakeLists.txt index 0dbd348..8be1e42 100644 --- a/src/pyreflect/CMakeLists.txt +++ b/src/pyreflect/CMakeLists.txt @@ -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) diff --git a/src/pyreflect/pyreflect.cpp b/src/pyreflect/pyreflect.cpp index a77993a..ac5ef86 100644 --- a/src/pyreflect/pyreflect.cpp +++ b/src/pyreflect/pyreflect.cpp @@ -37,6 +37,12 @@ namespace xo { //py::class_(m, "utc_nanos"); //py::class_(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 here. + */ py::class_>(m, "TypeDescr")