Skip to content

Commit

Permalink
[CMake] Ensure CLANG_RESOURCE_DIR is respected.
Browse files Browse the repository at this point in the history
  • Loading branch information
paperchalice authored and tstellar committed Jun 3, 2023
1 parent aa7eace commit 39aa0f5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 23 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ set(openmp_wrapper_files
openmp_wrappers/new
)

set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION_MAJOR}/include)
include(GetClangResourceDir)
get_clang_resource_dir(output_dir PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/.. SUBDIR include)
set(out_files)
set(generated_files)

Expand Down Expand Up @@ -456,7 +457,7 @@ add_header_target("openmp-resource-headers" ${openmp_wrapper_files})
add_header_target("windows-resource-headers" ${windows_only_files})
add_header_target("utility-resource-headers" ${utility_files})

set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include)
get_clang_resource_dir(header_install_dir SUBDIR include)

#############################################################
# Install rules for the catch-all clang-resource-headers target
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Tooling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ else()
list(APPEND implicitDirs -I ${implicitDir})
endforeach()

include(GetClangResourceDir)
get_clang_resource_dir(resource_dir PREFIX ${LLVM_BINARY_DIR})
add_custom_command(
COMMENT Generate ASTNodeAPI.json
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
Expand All @@ -61,7 +63,7 @@ else()
$<TARGET_FILE:clang-ast-dump>
# Skip this in debug mode because parsing AST.h is too slow
--skip-processing=${skip_expensive_processing}
-I ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION_MAJOR}/include
-I ${resource_dir}/include
-I ${CLANG_SOURCE_DIR}/include
-I ${LLVM_BINARY_DIR}/tools/clang/include
-I ${LLVM_BINARY_DIR}/include
Expand Down
7 changes: 5 additions & 2 deletions clang/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
list(APPEND compiler_rt_configure_deps LLVMTestingSupport)
endif()

include(GetClangResourceDir)
get_clang_resource_dir(output_resource_dir PREFIX ${LLVM_BINARY_DIR})
get_clang_resource_dir(install_resource_dir)
ExternalProject_Add(compiler-rt
DEPENDS llvm-config clang ${compiler_rt_configure_deps}
PREFIX ${COMPILER_RT_PREFIX}
Expand All @@ -82,9 +85,9 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
-DLLVM_LIT_ARGS=${LLVM_LIT_ARGS}
-DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION_MAJOR}
-DCOMPILER_RT_OUTPUT_DIR=${output_resource_dir}
-DCOMPILER_RT_EXEC_OUTPUT_DIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCOMPILER_RT_INSTALL_PATH:PATH=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}
-DCOMPILER_RT_INSTALL_PATH:PATH=${install_resource_dir}
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
Expand Down
10 changes: 3 additions & 7 deletions compiler-rt/cmake/base-config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(BuiltinTests)
include(CheckIncludeFile)
include(CheckCXXSourceCompiles)
include(GNUInstallDirs)
include(GetClangResourceDir)
include(ExtendPath)
include(CompilerRTDarwinUtils)

Expand Down Expand Up @@ -38,15 +39,10 @@ if (LLVM_LIBRARY_OUTPUT_INTDIR AND LLVM_RUNTIME_OUTPUT_INTDIR AND PACKAGE_VERSIO
endif()

if (LLVM_TREE_AVAILABLE)
# Compute the Clang version from the LLVM version.
# FIXME: We should be able to reuse CLANG_VERSION_MAJOR variable calculated
# in Clang cmake files, instead of copying the rules here.
string(REGEX MATCH "^[0-9]+" CLANG_VERSION_MAJOR
${PACKAGE_VERSION})
# Setup the paths where compiler-rt runtimes and headers should be stored.
set(COMPILER_RT_OUTPUT_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION_MAJOR})
get_clang_resource_dir(COMPILER_RT_OUTPUT_DIR PREFIX ${LLVM_LIBRARY_OUTPUT_INTDIR}/..)
set(COMPILER_RT_EXEC_OUTPUT_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
set(COMPILER_RT_INSTALL_PATH lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR})
get_clang_resource_dir(COMPILER_RT_INSTALL_PATH)
option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests."
${LLVM_INCLUDE_TESTS})
option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered"
Expand Down
11 changes: 8 additions & 3 deletions lldb/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Driver.h"

#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
Expand Down Expand Up @@ -51,11 +52,14 @@ static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
Log *log = GetLog(LLDBLog::Host);
std::string raw_path = lldb_shlib_spec.GetPath();
llvm::StringRef parent_dir = llvm::sys::path::parent_path(raw_path);
const std::string clang_resource_path =
clang::driver::Driver::GetResourcesPath("bin/lldb", CLANG_RESOURCE_DIR);

static const llvm::StringRef kResourceDirSuffixes[] = {
// LLVM.org's build of LLDB uses the clang resource directory placed
// in $install_dir/lib{,64}/clang/$clang_version.
CLANG_INSTALL_LIBDIR_BASENAME "/clang/" CLANG_VERSION_MAJOR_STRING,
// in $install_dir/lib{,64}/clang/$clang_version or
// $install_dir/bin/$CLANG_RESOURCE_DIR
clang_resource_path,
// swift-lldb uses the clang resource directory copied from swift, which
// by default is placed in $install_dir/lib{,64}/lldb/clang. LLDB places
// it there, so we use LLDB_INSTALL_LIBDIR_BASENAME.
Expand All @@ -82,7 +86,8 @@ static bool DefaultComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
}

bool lldb_private::ComputeClangResourceDirectory(FileSpec &lldb_shlib_spec,
FileSpec &file_spec, bool verify) {
FileSpec &file_spec,
bool verify) {
#if !defined(__APPLE__)
return DefaultComputeClangResourceDirectory(lldb_shlib_spec, file_spec,
verify);
Expand Down
10 changes: 5 additions & 5 deletions lldb/unittests/Expression/ClangParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//

#include "clang/Basic/Version.h"
#include "clang/Config/config.h"
#include "clang/Driver/Driver.h"

#include "Plugins/ExpressionParser/Clang/ClangHost.h"
#include "TestingSupport/SubsystemRAII.h"
Expand Down Expand Up @@ -37,13 +39,11 @@ static std::string ComputeClangResourceDir(std::string lldb_shlib_path,
TEST_F(ClangHostTest, ComputeClangResourceDirectory) {
#if !defined(_WIN32)
std::string path_to_liblldb = "/foo/bar/lib/";
std::string path_to_clang_dir =
"/foo/bar/" LLDB_INSTALL_LIBDIR_BASENAME "/clang/" CLANG_VERSION_MAJOR_STRING;
#else
std::string path_to_liblldb = "C:\\foo\\bar\\lib";
std::string path_to_clang_dir =
"C:\\foo\\bar\\lib\\clang\\" CLANG_VERSION_MAJOR_STRING;
std::string path_to_liblldb = "C:\\foo\\bar\\lib\\";
#endif
std::string path_to_clang_dir = clang::driver::Driver::GetResourcesPath(
path_to_liblldb + "liblldb", CLANG_RESOURCE_DIR);
EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir);

// The path doesn't really exist, so setting verify to true should make
Expand Down
6 changes: 5 additions & 1 deletion llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ function(llvm_ExternalProject_Add name source_dir)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
string(REGEX MATCH "^[0-9]+" CLANG_VERSION_MAJOR
${PACKAGE_VERSION})
set(resource_dir "${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION_MAJOR}")
if(DEFINED CLANG_RESOURCE_DIR AND NOT CLANG_RESOURCE_DIR STREQUAL "")
set(resource_dir ${LLVM_TOOLS_BINARY_DIR}/${CLANG_RESOURCE_DIR})
else()
set(resource_dir "${LLVM_LIBRARY_DIR}/clang/${CLANG_VERSION_MAJOR}")
endif()
set(flag_types ASM C CXX MODULE_LINKER SHARED_LINKER EXE_LINKER)
foreach(type ${flag_types})
set(${type}_flag -DCMAKE_${type}_FLAGS=-resource-dir=${resource_dir})
Expand Down
4 changes: 2 additions & 2 deletions openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ option(OPENMP_ENABLE_LIBOMP_PROFILING "Enable time profiling for libomp." OFF)
if(${OPENMP_STANDALONE_BUILD})
set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
else()
string(REGEX MATCH "[0-9]+" CLANG_VERSION ${PACKAGE_VERSION})
set(LIBOMP_HEADERS_INSTALL_PATH "${OPENMP_INSTALL_LIBDIR}/clang/${CLANG_VERSION}/include")
include(GetClangResourceDir)
get_clang_resource_dir(LIBOMP_HEADERS_INSTALL_PATH SUBDIR include)
endif()

# Build host runtime library, after LIBOMPTARGET variables are set since they are needed
Expand Down

1 comment on commit 39aa0f5

@nikic
Copy link
Contributor

@nikic nikic commented on 39aa0f5 Jun 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this commit is missing the cmake/Modules/GetClangResourceDir.cmake file.

Please sign in to comment.