From 7bf20187ec5edbc1e1f07dbf79fe10df4b1d0c43 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Wed, 31 Aug 2022 21:07:47 -0500 Subject: [PATCH] Update cmd/CMakeLists to conform with all other gz libraries (#478) (#480) This fixes the library path obtained by cmdgui.rb such that it points to the .so file contained in the non-dev debian pack Signed-off-by: Addisu Z. Taddese Signed-off-by: Louise Poubel Co-authored-by: Louise Poubel Co-authored-by: Jenn Nguyen --- conf/CMakeLists.txt | 19 ++++++++++------- src/CMakeLists.txt | 4 +++- src/cmd/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++++++-------- src/cmd/cmdgui.rb.in | 12 +++++++++-- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt index 90e3fdb6e..70201dfd8 100644 --- a/conf/CMakeLists.txt +++ b/conf/CMakeLists.txt @@ -1,20 +1,23 @@ -set(gz_library_path "${CMAKE_BINARY_DIR}/src/cmd/cmdgui${PROJECT_VERSION_MAJOR}") +# Used only for internal testing. +set(gz_library_path "${CMAKE_BINARY_DIR}/test/lib/ruby/gz/cmd${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}") # Generate a configuration file for internal testing. # Note that the major version of the library is included in the name. # Ex: gui0.yaml configure_file( - "gui.yaml.in" - "${CMAKE_BINARY_DIR}/test/conf/gui${PROJECT_VERSION_MAJOR}.yaml" @ONLY) + "${GZ_DESIGNATION}.yaml.in" + "${CMAKE_BINARY_DIR}/test/conf/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY) -set(gz_library_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/gz/cmdgui${PROJECT_VERSION_MAJOR}") +# Used for the installed version. +set(gz_library_path "${CMAKE_INSTALL_PREFIX}/lib/ruby/gz/cmd${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}") -# Generate a configuration file. +# Generate the configuration file that is installed. # Note that the major version of the library is included in the name. # Ex: gui0.yaml configure_file( - "gui.yaml.in" - "${CMAKE_CURRENT_BINARY_DIR}/gui${PROJECT_VERSION_MAJOR}.yaml" @ONLY) + "${GZ_DESIGNATION}.yaml.in" + "${CMAKE_CURRENT_BINARY_DIR}/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml" @ONLY) # Install the yaml configuration files in an unversioned location. -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gui${PROJECT_VERSION_MAJOR}.yaml DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.yaml + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/gz/) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86b8bc3fe..8ef0d9928 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,5 +81,7 @@ if(TARGET UNIT_gz_TEST) ENVIRONMENT "${_env_vars}") endif() -add_subdirectory(cmd) +if(NOT WIN32) + add_subdirectory(cmd) +endif() add_subdirectory(plugins) diff --git a/src/cmd/CMakeLists.txt b/src/cmd/CMakeLists.txt index ea320c2f6..821cd4acf 100644 --- a/src/cmd/CMakeLists.txt +++ b/src/cmd/CMakeLists.txt @@ -1,17 +1,47 @@ -# Generate the ruby script. +#=============================================================================== +# Generate the ruby script for internal testing. # Note that the major version of the library is included in the name. -if (APPLE) - set(GZ_LIBRARY_NAME lib${PROJECT_NAME_LOWER}.dylib) -else() - set(GZ_LIBRARY_NAME lib${PROJECT_NAME_LOWER}.so) -endif() +# Ex: cmdgui3.rb +set(cmd_script_generated_test "${CMAKE_BINARY_DIR}/test/lib/ruby/gz/cmd${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb") +set(cmd_script_configured_test "${cmd_script_generated_test}.configured") + +# Set the library_location variable to the full path of the library file within +# the build directory. +set(library_location "$") configure_file( - "cmdgui.rb.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmdgui${PROJECT_VERSION_MAJOR}.rb" @ONLY) + "cmd${GZ_DESIGNATION}.rb.in" + "${cmd_script_configured_test}" + @ONLY) + +file(GENERATE + OUTPUT "${cmd_script_generated_test}" + INPUT "${cmd_script_configured_test}") + + +#=============================================================================== +# Used for the installed version. +# Generate the ruby script that gets installed. +# Note that the major version of the library is included in the name. +# Ex: cmdgui3.rb +set(cmd_script_generated "${CMAKE_CURRENT_BINARY_DIR}/cmd${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR}.rb") +set(cmd_script_configured "${cmd_script_generated}.configured") + +# Set the library_location variable to the relative path to the library file +# within the install directory structure. +set(library_location "../../../${CMAKE_INSTALL_LIBDIR}/$") + +configure_file( + "cmd${GZ_DESIGNATION}.rb.in" + "${cmd_script_configured}" + @ONLY) + +file(GENERATE + OUTPUT "${cmd_script_generated}" + INPUT "${cmd_script_configured}") # Install the ruby command line library in an unversioned location. -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmdgui${PROJECT_VERSION_MAJOR}.rb DESTINATION lib/ruby/gz) +install(FILES ${cmd_script_generated} DESTINATION lib/ruby/gz) # Tack version onto and install the bash completion script configure_file( diff --git a/src/cmd/cmdgui.rb.in b/src/cmd/cmdgui.rb.in index 848a13f10..53fd5b31d 100644 --- a/src/cmd/cmdgui.rb.in +++ b/src/cmd/cmdgui.rb.in @@ -28,7 +28,7 @@ end require 'optparse' # Constants. -LIBRARY_NAME = '@GZ_LIBRARY_NAME@' +LIBRARY_NAME = '@library_location@' LIBRARY_VERSION = '@PROJECT_VERSION_FULL@' COMMON_OPTIONS = " -h [ --help ] Print this help message.\n"\ @@ -134,7 +134,15 @@ class Cmd # puts options # Read the plugin that handles the command. - plugin = LIBRARY_NAME + if LIBRARY_NAME[0] == '/' + # If the first character is a slash, we'll assume that we've been given an + # absolute path to the library. This is only used during test mode. + plugin = LIBRARY_NAME + else + # We're assuming that the library path is relative to the current + # location of this script. + plugin = File.expand_path(File.join(File.dirname(__FILE__), LIBRARY_NAME)) + end conf_version = LIBRARY_VERSION begin