diff --git a/CMakeLists.txt b/CMakeLists.txt index a42e61c3..e663e195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,8 @@ gz_configure_project(VERSION_SUFFIX) # Set project-specific options #============================================================================ -set(GZ_LAUNCH_PLUGIN_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/") +set(GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH "${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins/") +set(GZ_LAUNCH_PLUGIN_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH}") #============================================================================ # Search for project-specific dependencies diff --git a/include/gz/launch/InstallationDirectories.hh b/include/gz/launch/InstallationDirectories.hh new file mode 100644 index 00000000..f9fd398d --- /dev/null +++ b/include/gz/launch/InstallationDirectories.hh @@ -0,0 +1,46 @@ +/* + * 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_LAUNCH_INSTALLATION_DIRECTORIES_HH_ +#define GZ_LAUNCH_INSTALLATION_DIRECTORIES_HH_ + +#include + +#include +#include + +namespace gz +{ + namespace launch + { + inline namespace GZ_LAUNCH_VERSION_NAMESPACE { + + /// \brief getInstallPrefix return the install prefix of the library + /// i.e. CMAKE_INSTALL_PREFIX unless the library has been moved + GZ_LAUNCH_VISIBLE std::string getInstallPrefix(); + + /// \brief getPluginInstallPath return the plugin install path + GZ_LAUNCH_VISIBLE std::string getPluginInstallPath(); + + /// \brief getInitialConfigPath return the initial config path + GZ_LAUNCH_VISIBLE std::string getInitialConfigPath(); + + } + } +} + +#endif diff --git a/include/gz/launch/config.hh.in b/include/gz/launch/config.hh.in index b0fb1f30..73609ae4 100644 --- a/include/gz/launch/config.hh.in +++ b/include/gz/launch/config.hh.in @@ -30,8 +30,8 @@ #define GZ_LAUNCH_VERSION_HEADER "Gazebo Launch, version ${PROJECT_VERSION_FULL}\nCopyright (C) 2019 Open Source Robotics Foundation.\nReleased under the Apache 2.0 License.\n\n" -#define GZ_LAUNCH_INITIAL_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/${GZ_DATA_INSTALL_DIR}/configs" +#define GZ_LAUNCH_INITIAL_CONFIG_PATH _Pragma ("GCC warning \"'GZ_LAUNCH_INITIAL_CONFIG_PATH' macro is deprecated, use gz::launch::getInitialConfigPath() function instead. \"") "${CMAKE_INSTALL_PREFIX}/${GZ_DATA_INSTALL_DIR}/configs" -#define GZ_LAUNCH_PLUGIN_INSTALL_PATH "${GZ_LAUNCH_PLUGIN_INSTALL_PATH}" +#define GZ_LAUNCH_PLUGIN_INSTALL_PATH _Pragma ("GCC warning \"'GZ_LAUNCH_PLUGIN_INSTALL_PATH' macro is deprecated, use gz::launch::getPluginInstallPath() function instead. \"") "${GZ_LAUNCH_PLUGIN_INSTALL_PATH}" #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5f87b11..d3b5350d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,7 @@ # add_subdirectory(plugins) set (sources + InstallationDirectories.cc Manager.cc ) @@ -10,6 +11,16 @@ set (gtest_sources # Create the library target. gz_create_core_library(SOURCES ${sources}) +gz_add_get_install_prefix_impl(GET_INSTALL_PREFIX_FUNCTION gz::launch::getInstallPrefix + GET_INSTALL_PREFIX_HEADER gz/launch/InstallationDirectories.hh + OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE GZ_LAUNCH_INSTALL_PREFIX) + +set_property( + SOURCE InstallationDirectories.cc + PROPERTY COMPILE_DEFINITIONS + GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH="${GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH}" + GZ_LAUNCH_INITIAL_CONFIG_RELATIVE_PATH="${GZ_DATA_INSTALL_DIR}/configs" +) # Link the libraries that we always need. target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} @@ -31,6 +42,8 @@ gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} LIB_DEPS ${PROJECT_LIBRARY_TARGET_NAME} gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER} + ENVIRONMENT + GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} ) add_subdirectory(cmd) diff --git a/src/InstallationDirectories.cc b/src/InstallationDirectories.cc new file mode 100644 index 00000000..6f7eec19 --- /dev/null +++ b/src/InstallationDirectories.cc @@ -0,0 +1,41 @@ +/* + * 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 +#include + +#include + +namespace gz +{ +namespace launch +{ +inline namespace GZ_LAUNCH_VERSION_NAMESPACE { + +std::string getPluginInstallPath() +{ + return gz::common::joinPaths(getInstallPrefix(), GZ_LAUNCH_PLUGIN_RELATIVE_INSTALL_PATH); +} + +std::string getInitialConfigPath() +{ + return gz::common::joinPaths(getInstallPrefix(), GZ_LAUNCH_INITIAL_CONFIG_RELATIVE_PATH); +} + +} +} +} diff --git a/src/Manager.cc b/src/Manager.cc index 400d95a3..9ca71c87 100644 --- a/src/Manager.cc +++ b/src/Manager.cc @@ -57,6 +57,7 @@ #include #include "gz/launch/config.hh" +#include "gz/launch/InstallationDirectories.hh" #include "gz/launch/Plugin.hh" #include "vendor/backward.hpp" @@ -1089,7 +1090,7 @@ void ManagerPrivate::LoadPlugin(const tinyxml2::XMLElement *_elem) gz::common::SystemPaths systemPaths; systemPaths.SetPluginPathEnv("GZ_LAUNCH_PLUGIN_PATH"); - systemPaths.AddPluginPaths(GZ_LAUNCH_PLUGIN_INSTALL_PATH); + systemPaths.AddPluginPaths(gz::launch::getPluginInstallPath()); // Add LD_LIBRARY_PATH #ifdef __linux__ diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index b87f706d..49be965e 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -32,7 +32,8 @@ install( # Build the unit tests. gz_build_tests(TYPE UNIT SOURCES ${gtest_sources} TEST_LIST test_list - LIB_DEPS ${EXTRA_TEST_LIB_DEPS}) + LIB_DEPS ${EXTRA_TEST_LIB_DEPS} + ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) foreach(test ${test_list}) target_link_libraries(${test} gz) diff --git a/src/cmd/gz.cc b/src/cmd/gz.cc index d770541b..9a361da4 100644 --- a/src/cmd/gz.cc +++ b/src/cmd/gz.cc @@ -18,6 +18,7 @@ #include #include "gz/launch/config.hh" +#include "gz/launch/InstallationDirectories.hh" #include "gz.hh" #include "../Manager.hh" @@ -30,7 +31,8 @@ extern "C" char *gzVersion() ////////////////////////////////////////////////// extern "C" const char *configPath() { - return GZ_LAUNCH_INITIAL_CONFIG_PATH; + std::string configPath = gz::launch::getPluginInstallPath(); + return configPath.c_str(); } ////////////////////////////////////////////////// diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 1c6496c6..f4162ed8 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -10,7 +10,10 @@ if(NOT WIN32) # Disable test on Windows, it deals with UNIX signals set(tests faulty_plugins.cc) - gz_build_tests(TYPE INTEGRATION SOURCES ${tests} TEST_LIST test_targets) + gz_build_tests(TYPE INTEGRATION + SOURCES ${tests} + TEST_LIST test_targets + ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) foreach(test ${test_targets}) target_compile_definitions(${test} PRIVATE "bad_plugins_LIB=\"$\"") diff --git a/test/performance/CMakeLists.txt b/test/performance/CMakeLists.txt index a73bfddb..872a9539 100644 --- a/test/performance/CMakeLists.txt +++ b/test/performance/CMakeLists.txt @@ -4,4 +4,6 @@ set(tests) link_directories(${PROJECT_BINARY_DIR}/test) -gz_build_tests(TYPE PERFORMANCE SOURCES ${tests}) +gz_build_tests(TYPE PERFORMANCE + SOURCES ${tests} + ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}) diff --git a/test/regression/CMakeLists.txt b/test/regression/CMakeLists.txt index aac9ecda..1e94deee 100644 --- a/test/regression/CMakeLists.txt +++ b/test/regression/CMakeLists.txt @@ -5,4 +5,6 @@ set(tests link_directories(${PROJECT_BINARY_DIR}/test) -gz_build_tests(TYPE REGRESSION SOURCES ${tests}) +gz_build_tests(TYPE REGRESSION + SOURCES ${tests} + ENVIRONMENT GZ_LAUNCH_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})