[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -167,12 +181,14 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTAL install( DIRECTORY generic/include/clc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) if( ENABLE_RUNTIME_SUBNORMAL ) - add_library( subnormal_use_default STATIC -generic/lib/subnormal_use_default.ll ) - add_library( subnormal_disable STATIC -generic/lib/subnormal_disable.ll ) - install( TARGETS subnormal_use_default subnormal_disable ARCHIVE -DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) + foreach( file subnormal_use_default subnormal_disable ) +link_bc( + TARGET ${file} + INPUTS ${PROJECT_SOURCE_DIR}/generic/lib/${file}.ll +) +install( FILES $ ARCHIVE frasercrmck wrote: See #109926 https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -167,12 +181,14 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTAL install( DIRECTORY generic/include/clc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) if( ENABLE_RUNTIME_SUBNORMAL ) - add_library( subnormal_use_default STATIC -generic/lib/subnormal_use_default.ll ) - add_library( subnormal_disable STATIC -generic/lib/subnormal_disable.ll ) - install( TARGETS subnormal_use_default subnormal_disable ARCHIVE -DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) + foreach( file subnormal_use_default subnormal_disable ) +link_bc( + TARGET ${file} + INPUTS ${PROJECT_SOURCE_DIR}/generic/lib/${file}.ll +) +install( FILES $ ARCHIVE frasercrmck wrote: Oh, I'm sorry about that. Let me come up with a fix. Unfortunately our libclc testing is (/has always been) very sparse. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -167,12 +181,14 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libclc.pc DESTINATION "${CMAKE_INSTAL install( DIRECTORY generic/include/clc DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) if( ENABLE_RUNTIME_SUBNORMAL ) - add_library( subnormal_use_default STATIC -generic/lib/subnormal_use_default.ll ) - add_library( subnormal_disable STATIC -generic/lib/subnormal_disable.ll ) - install( TARGETS subnormal_use_default subnormal_disable ARCHIVE -DESTINATION "${CMAKE_INSTALL_DATADIR}/clc" ) + foreach( file subnormal_use_default subnormal_disable ) +link_bc( + TARGET ${file} + INPUTS ${PROJECT_SOURCE_DIR}/generic/lib/${file}.ll +) +install( FILES $ ARCHIVE aaronpuchert wrote: This causes an installation error for me with `-DENABLE_RUNTIME_SUBNORMAL:BOOL=ON`: ``` CMake Error at cmake_install.cmake:54 (file): file INSTALL cannot find "[...]/ARCHIVE": No such file or directory. ``` According to the [documentation](https://cmake.org/cmake/help/latest/command/install.html), `ARCHIVE` is a valid option for `install(TARGETS ...)`, but not for `install(FILES ...)`. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck closed https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87622 >From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 3 Apr 2024 16:09:30 +0100 Subject: [PATCH 1/4] [libclc] Refactor build system to allow in-tree builds The previous build system was adding custom "OpenCL" and "LLVM IR" languages in CMake to build the builtin libraries. This was making it harder to build in-tree because the tool binaries needed to be present at configure time. This commit refactors the build system to use custom commands to build the bytecode files one by one, and link them all together into the final bytecode library. It also enables in-tree builds by aliasing the clang/llvm-link/etc. tool targets to internal targets, which are imported from the LLVM installation directory when building out of tree. Diffing (with llvm-diff) all of the final bytecode libraries in an out-of-tree configuration against those built using the current tip system shows no changes. Note that there are textual changes to metadata IDs which confuse regular diff, and that llvm-diff 14 and below may show false-positives. This commit also removes a file listed in one of the SOURCEs which didn't exist and which was preventing the use of ENABLE_RUNTIME_SUBNORMAL when configuring CMake. --- libclc/CMakeLists.txt | 257 ++ libclc/cmake/CMakeCLCCompiler.cmake.in| 9 - libclc/cmake/CMakeCLCInformation.cmake| 12 - libclc/cmake/CMakeDetermineCLCCompiler.cmake | 18 -- .../cmake/CMakeDetermineLLAsmCompiler.cmake | 24 -- libclc/cmake/CMakeLLAsmCompiler.cmake.in | 10 - libclc/cmake/CMakeLLAsmInformation.cmake | 12 - libclc/cmake/CMakeTestCLCCompiler.cmake | 56 libclc/cmake/CMakeTestLLAsmCompiler.cmake | 56 libclc/cmake/modules/AddLibclc.cmake | 153 +++ libclc/generic/lib/SOURCES| 1 - llvm/tools/CMakeLists.txt | 3 + 12 files changed, 305 insertions(+), 306 deletions(-) delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake create mode 100644 libclc/cmake/modules/AddLibclc.cmake diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index c6e3cdf23fe0c8..ff4e4369a7af39 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 17) +# Add path for custom modules +list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" ) + +set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir ) + +include( AddLibclc ) + include( GNUInstallDirs ) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS amdgcn-amdhsa/lib/SOURCES; @@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + # Out-of-tree configuration + set( LIBCLC_STANDALONE_BUILD TRUE ) -message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + include(AddLLVM) -if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) - message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) -endif() + message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) -find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) +message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) + endif() -# Print toolchain -message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" ) -message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" ) -message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" ) -message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" ) -message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" ) -if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
mgorny wrote: Yeah, things seem to build and install fine for me too, with this patch applied. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/rjodinchr approved this pull request. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87622 >From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 3 Apr 2024 16:09:30 +0100 Subject: [PATCH 1/3] [libclc] Refactor build system to allow in-tree builds The previous build system was adding custom "OpenCL" and "LLVM IR" languages in CMake to build the builtin libraries. This was making it harder to build in-tree because the tool binaries needed to be present at configure time. This commit refactors the build system to use custom commands to build the bytecode files one by one, and link them all together into the final bytecode library. It also enables in-tree builds by aliasing the clang/llvm-link/etc. tool targets to internal targets, which are imported from the LLVM installation directory when building out of tree. Diffing (with llvm-diff) all of the final bytecode libraries in an out-of-tree configuration against those built using the current tip system shows no changes. Note that there are textual changes to metadata IDs which confuse regular diff, and that llvm-diff 14 and below may show false-positives. This commit also removes a file listed in one of the SOURCEs which didn't exist and which was preventing the use of ENABLE_RUNTIME_SUBNORMAL when configuring CMake. --- libclc/CMakeLists.txt | 257 ++ libclc/cmake/CMakeCLCCompiler.cmake.in| 9 - libclc/cmake/CMakeCLCInformation.cmake| 12 - libclc/cmake/CMakeDetermineCLCCompiler.cmake | 18 -- .../cmake/CMakeDetermineLLAsmCompiler.cmake | 24 -- libclc/cmake/CMakeLLAsmCompiler.cmake.in | 10 - libclc/cmake/CMakeLLAsmInformation.cmake | 12 - libclc/cmake/CMakeTestCLCCompiler.cmake | 56 libclc/cmake/CMakeTestLLAsmCompiler.cmake | 56 libclc/cmake/modules/AddLibclc.cmake | 153 +++ libclc/generic/lib/SOURCES| 1 - llvm/tools/CMakeLists.txt | 3 + 12 files changed, 305 insertions(+), 306 deletions(-) delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake create mode 100644 libclc/cmake/modules/AddLibclc.cmake diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index c6e3cdf23fe0c8..ff4e4369a7af39 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 17) +# Add path for custom modules +list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" ) + +set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir ) + +include( AddLibclc ) + include( GNUInstallDirs ) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS amdgcn-amdhsa/lib/SOURCES; @@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + # Out-of-tree configuration + set( LIBCLC_STANDALONE_BUILD TRUE ) -message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + include(AddLLVM) -if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) - message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) -endif() + message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) -find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) +message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) + endif() -# Print toolchain -message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" ) -message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" ) -message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" ) -message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" ) -message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" ) -if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87622 >From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 3 Apr 2024 16:09:30 +0100 Subject: [PATCH 1/2] [libclc] Refactor build system to allow in-tree builds The previous build system was adding custom "OpenCL" and "LLVM IR" languages in CMake to build the builtin libraries. This was making it harder to build in-tree because the tool binaries needed to be present at configure time. This commit refactors the build system to use custom commands to build the bytecode files one by one, and link them all together into the final bytecode library. It also enables in-tree builds by aliasing the clang/llvm-link/etc. tool targets to internal targets, which are imported from the LLVM installation directory when building out of tree. Diffing (with llvm-diff) all of the final bytecode libraries in an out-of-tree configuration against those built using the current tip system shows no changes. Note that there are textual changes to metadata IDs which confuse regular diff, and that llvm-diff 14 and below may show false-positives. This commit also removes a file listed in one of the SOURCEs which didn't exist and which was preventing the use of ENABLE_RUNTIME_SUBNORMAL when configuring CMake. --- libclc/CMakeLists.txt | 257 ++ libclc/cmake/CMakeCLCCompiler.cmake.in| 9 - libclc/cmake/CMakeCLCInformation.cmake| 12 - libclc/cmake/CMakeDetermineCLCCompiler.cmake | 18 -- .../cmake/CMakeDetermineLLAsmCompiler.cmake | 24 -- libclc/cmake/CMakeLLAsmCompiler.cmake.in | 10 - libclc/cmake/CMakeLLAsmInformation.cmake | 12 - libclc/cmake/CMakeTestCLCCompiler.cmake | 56 libclc/cmake/CMakeTestLLAsmCompiler.cmake | 56 libclc/cmake/modules/AddLibclc.cmake | 153 +++ libclc/generic/lib/SOURCES| 1 - llvm/tools/CMakeLists.txt | 3 + 12 files changed, 305 insertions(+), 306 deletions(-) delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake create mode 100644 libclc/cmake/modules/AddLibclc.cmake diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index c6e3cdf23fe0c8..ff4e4369a7af39 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 17) +# Add path for custom modules +list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" ) + +set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir ) + +include( AddLibclc ) + include( GNUInstallDirs ) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS amdgcn-amdhsa/lib/SOURCES; @@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + # Out-of-tree configuration + set( LIBCLC_STANDALONE_BUILD TRUE ) -message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + include(AddLLVM) -if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) - message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) -endif() + message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) -find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) +message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) + endif() -# Print toolchain -message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" ) -message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" ) -message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" ) -message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" ) -message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" ) -if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
frasercrmck wrote: CC @mgorny - I was unsure whether you are actively using and interested `libclc` or you were just looking after build bots or some other reason. I've successfully built the SPIR-V libraries out-of-tree but another pair of eyes can't hurt. I was wondering - if we `libclc` building in-tree, would there be interest in building the SPIR-V targets with the LLVM SPIRV backend, rather than the external `llvm-spirv` tool? https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87622 >From 47cd6ddbf292fd8a50534e091ac64ebee3c40ee5 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 3 Apr 2024 16:09:30 +0100 Subject: [PATCH] [libclc] Refactor build system to allow in-tree builds The previous build system was adding custom "OpenCL" and "LLVM IR" languages in CMake to build the builtin libraries. This was making it harder to build in-tree because the tool binaries needed to be present at configure time. This commit refactors the build system to use custom commands to build the bytecode files one by one, and link them all together into the final bytecode library. It also enables in-tree builds by aliasing the clang/llvm-link/etc. tool targets to internal targets, which are imported from the LLVM installation directory when building out of tree. Diffing (with llvm-diff) all of the final bytecode libraries in an out-of-tree configuration against those built using the current tip system shows no changes. Note that there are textual changes to metadata IDs which confuse regular diff, and that llvm-diff 14 and below may show false-positives. This commit also removes a file listed in one of the SOURCEs which didn't exist and which was preventing the use of ENABLE_RUNTIME_SUBNORMAL when configuring CMake. --- libclc/CMakeLists.txt | 257 ++ libclc/cmake/CMakeCLCCompiler.cmake.in| 9 - libclc/cmake/CMakeCLCInformation.cmake| 12 - libclc/cmake/CMakeDetermineCLCCompiler.cmake | 18 -- .../cmake/CMakeDetermineLLAsmCompiler.cmake | 24 -- libclc/cmake/CMakeLLAsmCompiler.cmake.in | 10 - libclc/cmake/CMakeLLAsmInformation.cmake | 12 - libclc/cmake/CMakeTestCLCCompiler.cmake | 56 libclc/cmake/CMakeTestLLAsmCompiler.cmake | 56 libclc/cmake/modules/AddLibclc.cmake | 153 +++ libclc/generic/lib/SOURCES| 1 - llvm/tools/CMakeLists.txt | 3 + 12 files changed, 305 insertions(+), 306 deletions(-) delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake create mode 100644 libclc/cmake/modules/AddLibclc.cmake diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index c6e3cdf23fe0c8..ff4e4369a7af39 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 17) +# Add path for custom modules +list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" ) + +set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir ) + +include( AddLibclc ) + include( GNUInstallDirs ) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS amdgcn-amdhsa/lib/SOURCES; @@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + # Out-of-tree configuration + set( LIBCLC_STANDALONE_BUILD TRUE ) -message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + include(AddLLVM) -if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) - message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) -endif() + message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) -find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) +message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) + endif() -# Print toolchain -message( STATUS "libclc toolchain - clang: ${LLVM_CLANG}" ) -message( STATUS "libclc toolchain - llvm-as: ${LLVM_AS}" ) -message( STATUS "libclc toolchain - llvm-link: ${LLVM_LINK}" ) -message( STATUS "libclc toolchain - opt: ${LLVM_OPT}" ) -message( STATUS "libclc toolchain - llvm-spirv: ${LLVM_SPIRV}" ) -if( NOT LLVM_CLANG OR NOT LLVM_OPT OR NOT LLVM_AS OR NOT LLV
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck edited https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/87622 >From b87c2862491aed03f883d6b124a845b0d7c47699 Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 3 Apr 2024 16:09:30 +0100 Subject: [PATCH] [libclc] Refactor build system to allow in-tree builds The previous build system was adding custom "OpenCL" and "LLVM IR" languages in CMake to build the builtin libraries. This was making it harder to build in-tree because the tool binaries needed to be present at configure time. This commit refactors the build system to use custom commands to build the bytecode files one by one, and link them all together into the final bytecode library. It also enables in-tree builds by aliasing the clang/llvm-link/etc. tool targets to internal targets, which are imported from the LLVM installation directory when building out of tree. Diffing (with llvm-diff) all of the final bytecode libraries in an out-of-tree configuration against those built using the current tip system shows no changes. Note that there are textual changes to metadata IDs which confuse regular diff, and that llvm-diff 14 and below may show false-positives. This commit also removes a file listed in one of the SOURCEs which didn't exist and which was preventing the use of ENABLE_RUNTIME_SUBNORMAL when configuring CMake. --- libclc/CMakeLists.txt | 233 ++ libclc/cmake/CMakeCLCCompiler.cmake.in| 9 - libclc/cmake/CMakeCLCInformation.cmake| 12 - libclc/cmake/CMakeDetermineCLCCompiler.cmake | 18 -- .../cmake/CMakeDetermineLLAsmCompiler.cmake | 24 -- libclc/cmake/CMakeLLAsmCompiler.cmake.in | 10 - libclc/cmake/CMakeLLAsmInformation.cmake | 12 - libclc/cmake/CMakeTestCLCCompiler.cmake | 56 - libclc/cmake/CMakeTestLLAsmCompiler.cmake | 56 - libclc/cmake/modules/AddLibclc.cmake | 153 libclc/generic/lib/SOURCES| 1 - llvm/tools/CMakeLists.txt | 3 + 12 files changed, 293 insertions(+), 294 deletions(-) delete mode 100644 libclc/cmake/CMakeCLCCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeCLCInformation.cmake delete mode 100644 libclc/cmake/CMakeDetermineCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeDetermineLLAsmCompiler.cmake delete mode 100644 libclc/cmake/CMakeLLAsmCompiler.cmake.in delete mode 100644 libclc/cmake/CMakeLLAsmInformation.cmake delete mode 100644 libclc/cmake/CMakeTestCLCCompiler.cmake delete mode 100644 libclc/cmake/CMakeTestLLAsmCompiler.cmake create mode 100644 libclc/cmake/modules/AddLibclc.cmake diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 8750a65a717f9b..e509a61f51b927 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -4,6 +4,15 @@ project( libclc VERSION 0.2.0 LANGUAGES CXX C) set(CMAKE_CXX_STANDARD 17) +# Add path for custom modules +list( INSERT CMAKE_MODULE_PATH 0 "${PROJECT_SOURCE_DIR}/cmake/modules" ) + +set( LIBCLC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) +set( LIBCLC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} ) +set( LIBCLC_OBJFILE_DIR ${LIBCLC_BINARY_DIR}/obj.libclc.dir ) + +include( AddLibclc ) + include( GNUInstallDirs ) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS amdgcn-amdhsa/lib/SOURCES; @@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + # Out-of-tree configuration + set( LIBCLC_STANDALONE_BUILD TRUE ) -message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + include(AddLLVM) -if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) - message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) -endif() + message( STATUS "libclc LLVM version: ${LLVM_PACKAGE_VERSION}" ) -find_program( LLVM_CLANG clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_AS llvm-as PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_LINK llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_OPT opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + if( LLVM_PACKAGE_VERSION VERSION_LESS LIBCLC_MIN_LLVM ) +message( FATAL_ERROR "libclc needs at least LLVM ${LIBCLC_MIN_LLVM}" ) + endif() + + # Import required tools as targets + foreach( tool clang llvm-as llvm-link opt ) +find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) +add_executable( libclc::${tool} IMPORTED GLOBAL ) +set_target_properties( libclc::${tool} PROPERTIES IMPORTED_LOCATION ${LLVM_TOOL_${tool}} ) + endforeach() +else() + # In-tree configuration +
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -358,3 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) endif() endforeach( d ) endforeach( t ) + +if( NOT LIBCLC_STANDALONE_BUILD ) + add_subdirectory( test ) frasercrmck wrote: Ach yeah sorry, I have another path locally which adds some LIT tests - this should be in that one. I'll remove it for now, and we can maybe decide whether or not to add LIT testing to this PR or not. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -27,31 +36,51 @@ set( LIBCLC_TARGETS_TO_BUILD "all" option( ENABLE_RUNTIME_SUBNORMAL "Enable runtime linking of subnormal support." OFF ) -find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") -include(AddLLVM) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) frasercrmck wrote: Yeah, I think you're right. I'm not 100%, but other LLVM sub-projects do it so I think we should too. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)
@@ -358,3 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} ) endif() endforeach( d ) endforeach( t ) + +if( NOT LIBCLC_STANDALONE_BUILD ) + add_subdirectory( test ) rjodinchr wrote: There is no `CMakeLists.txt` in `/llvm/libclc/test`. https://github.com/llvm/llvm-project/pull/87622 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits