Skip to content

Commit

Permalink
CMake: fix empty string warnings
Browse files Browse the repository at this point in the history
Prior to this change, numerous warnings are issued by cmake:
  CMake Warning:
    Ignoring empty string ("") provided on the command line.

Rework how the decision to use 'cygpath -w' is made: Provide
USE_PATH_TOOL to GenerateStub.cmake so it can behave as desired.

Signed-off-by: Keith W. Campbell <keithc@ca.ibm.com>
  • Loading branch information
keithc-ca committed Mar 22, 2024
1 parent cbfcf7d commit 1691da5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
11 changes: 6 additions & 5 deletions cmake/modules/OmrDDRSupport.cmake
Expand Up @@ -39,17 +39,18 @@ endif()
set(OMR_MODULES_DIR ${CMAKE_CURRENT_LIST_DIR})
set(DDR_INFO_DIR "${CMAKE_BINARY_DIR}/ddr_info")

if(OMR_OS_WINDOWS AND (OMR_TOOLCONFIG STREQUAL "msvc"))
set(USE_PATH_TOOL TRUE)
else()
set(USE_PATH_TOOL FALSE)
endif()

function(make_ddr_set set_name)
set(DDR_TARGET_NAME "${set_name}")
set(DDR_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/${DDR_TARGET_NAME}")
set(DDR_MACRO_INPUTS_FILE "${DDR_BIN_DIR}/macros.list")
set(DDR_TOOLS_EXPORT "${omr_BINARY_DIR}/ddr/tools/DDRTools.cmake")
set(DDR_CONFIG_STAMP "${DDR_BIN_DIR}/config.stamp")
if((CMAKE_HOST_SYSTEM_NAME STREQUAL "CYGWIN") AND (OMR_TOOLCONFIG STREQUAL "msvc"))
set(PATH_TOOL cygpath -w)
else()
set(PATH_TOOL "")
endif()

# if DDR is not enabled, just skip
# Also skip if we are on a multi config generator since it is unsupported at the moment
Expand Down
38 changes: 17 additions & 21 deletions cmake/modules/ddr/DDRSetStub.cmake.in
Expand Up @@ -31,7 +31,6 @@ set(DDR_BLOB "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,BLOB>")
set(DDR_SUPERSET "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,SUPERSET>")
set(DDR_MACRO_LIST "${DDR_INFO_DIR}/sets/@DDR_TARGET_NAME@.macros")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OMR_MODULES_DIR})
set(PATH_TOOL "@PATH_TOOL@")
set(OBJECT_SEARCH_ROOT "$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_OBJECT_SEARCH_ROOT>")

