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

Update cmd/CMakeLists to conform with all other gz libraries (#478) #480

Merged
merged 2 commits into from
Sep 1, 2022
Merged
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
19 changes: 11 additions & 8 deletions conf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
48 changes: 39 additions & 9 deletions src/cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "$<TARGET_FILE:${PROJECT_LIBRARY_TARGET_NAME}>")

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}/$<TARGET_FILE_NAME:${PROJECT_LIBRARY_TARGET_NAME}>")

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(
Expand Down
12 changes: 10 additions & 2 deletions src/cmd/cmdgui.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"\
Expand Down Expand Up @@ -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
Expand Down