Skip to content

Commit

Permalink
[compiler-rt][cmake] Factor out extend_install_path function
Browse files Browse the repository at this point in the history
It is likely to become used again, if other projects want their own per-project
install directory variables. `install` is removed from the name since it is not inherently about installing.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D115746
  • Loading branch information
Ericson2314 committed Dec 30, 2021
1 parent 458db51 commit bde561c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
19 changes: 19 additions & 0 deletions cmake/Modules/ExtendPath.cmake
@@ -0,0 +1,19 @@
# Extend the path in `base_path` with the path in `current_segment`, returning
# the result in `joined_path`. If `current_segment` is an absolute path then
# just return it, in effect overriding `base_path`, and issue a warning.
#
# Note that the code returns a relative path (avoiding introducing leading
# slashes) if `base_path` is empty.
function(extend_path joined_path base_path current_segment)
if("${current_segment}" STREQUAL "")
set(temp_path "${base_path}")
elseif("${base_path}" STREQUAL "")
set(temp_path "${current_segment}")
elseif(IS_ABSOLUTE "${current_segment}")
message(WARNING "Since \"${current_segment}\" is absolute, it overrides install path: \"${base_path}\".")
set(temp_path "${current_segment}")
else()
set(temp_path "${base_path}/${current_segment}")
endif()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()
25 changes: 6 additions & 19 deletions compiler-rt/cmake/base-config-ix.cmake
Expand Up @@ -5,6 +5,7 @@

include(CheckIncludeFile)
include(CheckCXXSourceCompiles)
include(ExtendPath)

check_include_file(unwind.h HAVE_UNWIND_H)

Expand Down Expand Up @@ -85,20 +86,6 @@ else()
set(COMPILER_RT_TEST_COMPILER_ID GNU)
endif()

function(extend_install_path joined_path current_segment)
if("${current_segment}" STREQUAL "")
set(temp_path "${COMPILER_RT_INSTALL_PATH}")
elseif("${COMPILER_RT_INSTALL_PATH}" STREQUAL "")
set(temp_path "${current_segment}")
elseif(IS_ABSOLUTE "${current_segment}")
message(WARNING "Since \"${current_segment}\" is absolute, it overrides COMPILER_RT_INSTALL_PATH: \"${COMPILER_RT_INSTALL_PATH}\".")
set(temp_path "${current_segment}")
else()
set(temp_path "${COMPILER_RT_INSTALL_PATH}/${current_segment}")
endif()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()

if(NOT DEFINED COMPILER_RT_OS_DIR)
if(ANDROID)
# The CMAKE_SYSTEM_NAME for Android is Android, but the OS is Linux and the
Expand All @@ -111,23 +98,23 @@ endif()
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(COMPILER_RT_OUTPUT_LIBRARY_DIR
${COMPILER_RT_OUTPUT_DIR}/lib)
extend_install_path(default_install_path lib)
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
"Path where built compiler-rt libraries should be installed.")
else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(COMPILER_RT_OUTPUT_LIBRARY_DIR
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
extend_install_path(default_install_path "lib/${COMPILER_RT_OS_DIR}")
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}")
set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
"Path where built compiler-rt libraries should be installed.")
endif()
extend_install_path(default_install_path bin)
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" bin)
set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
"Path where built compiler-rt executables should be installed.")
extend_install_path(default_install_path include)
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" include)
set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
"Path where compiler-rt headers should be installed.")
extend_install_path(default_install_path share)
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" share)
set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH
"Path where compiler-rt data files should be installed.")

Expand Down

0 comments on commit bde561c

Please sign in to comment.