Skip to content

Commit

Permalink
Merge pull request #937 from ROCm-Developer-Tools/amd/dev/kzhuravl/SW…
Browse files Browse the repository at this point in the history
…DEV-379066

[HIPIFY][SWDEV-379066][build] Add the ability to include hipify in HIP SDK
  • Loading branch information
emankov authored Jul 7, 2023
2 parents 9b25d43 + e687b17 commit 5c2bad1
Showing 1 changed file with 60 additions and 21 deletions.
81 changes: 60 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ cmake_minimum_required(VERSION 3.16.8)
project(hipify-clang)

include(GNUInstallDirs)
find_package(LLVM REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH})

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}:")
message(STATUS " - CMake module path: ${LLVM_CMAKE_DIR}")
message(STATUS " - Include path : ${LLVM_INCLUDE_DIRS}")
message(STATUS " - Binary path : ${LLVM_TOOLS_BINARY_DIR}")
option(HIPIFY_INCLUDE_IN_HIP_SDK "Include HIPIFY in HIP SDK" OFF)
if(HIPIFY_INCLUDE_IN_HIP_SDK)
if(NOT WIN32)
message(FATAL_ERROR "HIPIFY_INCLUDE_IN_HIP_SDK is only supported on Windows")
endif()
if(CMAKE_GENERATOR MATCHES "Visual Studio")
message(FATAL_ERROR "HIPIFY_INCLUDE_IN_HIP_SDK is not targeting Visual Studio")
endif()
else()
find_package(LLVM REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH})

message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}:")
message(STATUS " - CMake module path: ${LLVM_CMAKE_DIR}")
message(STATUS " - Include path : ${LLVM_INCLUDE_DIRS}")
message(STATUS " - Binary path : ${LLVM_TOOLS_BINARY_DIR}")
endif()

option(HIPIFY_CLANG_TESTS "Build HIPIFY tests, if lit is installed" OFF)
option(HIPIFY_CLANG_TESTS_ONLY "Build HIPIFY tests only, if lit is installed and hipify-clang binary is already produced" OFF)
Expand All @@ -31,8 +42,31 @@ file(GLOB_RECURSE HIPIFY_HEADERS src/*.h)
add_llvm_executable(hipify-clang ${HIPIFY_SOURCES} ${HIPIFY_HEADERS})
target_link_directories(hipify-clang PRIVATE ${LLVM_LIBRARY_DIRS})

set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
if(HIPIFY_INCLUDE_IN_HIP_SDK)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "In order to include HIPIFY in HIP SDK, HIPIFY needs to be built with LLVM_EXTERNAL_PROJECTS")
endif()

# Need to add clang include directories explicitly if
# building as part of llvm.
if(LLVM_EXTERNAL_CLANG_SOURCE_DIR)
target_include_directories(hipify-clang
PRIVATE
${LLVM_BINARY_DIR}/tools/clang/include
${LLVM_EXTERNAL_CLANG_SOURCE_DIR}/include)
endif()
# Need to add lld include directories explicitly if
# building as part of llvm.
if(LLVM_EXTERNAL_LLD_SOURCE_DIR)
target_include_directories(hipify-clang
PRIVATE
${LLVM_BINARY_DIR}/tools/lld/include
${LLVM_EXTERNAL_LLD_SOURCE_DIR}/include)
endif()
else()
set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
endif()

# Link against LLVM and CLANG libraries
target_link_libraries(hipify-clang PRIVATE
Expand Down Expand Up @@ -129,24 +163,29 @@ set(HIPIFY_BIN_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/bin")
install(TARGETS hipify-clang DESTINATION bin)
# install bin directory in CMAKE_INSTALL_PREFIX path
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/bin
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
DESTINATION .
USE_SOURCE_PERMISSIONS
PATTERN "hipify-perl"
PATTERN "*.sh")
# install all folders under clang/version/ in CMAKE_INSTALL_PREFIX path
install(
DIRECTORY ${LLVM_DIR}/../../clang/${LIB_CLANG_RES}/
DESTINATION .
COMPONENT clang-resource-headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.modulemap"
PATTERN "algorithm"
PATTERN "complex"
PATTERN "new"
PATTERN "ppc_wrappers" EXCLUDE
PATTERN "openmp_wrappers" EXCLUDE)

# Headers are already included in HIP SDK, so skip those if including
# HIPIFY in HIP SDK.
if(NOT HIPIFY_INCLUDE_IN_HIP_SDK)
# install all folders under clang/version/ in CMAKE_INSTALL_PREFIX path
install(
DIRECTORY ${LLVM_DIR}/../../clang/${LIB_CLANG_RES}/
DESTINATION .
COMPONENT clang-resource-headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.modulemap"
PATTERN "algorithm"
PATTERN "complex"
PATTERN "new"
PATTERN "ppc_wrappers" EXCLUDE
PATTERN "openmp_wrappers" EXCLUDE)
endif()

option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compatibility" ON)

Expand Down

0 comments on commit 5c2bad1

Please sign in to comment.