Skip to content

Commit

Permalink
Merge pull request sofa-framework#758 from guparan/fix_missing_resources
Browse files Browse the repository at this point in the history
[SofaGuiQt][runSofa] FIX missing resources
  • Loading branch information
epernod authored and guparan committed Oct 4, 2018
1 parent 0f11db0 commit df97736
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
16 changes: 7 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion applications/projects/runSofa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion applications/projects/runSofa/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> iniFileValues = Utils::readBasicIniFile(sofaIniFilePath);
if (iniFileValues.find("RESOURCES_DIR") != iniFileValues.end())
{
GuiDataRepository.addFirstPath( iniFileValues["RESOURCES_DIR"] );
}

sofa::helper::BackTrace::autodump();

ExecParams::defaultInstance()->setAspectID(0);
Expand Down
1 change: 1 addition & 0 deletions applications/projects/runSofa/etc/runSofa.ini.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RESOURCES_DIR=@RESOURCES_DIR@
7 changes: 7 additions & 0 deletions applications/sofa/gui/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 7 additions & 2 deletions applications/sofa/gui/qt/RealGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> 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)
Expand Down
1 change: 1 addition & 0 deletions applications/sofa/gui/qt/etc/SofaGuiQt.ini.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RESOURCES_DIR=@RESOURCES_DIR@

0 comments on commit df97736

Please sign in to comment.