From 3557c4d4e7a8e65caa0be0020b1da20af50c50d2 Mon Sep 17 00:00:00 2001 From: parker Date: Tue, 12 Aug 2025 22:22:46 +0100 Subject: [PATCH] feat: working rpm and targz packages with opDefs library --- CMakeLists.txt | 24 +++++++++--- cmake/CPackProjectConfig.cmake | 12 ++++++ src/Engine/Operator/OperatorTable.cpp | 53 ++++++++++++++++++++++++++- src/Engine/Operator/OperatorTable.h | 2 + src/OpDefs/CMakeLists.txt | 6 +++ src/OpDefs/RegisterPlugin.cpp | 44 +++++++++++----------- 6 files changed, 113 insertions(+), 28 deletions(-) create mode 100644 cmake/CPackProjectConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 985fd37..8e66ac4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ set(CMAKE_AUTORCC ON) # setup project project(enzo) +set(ENZO_DEV_LIB_DIR "${CMAKE_SOURCE_DIR}/build/src/OpDefs/") + set(ENGINE_SOURCES src/Engine/Operator/Attribute.cpp src/Engine/Operator/Geometry.cpp @@ -91,16 +93,28 @@ qt_add_executable(${AppExec} ${ENGINE_SOURCES} ) +target_compile_definitions(${AppExec} PRIVATE ENZO_DEV_LIB_DIR="${ENZO_DEV_LIB_DIR}") + + # --- packaging --- -if(UNIX) - set(CPACK_PACKAGING_INSTALL_PREFIX "/opt") -endif(UNIX) +set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/CPackProjectConfig.cmake) -set(ENZO_BIN_DIR ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_PROJECT_NAME}/bin) +set(CPACK_GENERATOR "RPM;TGZ") + +set(ENZO_BIN_DIR ${CMAKE_PROJECT_NAME}/bin) +set(ENZO_LIB_DIR ${CMAKE_PROJECT_NAME}/lib) + +install( + TARGETS ${AppExec} + RUNTIME DESTINATION ${ENZO_BIN_DIR} + LIBRARY DESTINATION ${ENZO_LIB_DIR} + ARCHIVE DESTINATION ${ENZO_LIB_DIR} +) -install(TARGETS ${AppExec} RUNTIME DESTINATION ${ENZO_BIN_DIR}) include(CPack) +# set(CPACK_RPM_PACKAGE_REQUIRES "openssl >= 1.1.1, zlib >= 1.2.11") + # --- end packaging diff --git a/cmake/CPackProjectConfig.cmake b/cmake/CPackProjectConfig.cmake new file mode 100644 index 0000000..3afcf92 --- /dev/null +++ b/cmake/CPackProjectConfig.cmake @@ -0,0 +1,12 @@ +if (CPACK_GENERATOR MATCHES "RPM") + # rpm specific config + + if(UNIX) + set(CPACK_PACKAGING_INSTALL_PREFIX "/opt") + endif(UNIX) + +elseif(CPACK_GENERATOR MATCHES "TGZ") + # tgz specific config + +endif() + diff --git a/src/Engine/Operator/OperatorTable.cpp b/src/Engine/Operator/OperatorTable.cpp index 72a18eb..7465b6a 100644 --- a/src/Engine/Operator/OperatorTable.cpp +++ b/src/Engine/Operator/OperatorTable.cpp @@ -2,8 +2,13 @@ #include "Engine/Operator/OpInfo.h" #include "Engine/Types.h" #include +#include +#include +#include +#include #include +#include void enzo::op::OperatorTable::addOperator(enzo::op::OpInfo info) { @@ -48,13 +53,59 @@ std::vector enzo::op::OperatorTable::getData() return opInfoStore_; } +boost::filesystem::path enzo::op::OperatorTable::findPlugin(const std::string& undecoratedLibName) +{ + + const auto libName = boost::dll::shared_library::decorate(undecoratedLibName); + + // check for lib dir + { + const boost::filesystem::path executable = boost::dll::program_location(); + const boost::filesystem::path enzoRoot = executable.parent_path().parent_path(); + const boost::filesystem::path enzoLib = enzoRoot / "lib"; + const boost::filesystem::path candidate = enzoLib / libName; + + if(boost::filesystem::exists(candidate)) + { + IC(candidate); + return candidate; + } + else std::cout << "Couldn't find lib at: " << candidate.string() << "\n"; + } + + // check for dev macro + #ifndef ENZO_DEV_LIB_DIR + #define ENZO_DEV_LIB_DIR "" + #endif + if(std::string(ENZO_DEV_LIB_DIR).size()) + { + const auto candidate = boost::filesystem::path(ENZO_DEV_LIB_DIR) / libName; + if(boost::filesystem::exists(candidate)) + { + IC(candidate); + return candidate; + } + else std::cout << "Couldn't find lib at: " << candidate.string() << "\n"; + } + + + // TODO: add env var finder + // TODO: add same dirfinder + + throw std::runtime_error("Couldn't find plugin: " + libName.string()); +} + + void enzo::op::OperatorTable::initPlugins() { static bool pluginsLoaded=false; if(pluginsLoaded) return; + // auto initPlugin = boost::dll::import_symbol( + // "build/src/OpDefs/libenzoOps1.so", "newSopOperator" + // ); auto initPlugin = boost::dll::import_symbol( - "build/src/OpDefs/libenzoOps1.so", "newSopOperator" + findPlugin("enzoOps1"), "newSopOperator" ); initPlugin(enzo::op::OperatorTable::addOperator); diff --git a/src/Engine/Operator/OperatorTable.h b/src/Engine/Operator/OperatorTable.h index dbbdf14..c7a30f2 100644 --- a/src/Engine/Operator/OperatorTable.h +++ b/src/Engine/Operator/OperatorTable.h @@ -5,6 +5,7 @@ #include "Engine/Operator/GeometryOpDef.h" #include "Engine/Operator/OpInfo.h" #include "Engine/Parameter/Template.h" +#include namespace enzo::op @@ -17,6 +18,7 @@ public: static nt::opConstructor getOpConstructor(std::string name); static const std::optional getOpInfo(std::string name); static std::vector getData(); + static boost::filesystem::path findPlugin(const std::string& undecoratedLibName); // TODO: move to better spot (maybe engine class) static void initPlugins(); private: diff --git a/src/OpDefs/CMakeLists.txt b/src/OpDefs/CMakeLists.txt index aa335f6..5cfa617 100644 --- a/src/OpDefs/CMakeLists.txt +++ b/src/OpDefs/CMakeLists.txt @@ -32,6 +32,12 @@ add_library(${libName} SHARED ) target_link_libraries(${libName} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb) +# packaging +install(TARGETS ${libName} + LIBRARY DESTINATION ${ENZO_LIB_DIR} + ARCHIVE DESTINATION ${ENZO_LIB_DIR} +) + MESSAGE("CURRENT SOURCE DIR" ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(${libName} PUBLIC diff --git a/src/OpDefs/RegisterPlugin.cpp b/src/OpDefs/RegisterPlugin.cpp index 431baab..26b675b 100644 --- a/src/OpDefs/RegisterPlugin.cpp +++ b/src/OpDefs/RegisterPlugin.cpp @@ -25,28 +25,28 @@ extern "C" 1, } ); - addOperator( - enzo::op::OpInfo { - "house", - "House", - &GOP_house::ctor, - GOP_house::parameterList, - 0, - 0, - 1, - } - ); - addOperator( - enzo::op::OpInfo { - "testGeoCube", - "Test Cube", - &GopTestGeoCube::ctor, - GopTestGeoCube::parameterList, - 0, - 0, - 1, - } - ); + // addOperator( + // enzo::op::OpInfo { + // "house", + // "House", + // &GOP_house::ctor, + // GOP_house::parameterList, + // 0, + // 0, + // 1, + // } + // ); + // addOperator( + // enzo::op::OpInfo { + // "testGeoCube", + // "Test Cube", + // &GopTestGeoCube::ctor, + // GopTestGeoCube::parameterList, + // 0, + // 0, + // 1, + // } + // ); addOperator( enzo::op::OpInfo { "geometryImport",