From c24e77dc0ffb211af7c6781693a765118af66d0c Mon Sep 17 00:00:00 2001 From: Romaric Jodin Date: Wed, 6 Nov 2024 20:45:42 +0100 Subject: [PATCH] build libclc as part of llvm (#1417) It should help with cross-compiling target like android --- CMakeLists.txt | 42 ++++++++++++++---------------------------- cmake/CMakeLists.txt | 4 ++-- 2 files changed, 16 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0722c7d5..3fcb7d530 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. @@ -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}) @@ -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 "" @@ -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 @@ -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) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 179e7a9d3..701f31dec 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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()