set(DDR_TARGETS
Expand All @@ -49,8 +48,8 @@ project(@DDR_TARGET_NAME@ LANGUAGES NONE)
include("@DDR_TOOLS_EXPORT@")
include(OmrUtility)

# given a var, make the path specified absolute,
# assuming paths are relative to the ddr set source directory
# Given a var, make the path specified absolute,
# assuming paths are relative to the ddr set source directory.
macro(make_absolute var_name)
if(${var_name})
get_filename_component(${var_name} "${${var_name}}"
Expand All @@ -59,9 +58,9 @@ macro(make_absolute var_name)
endif()
endmacro()

make_absolute(DDR_BLOB)
make_absolute(DDR_EXCLUDES)
make_absolute(DDR_OVERRIDES_FILE)
make_absolute(DDR_BLOB)
make_absolute(DDR_SUPERSET)

function(get_relative_path output filename base)
Expand All @@ -79,7 +78,7 @@ function(add_filename_extension output filename prefix)

string(REGEX REPLACE "${extension}$" "${prefix}${extension}" temp "${filename}")
set("${output}" "${temp}" PARENT_SCOPE)
endfunction(add_filename_extension)
endfunction()

function(process_source_files src_files)
set(options "")
Expand All @@ -91,7 +90,7 @@ function(process_source_files src_files)
set(stub_files)
set(annotated_files)

# build up the command line to the preprocessor
# Build up the command line to the preprocessor.
set(BASE_ARGS)
if("@CMAKE_C_COMPILER_ID@" STREQUAL "MSVC")
list(APPEND BASE_ARGS "-nologo")
Expand All @@ -106,7 +105,7 @@ function(process_source_files src_files)

foreach(source_file IN LISTS OPT_UNPARSED_ARGUMENTS)
get_filename_component(extension "${source_file}" EXT)
# if file isn't a C/C++ file, ignore it
# If source_file isn't a C/C++ file, ignore it.
if(NOT extension MATCHES "\.[ch](pp)?$")
continue()
endif()
Expand All @@ -123,11 +122,6 @@ function(process_source_files src_files)
list(APPEND stub_files "${stub_file}")
list(APPEND annotated_files "${annt_file}")

if(PATH_TOOL)
set(path_tool_opt "-DPATH_TOOL=${PATH_TOOL}")
else()
set(path_tool_opt "")
endif()
add_custom_command(
OUTPUT "${stub_file}"
DEPENDS
Expand All @@ -136,9 +130,9 @@ function(process_source_files src_files)
${DDR_SUPPORT_DIR}/GenerateStub.cmake
COMMAND ${CMAKE_COMMAND}
-DAWK_SCRIPT=${DDR_SUPPORT_DIR}/cmake_ddr.awk
-DUSE_PATH_TOOL=@USE_PATH_TOOL@
-Dinput_file=${abs_file}
-Doutput_file=${stub_file}
"${path_tool_opt}"
-P ${DDR_SUPPORT_DIR}/GenerateStub.cmake
COMMENT ""
VERBATIM
Expand All @@ -152,11 +146,11 @@ function(process_source_files src_files)
list(APPEND pp_command "-xc++")
endif()
if("@OMR_OS_ZOS@" AND "@OMR_ENV_DATA64@")
# we need to set 64 bit code generation to ensure that limits.h macros are set correctly.
# We need to set 64 bit code generation to ensure that limits.h macros are set correctly.
list(APPEND pp_command "-Wc,lp64")
endif()
if("@OMR_OS_WINDOWS@" AND extension MATCHES "\.hpp$")
# Visual Studio needs to be told that .hpp files as C++ code.
# Visual Studio needs to be told that .hpp files are C++ code.
list(APPEND pp_command "/TP")
endif()
list(APPEND pp_command ${BASE_ARGS} "-E" "${stub_file}")
Expand Down Expand Up @@ -184,7 +178,7 @@ set(target_files "")
function(process_target target)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${target}")
set(target_info_file "${DDR_INFO_DIR}/targets/${target}.txt")
# make cmake configuration depend on input file
# Make cmake configuration depend on input file.
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${target_info_file}")
file(STRINGS "${target_info_file}" target_config)

Expand Down Expand Up @@ -217,7 +211,7 @@ function(process_target target)
)
list(APPEND annotated_files ${project_annt_hdr})

# bump changes up to parent scope
# Bump changes up to parent scope.
set(annotated_files "${annotated_files}" PARENT_SCOPE)
endfunction(process_target)

Expand All @@ -229,6 +223,7 @@ set(subset_macro_lists "")
foreach(subset IN LISTS DDR_SUBSETS)
list(APPEND subset_macro_lists "${DDR_INFO_DIR}/sets/${subset}.macros")
endforeach()

add_custom_command(
OUTPUT ${DDR_MACRO_LIST}
DEPENDS ${annotated_files} ${subset_macro_lists}
Expand Down Expand Up @@ -258,19 +253,19 @@ endif()

set(subset_binaries)
foreach(subset IN LISTS DDR_SUBSETS)
# name of file which subset generates, listing all of the input binaries
# The name of the file which subset generates, listing all of the input binaries.
set(binaries_list_file "${DDR_INFO_DIR}/sets/${subset}.binaries")
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${binaries_list_file}")
file(STRINGS "${binaries_list_file}" binaries)
list(APPEND subset_binaries ${binaries})
endforeach()

if(ZOS)
# On zos, we have to glob for the individual .dbg files
# On z/OS, we have to glob for the individual .dbg files.
set(target_files)

if(OBJECT_EXCLUDE_REGEX STREQUAL "^")
# Empty exclude regex, just include everything
# Empty exclude regex, just include everything.
file(GLOB_RECURSE target_files "${OBJECT_SEARCH_ROOT}/*.dbg")
else()
file(GLOB_RECURSE dbg_files RELATIVE "${OBJECT_SEARCH_ROOT}" "${OBJECT_SEARCH_ROOT}/*.dbg")
Expand All @@ -282,7 +277,7 @@ if(ZOS)
endif()
endif()

# now we generate our own list of binaries, so that they can be parsed if we are a subset
# Now we generate our own list of binaries, so that they can be parsed if we are a subset.
omr_join("\n" binaries_list
${target_files}
${subset_binaries}
Expand All @@ -300,4 +295,5 @@ if(DDR_BLOB OR DDR_SUPERSET)
${EXTRA_DDRGEN_OPTIONS}
)
endif()

add_custom_target(@DDR_TARGET_NAME@ ALL DEPENDS ${DDR_BLOB} ${DDR_MACRO_LIST})
18 changes: 10 additions & 8 deletions cmake/modules/ddr/GenerateStub.cmake
Expand Up @@ -25,24 +25,26 @@ elseif(NOT EXISTS "${input_file}")
message(FATAL_ERROR "Input file '${input_file}' does not exist")
endif()

macro(convert_path output filename)
if(PATH_TOOL)
if(USE_PATH_TOOL)
macro(convert_path output filename)
execute_process(
COMMAND ${PATH_TOOL} "${filename}"
COMMAND cygpath -w "${filename}"
OUTPUT_VARIABLE _converted_path
RESULT_VARIABLE _convert_rc
)
if(NOT _convert_rc EQUAL 0)
message(FATAL_ERROR "Error converting path ${filename}")
endif()

# remove excess whitespace and save into result variable
# Remove excess whitespace and save into result variable.
string(STRIP "${_converted_path}" ${output})
else()
# no defined tool to convert path names, so do nothing
endmacro()
else()
macro(convert_path output filename)
# No need to convert path names, so do nothing.
set(${output} "${filename}")
endif()
endmacro()
endmacro()
endif()

file(WRITE "${output_file}" "/* generated file, DO NOT EDIT */\nconst char ddr_source[] = \"${input_file}\";\n")

Expand Down

0 comments on commit 1691da5

Please sign in to comment.