Skip to content

Commit

Permalink
CMake: Add support for cygwin paths when using msvc
Browse files Browse the repository at this point in the history
Pass paths through cygpath when generating ddr files, so  that they will
be understood by msvc

Signed-off-by: Devin Nakamura <devinn@ca.ibm.com>
  • Loading branch information
dnakamura committed Sep 10, 2020
1 parent a6b90c9 commit b9dc916
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cmake/modules/OmrDDRSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function(make_ddr_set set_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
2 changes: 1 addition & 1 deletion cmake/modules/OmrUtility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function(omr_remove_flags variable)
set(${variable} "${result}" PARENT_SCOPE)
endfunction(omr_remove_flags)

# omr_join(<output_variable> <item>...)
# omr_join(<glue> <output_variable> <item>...)
# takes given items an joins them with <glue>, places result in output variable
function(omr_join glue output)
string(REGEX REPLACE "(^|[^\\]);" "\\1${glue}" result "${ARGN}")
Expand Down
11 changes: 9 additions & 2 deletions cmake/modules/ddr/DDRSetStub.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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(DDR_TARGETS
$<JOIN:$<TARGET_PROPERTY:@DDR_TARGET_NAME@,DDR_TARGETS>,
Expand Down Expand Up @@ -117,6 +118,11 @@ 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 @@ -127,10 +133,11 @@ function(process_source_files src_files)
-DAWK_SCRIPT=${DDR_SUPPORT_DIR}/cmake_ddr.awk
-Dinput_file=${abs_file}
-Doutput_file=${stub_file}
"${path_tool_opt}"
-P ${DDR_SUPPORT_DIR}/GenerateStub.cmake
VERBATIM
)

# TODO this will break when we use a compiler which doesn't take UNIX style args (e.g. MSVC)
set(pp_command "@CMAKE_C_COMPILER@")
list(APPEND pp_command ${BASE_ARGS} "-E" "${stub_file}")
add_custom_command(
Expand Down Expand Up @@ -238,7 +245,7 @@ foreach(subset IN LISTS DDR_SUBSETS)
endforeach()

# now we generate our own list of binaries, so that they can be parsed if we are a subset
omr_join(binaries_list "\n"
omr_join("\n" binaries_list
${target_files}
${subset_binaries}
)
Expand Down
26 changes: 23 additions & 3 deletions cmake/modules/ddr/GenerateStub.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,26 @@ if(NOT EXISTS "${input_file}")
message(FATAL_ERROR "Input file '${input_file}' does not exist")
endif()

execute_process(COMMAND grep -E -q "@ddr_(namespace|options):" ${input_file} RESULT_VARIABLE rc)
macro(convert_path output filename)
if(PATH_TOOL)
execute_process(
COMMAND ${PATH_TOOL} "${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
string(STRIP "${_converted_path}" ${output})
else()
# no defined tool to convert path names. Do nothing
set(${output} "${filename}")
endif()
endmacro()

execute_process(COMMAND grep -E -q "@ddr_(namespace|options):" ${input_file} RESULT_VARIABLE rc)
if(NOT rc EQUAL 0)
# input didn't have any DDR directives, so just dump an empty file
file(WRITE ${output_file} "")
Expand All @@ -42,10 +60,12 @@ else()
file(WRITE "${output_file}" "/* generated file, DO NOT EDIT */\n")
if(pre_includes)
foreach(inc_file IN LISTS pre_includes)
file(APPEND ${output_file} "#include \"${inc_file}\"\n")
convert_path(native_inc_file "${inc_file}")
file(APPEND ${output_file} "#include \"${native_inc_file}\"\n")
endforeach()
endif()
file(APPEND ${output_file} "#include \"${input_file}\"\n")
convert_path(native_input_file "${input_file}")
file(APPEND ${output_file} "#include \"${native_input_file}\"\n")
file(APPEND ${output_file} "${awk_result}")
else()
message(FATAL_ERROR "GenerateStub: Invoking awk script failed (${rc})")
Expand Down

0 comments on commit b9dc916

Please sign in to comment.