From df97736c159fc2108824d804baee0fef3811c8ca Mon Sep 17 00:00:00 2001 From: erik pernod Date: Fri, 31 Aug 2018 09:23:40 +0200 Subject: [PATCH] Merge pull request #758 from guparan/fix_missing_resources [SofaGuiQt][runSofa] FIX missing resources --- CMakeLists.txt | 16 +++++++--------- applications/projects/runSofa/CMakeLists.txt | 8 +++++++- applications/projects/runSofa/Main.cpp | 9 ++++++++- applications/projects/runSofa/etc/runSofa.ini.in | 1 + applications/sofa/gui/qt/CMakeLists.txt | 7 +++++++ applications/sofa/gui/qt/RealGUI.cpp | 9 +++++++-- applications/sofa/gui/qt/etc/SofaGuiQt.ini.in | 1 + 7 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 applications/projects/runSofa/etc/runSofa.ini.in create mode 100644 applications/sofa/gui/qt/etc/SofaGuiQt.ini.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 174357a5496..5f25a039958 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,12 +59,6 @@ list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/applications/plugins) list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/applications/packages) list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/applications/projects) -# Create etc/sofa.ini: it contains the paths to share/ and examples/. In the -# build directory, it points to the source tree, -set(SHARE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/share") -set(EXAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/examples") -configure_file(${SOFA_KERNEL_SOURCE_DIR}/etc/sofa.ini.in "${CMAKE_BINARY_DIR}/etc/sofa.ini") - ## RPATH if(UNIX) # RPATH is a field in ELF binaries that is used as a hint by the system @@ -269,11 +263,15 @@ install(FILES "${CMAKE_SOURCE_DIR}/CHANGELOG.md" DESTINATION . COMPONENT applica install(FILES "${CMAKE_SOURCE_DIR}/LICENSE.LGPL.txt" DESTINATION . COMPONENT applications) install(FILES "${CMAKE_SOURCE_DIR}/Authors.txt" DESTINATION . COMPONENT applications) -## Create etc/installedSofa.ini: it contains the paths to share/ and examples/. Compare to the Sofa.ini in the -## build directory, this one contains relative paths to the installed resource directory. +# Create build and install versions of etc/sofa.ini: +# - In build dir, sofa.ini contains absolute paths to distant (in source) share/ and examples/ dirs +# - In install dir, sofa.ini (generated later via installedSofa.ini) contains relative paths to local share/ and examples/ dirs +set(SHARE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/share") +set(EXAMPLES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/examples") +configure_file("${SOFA_KERNEL_SOURCE_DIR}/etc/sofa.ini.in" "${CMAKE_BINARY_DIR}/etc/sofa.ini") set(SHARE_DIR "../share/sofa") set(EXAMPLES_DIR "../share/sofa/examples") -configure_file(${SOFA_KERNEL_SOURCE_DIR}/etc/sofa.ini.in "${CMAKE_BINARY_DIR}/etc/installedSofa.ini") +configure_file("${SOFA_KERNEL_SOURCE_DIR}/etc/sofa.ini.in" "${CMAKE_BINARY_DIR}/etc/installedSofa.ini") install(FILES "${CMAKE_BINARY_DIR}/etc/installedSofa.ini" DESTINATION etc RENAME sofa.ini COMPONENT applications) option(SOFA_INSTALL_RESOURCES_FILES "Copy resources files (etc/, share/, examples/) when installing" ON) diff --git a/applications/projects/runSofa/CMakeLists.txt b/applications/projects/runSofa/CMakeLists.txt index 38b4dd1ff81..a61b7f27665 100644 --- a/applications/projects/runSofa/CMakeLists.txt +++ b/applications/projects/runSofa/CMakeLists.txt @@ -53,7 +53,13 @@ if(SOFA_BUILD_TESTS) endif() endif() -# if MSVC then plugins are located in bin/ instead of lib/ on Mac and Linux +# Create build and install versions of .ini file for resources finding +set(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/etc/${PROJECT_NAME}.ini.in" "${CMAKE_BINARY_DIR}/etc/${PROJECT_NAME}.ini") +set(RESOURCES_DIR "../share/sofa/gui/runSofa") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/etc/${PROJECT_NAME}.ini.in" "${CMAKE_BINARY_DIR}/etc/installed${PROJECT_NAME}.ini") +install(FILES "${CMAKE_BINARY_DIR}/etc/installed${PROJECT_NAME}.ini" DESTINATION etc RENAME ${PROJECT_NAME}.ini COMPONENT applications) + install(DIRECTORY "resources" DESTINATION "share/sofa/gui/runSofa" COMPONENT resources) install(FILES "${_defaultConfigPluginFilePath}" DESTINATION ${_pluginLocation}/ COMPONENT applications) diff --git a/applications/projects/runSofa/Main.cpp b/applications/projects/runSofa/Main.cpp index 457049b3292..c05c613cd59 100644 --- a/applications/projects/runSofa/Main.cpp +++ b/applications/projects/runSofa/Main.cpp @@ -147,7 +147,14 @@ void addGUIParameters(ArgumentParser* argumentParser) // --------------------------------------------------------------------- int main(int argc, char** argv) { - GuiDataRepository.addFirstPath(Utils::getSofaPathTo("share/sofa/gui/runSofa/resources").c_str()) ; + // Add resources dir to GuiDataRepository + const std::string sofaIniFilePath = Utils::getSofaPathPrefix() + "/etc/runSofa.ini"; + std::map iniFileValues = Utils::readBasicIniFile(sofaIniFilePath); + if (iniFileValues.find("RESOURCES_DIR") != iniFileValues.end()) + { + GuiDataRepository.addFirstPath( iniFileValues["RESOURCES_DIR"] ); + } + sofa::helper::BackTrace::autodump(); ExecParams::defaultInstance()->setAspectID(0); diff --git a/applications/projects/runSofa/etc/runSofa.ini.in b/applications/projects/runSofa/etc/runSofa.ini.in new file mode 100644 index 00000000000..1a9c6a74899 --- /dev/null +++ b/applications/projects/runSofa/etc/runSofa.ini.in @@ -0,0 +1 @@ +RESOURCES_DIR=@RESOURCES_DIR@ diff --git a/applications/sofa/gui/qt/CMakeLists.txt b/applications/sofa/gui/qt/CMakeLists.txt index 77b5b687647..ecbd6ae31ce 100644 --- a/applications/sofa/gui/qt/CMakeLists.txt +++ b/applications/sofa/gui/qt/CMakeLists.txt @@ -201,6 +201,13 @@ set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DSOFA_BUILD_SOF sofa_install_targets(SofaGui SofaGuiQt "sofa/gui/qt") +# Create build and install versions of .ini file for resources finding +set(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/etc/${PROJECT_NAME}.ini.in "${CMAKE_BINARY_DIR}/etc/${PROJECT_NAME}.ini") +set(RESOURCES_DIR "../share/sofa/gui/qt") +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/etc/${PROJECT_NAME}.ini.in "${CMAKE_BINARY_DIR}/etc/installed${PROJECT_NAME}.ini") +install(FILES "${CMAKE_BINARY_DIR}/etc/installed${PROJECT_NAME}.ini" DESTINATION etc RENAME ${PROJECT_NAME}.ini COMPONENT applications) + install(DIRECTORY "resources" DESTINATION "share/sofa/gui/qt" COMPONENT resources) install(FILES ${HEADER_FILES} DESTINATION "include/sofa/gui/qt" COMPONENT headers) install(FILES ${MOC_HEADER_FILES} DESTINATION "include/sofa/gui/qt" COMPONENT headers) diff --git a/applications/sofa/gui/qt/RealGUI.cpp b/applications/sofa/gui/qt/RealGUI.cpp index 13b5263b801..817ddee353d 100644 --- a/applications/sofa/gui/qt/RealGUI.cpp +++ b/applications/sofa/gui/qt/RealGUI.cpp @@ -250,8 +250,13 @@ void RealGUI::CreateApplication(int /*_argc*/, char** /*_argv*/) argv[1]=NULL; application = new QSOFAApplication ( *argc,argv ); - //Initialize GUI resources path - GuiDataRepository.addFirstPath(Utils::getSofaPathTo("share/sofa/gui/qt/resources").c_str()); + // Add resources dir to GuiDataRepository + const std::string sofaIniFilePath = Utils::getSofaPathPrefix() + "/etc/SofaGuiQt.ini"; + std::map iniFileValues = Utils::readBasicIniFile(sofaIniFilePath); + if (iniFileValues.find("RESOURCES_DIR") != iniFileValues.end()) + { + sofa::gui::GuiDataRepository.addFirstPath( iniFileValues["RESOURCES_DIR"] ); + } //force locale to Standard C //(must be done immediatly after the QApplication has been created) diff --git a/applications/sofa/gui/qt/etc/SofaGuiQt.ini.in b/applications/sofa/gui/qt/etc/SofaGuiQt.ini.in new file mode 100644 index 00000000000..1a9c6a74899 --- /dev/null +++ b/applications/sofa/gui/qt/etc/SofaGuiQt.ini.in @@ -0,0 +1 @@ +RESOURCES_DIR=@RESOURCES_DIR@