Skip to content

Commit

Permalink
cmake: add 'make generate' Windows compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
apwojcik committed Oct 4, 2023
1 parent f5411e0 commit 3674d8f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
54 changes: 53 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,56 @@
# THE SOFTWARE.
#####################################################################################

add_custom_target(generate bash ${CMAKE_CURRENT_SOURCE_DIR}/generate.sh)
find_program(CLANG_FORMAT clang-format PATHS /opt/rocm/llvm $ENV{HIP_PATH})
if(NOT CLANG_FORMAT)
message(WARNING "clang-format not found - skipping 'generate' target!")
return()
endif()

find_package(Python 3 COMPONENTS Interpreter)
if(NOT TARGET Python::Interpreter)
message(WARNING "Python 3 interpreter not found - skipping 'generate' target!")
return()
endif()

add_custom_target(generate)
cmake_path(SET SRC_DIR NORMALIZE "${CMAKE_CURRENT_SOURCE_DIR}/../src")

file(GLOB __files CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp)
foreach(__file ${__files})
cmake_path(NATIVE_PATH __file NORMALIZE __input_native_path)
cmake_path(GET __file FILENAME __file_name)
cmake_path(SET __output_path "${SRC_DIR}/include/migraphx/${__file_name}")
cmake_path(NATIVE_PATH __output_path __output_native_path)
add_custom_command(
OUTPUT ${__output_native_path}
COMMAND ${Python_EXECUTABLE} te.py ${__input_native_path} | ${CLANG_FORMAT} -style=file > ${__output_native_path}
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${__input_path}
)
string(MAKE_C_IDENTIFIER ${__file_name} __cid)
add_custom_target(generate_include_migraphx_${__cid} DEPENDS ${__output_native_path})
add_dependencies(generate generate_include_migraphx_${__cid})
endforeach()

function(generate_api __input_path __output_path)
cmake_path(NATIVE_PATH __output_path NORMALIZE __output_native_path)
cmake_path(NATIVE_PATH __input_path NORMALIZE __input_native_path)
cmake_path(SET __migraphx_py_path "${SRC_DIR}/api/migraphx.py")
cmake_path(NATIVE_PATH __migraphx_py_path __migraphx_py_native_path)
add_custom_command(
OUTPUT ${__output_path}
COMMAND ${Python_EXECUTABLE} api.py ${__migraphx_py_native_path} ${__input_native_path} | ${CLANG_FORMAT} -style=file > ${__output_native_path}
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${__input_path}
)
cmake_path(RELATIVE_PATH __output_path BASE_DIRECTORY ${SRC_DIR} OUTPUT_VARIABLE __rel_name)
string(MAKE_C_IDENTIFIER ${__rel_name} __cid)
add_custom_target(generate_${__cid} DEPENDS ${__output_native_path})
add_dependencies(generate generate_${__cid})
endfunction()

generate_api("${CMAKE_CURRENT_SOURCE_DIR}/api/migraphx.h" "${SRC_DIR}/api/include/migraphx/migraphx.h")
generate_api("${CMAKE_CURRENT_SOURCE_DIR}/api/api.cpp" "${SRC_DIR}/api/api.cpp")
43 changes: 0 additions & 43 deletions tools/generate.sh

This file was deleted.

0 comments on commit 3674d8f

Please sign in to comment.