Skip to content

Commit

Permalink
build libclc as part of llvm (#1417)
Browse files Browse the repository at this point in the history
It should help with cross-compiling target like android
  • Loading branch information
rjodinchr authored Nov 6, 2024
1 parent 48acbf9 commit c24e77d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
42 changes: 14 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ if (${EXTERNAL_LLVM} EQUAL 1)
message(FATAL_ERROR "External LLVM requires CLSPV_LLVM_BINARY_DIR to be specified")
endif()
if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
if (NOT DEFINED CLSPV_LIBCLC_SOURCE_DIR)
message(FATAL_ERROR "External LLVM requires CLSPV_LIBCLC_SOURCE_DIR to be specified")
endif()
if (NOT DEFINED CLSPV_LLVM_CMAKE_MODULES_DIR)
message(FATAL_ERROR "External LLVM requires CLSPV_LLVM_CMAKE_MODULES_DIR to be specified")
endif()
message(FATAL_ERROR "External LLVM requires CLSPV_EXTERNAL_LIBCLC_DIR to be specified")
endif()
else()
# Setup to use the LLVM monorepo.
Expand All @@ -126,16 +121,6 @@ else()
set(CLSPV_CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm/clang)
endif()

if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
if (NOT DEFINED CLSPV_LIBCLC_SOURCE_DIR)
set(CLSPV_LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm/libclc)
endif()

if (NOT DEFINED CLSPV_LLVM_CMAKE_MODULES_DIR)
set(CLSPV_LLVM_CMAKE_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm/cmake/Modules)
endif()
endif()

use_component(${CLSPV_LLVM_SOURCE_DIR})
use_component(${CLSPV_CLANG_SOURCE_DIR})

Expand All @@ -145,7 +130,19 @@ else()

# First tell LLVM where to find clang.
set(LLVM_EXTERNAL_CLANG_SOURCE_DIR ${CLSPV_CLANG_SOURCE_DIR})
set(LLVM_ENABLE_PROJECTS clang)
set(LLVM_ENABLE_PROJECTS clang CACHE STRING "LLVM enabled projects for clspv")

# Also tell LLVM where to find libclc if required.
if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
if (NOT DEFINED CLSPV_LIBCLC_SOURCE_DIR)
set(CLSPV_LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm/libclc)
endif()
use_component(${CLSPV_LIBCLC_SOURCE_DIR})

set(LLVM_ENABLE_PROJECTS "${LLVM_ENABLE_PROJECTS};libclc")
set(LIBCLC_TARGETS_TO_BUILD clspv--;clspv64--)
set(LLVM_EXTERNAL_LIBCLC_SOURCE_DIR ${CLSPV_LIBCLC_SOURCE_DIR})
endif()

# Tell LLVM not to build any targets.
set(LLVM_TARGETS_TO_BUILD ""
Expand All @@ -159,11 +156,6 @@ else()
include(HandleLLVMOptions)
endif()

if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
include(${CLSPV_LLVM_CMAKE_MODULES_DIR}/LLVMVersion.cmake)
set(LLVM_VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
endif()

set(CLSPV_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

set(CLSPV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down Expand Up @@ -198,12 +190,6 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror-unused-variable -Werror-switch")
endif()

if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
set(LIBCLC_TARGETS_TO_BUILD clspv--;clspv64--)
string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" CLSPV_LIBCLC_SUFFIX "${CLSPV_LIBCLC_SOURCE_DIR}")
add_subdirectory(${CLSPV_LIBCLC_SOURCE_DIR} EXCLUDE_FROM_ALL)
endif()

# Bring in our cmake folder
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/cmake)

Expand Down
4 changes: 2 additions & 2 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ add_custom_target(clspv64_builtin_library
DEPENDS ${CLSPV64_LIBRARY_OUTPUT_FILE})

if (NOT DEFINED CLSPV_EXTERNAL_LIBCLC_DIR)
set(CLSPV_LIBRARY_INPUT_FILE ${CLSPV_BINARY_DIR}/${CLSPV_LIBCLC_SUFFIX}/clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_FILE ${CLSPV_BINARY_DIR}/${CLSPV_LIBCLC_SUFFIX}/clspv64--.bc)
set(CLSPV_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/tools/libclc/clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_FILE ${CLSPV_LLVM_BINARY_DIR}/tools/libclc/clspv64--.bc)
set(CLSPV_LIBRARY_INPUT_DEP prepare-clspv--.bc)
set(CLSPV64_LIBRARY_INPUT_DEP prepare-clspv64--.bc)
else()
Expand Down

0 comments on commit c24e77d

Please sign in to comment.