Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional binary relocatability #552

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ gz_find_package (Qt5
PKGCONFIG "Qt5Core Qt5Quick Qt5QuickControls2 Qt5Widgets"
)

set(GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR
${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins
)

set(GZ_GUI_PLUGIN_INSTALL_DIR
${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins
${CMAKE_INSTALL_PREFIX}/${GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR}
)

#============================================================================
Expand Down
9 changes: 9 additions & 0 deletions include/gz/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ gz_create_core_library(SOURCES
${headers_MOC}
${resources_RCC}
)
gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION gz::gui::getInstallPrefix
GET_INSTALL_PREFIX_HEADER gz/gui/InstallationDirectories.hh
OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GZ_GUI_INSTALL_PREFIX)

set_property(
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/InstallationDirectories.cc
PROPERTY COMPILE_DEFINITIONS
GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR="${GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR}"
)

target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
PUBLIC
Expand Down
43 changes: 43 additions & 0 deletions include/gz/gui/InstallationDirectories.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2023 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GZ_GUI_INSTALLATION_DIRECTORIES_HH_
#define GZ_GUI_INSTALLATION_DIRECTORIES_HH_

#include <string>

#include <gz/gui/config.hh>
#include <gz/gui/Export.hh>

namespace gz
{
namespace gui
{
inline namespace GZ_GUI_VERSION_NAMESPACE {

/// \brief getInstallPrefix return the install prefix of the library
/// i.e. CMAKE_INSTALL_PREFIX unless the library has been moved
GZ_GUI_VISIBLE std::string getInstallPrefix();

/// \brief getPluginInstallDir return the install directory of the plugins
GZ_GUI_VISIBLE std::string getPluginInstallDir();

}
}
}

#endif
2 changes: 1 addition & 1 deletion include/gz/gui/config.hh.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

#define GZ_GUI_VERSION_HEADER "Gazebo GUI, version ${PROJECT_VERSION_FULL}\nCopyright (C) 2017 Open Source Robotics Foundation.\nReleased under the Apache 2.0 License.\n\n"

#define GZ_GUI_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins"
#define GZ_GUI_PLUGIN_INSTALL_DIR _Pragma ("GCC warning \"'GZ_GUI_PLUGIN_INSTALL_DIR' macro is deprecated, use gz::gui::getPluginInstallDir() function instead. \"") "${GZ_GUI_PLUGIN_INSTALL_DIR}"

#endif // GZ_GUI_CONFIG_HH_
11 changes: 6 additions & 5 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gz/gui/config.hh"
#include "gz/gui/Dialog.hh"
#include "gz/gui/Helpers.hh"
#include "gz/gui/InstallationDirectories.hh"
#include "gz/gui/MainWindow.hh"
#include "gz/gui/Plugin.hh"

Expand Down Expand Up @@ -460,12 +461,12 @@ bool Application::LoadPlugin(const std::string &_filename,
// Add default folder and install folder
std::string home;
common::env(GZ_HOMEDIR, home);
systemPaths.AddPluginPaths(home + "/.gz/gui/plugins:" +
GZ_GUI_PLUGIN_INSTALL_DIR);
systemPaths.AddPluginPaths(home + "/.gz/gui/plugins");
systemPaths.AddPluginPaths(gz::gui::getPluginInstallDir());

// TODO(CH3): Deprecated. Remove on tock.
systemPaths.AddPluginPaths(home + "/.ignition/gui/plugins:" +
GZ_GUI_PLUGIN_INSTALL_DIR);
systemPaths.AddPluginPaths(home + "/.ignition/gui/plugins");
systemPaths.AddPluginPaths(gz::gui::getPluginInstallDir());


auto pathToLib = systemPaths.FindSharedLibrary(_filename);
Expand Down Expand Up @@ -775,7 +776,7 @@ std::vector<std::pair<std::string, std::vector<std::string>>>
paths.push_back(home + "/.ignition/gui/plugins");

// 4. Install path
paths.push_back(GZ_GUI_PLUGIN_INSTALL_DIR);
paths.push_back(gz::gui::getPluginInstallDir());

// Populate map
std::vector<std::pair<std::string, std::vector<std::string>>> plugins;
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set (sources
${CMAKE_CURRENT_SOURCE_DIR}/GuiEvents.cc
${CMAKE_CURRENT_SOURCE_DIR}/Helpers.cc
${CMAKE_CURRENT_SOURCE_DIR}/gz.cc
${CMAKE_CURRENT_SOURCE_DIR}/InstallationDirectories.cc
${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.cc
${CMAKE_CURRENT_SOURCE_DIR}/PlottingInterface.cc
${CMAKE_CURRENT_SOURCE_DIR}/Plugin.cc
Expand Down Expand Up @@ -53,6 +54,8 @@ gz_build_tests(TYPE UNIT
TINYXML2::TINYXML2
TEST_LIST
gtest_targets
ENVIRONMENT
GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

foreach(test ${gtest_targets})
Expand All @@ -76,6 +79,7 @@ if(TARGET UNIT_gz_TEST)

set(_env_vars)
list(APPEND _env_vars "GZ_CONFIG_PATH=${CMAKE_BINARY_DIR}/test/conf")
list(APPEND _env_vars "GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")

set_tests_properties(UNIT_gz_TEST PROPERTIES
ENVIRONMENT "${_env_vars}")
Expand Down
37 changes: 37 additions & 0 deletions src/InstallationDirectories.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2023 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gz/gui/config.hh>
#include <gz/gui/InstallationDirectories.hh>

#include <gz/common/Filesystem.hh>

namespace gz
{
namespace gui
{
inline namespace GZ_GUI_VERSION_NAMESPACE {

std::string getPluginInstallDir()
{
return gz::common::joinPaths(
getInstallPrefix(), GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR);
}

}
}
}
4 changes: 3 additions & 1 deletion src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function(gz_gui_add_plugin plugin_name)
# Used to make test-directory headers visible to the unit tests
${PROJECT_SOURCE_DIR}
# Used to make test_config.h visible to the unit tests
${PROJECT_BINARY_DIR})
${PROJECT_BINARY_DIR}
ENVIRONMENT
GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
endif()

if (MSVC)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ gz_build_tests(
gz-plugin${GZ_PLUGIN_VER}::loader
gz-rendering${GZ_RENDERING_VER}::gz-rendering${GZ_RENDERING_VER}
Qt5::Test
ENVIRONMENT
GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
4 changes: 3 additions & 1 deletion test/performance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gz_get_sources(tests)

gz_build_tests(TYPE PERFORMANCE SOURCES ${tests})
gz_build_tests(TYPE PERFORMANCE
SOURCES ${tests}
ENVIRONMENT GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
4 changes: 3 additions & 1 deletion test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
gz_get_sources(tests)

gz_build_tests(TYPE REGRESSION SOURCES ${tests})
gz_build_tests(TYPE REGRESSION
SOURCES ${tests}
ENVIRONMENT GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})