diff --git a/compiler-rt/cmake/Modules/HandleCompilerRT.cmake b/compiler-rt/cmake/Modules/HandleCompilerRT.cmake --- a/compiler-rt/cmake/Modules/HandleCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/HandleCompilerRT.cmake @@ -6,11 +6,11 @@ function(cache_compiler_rt_library err_flag name target library_file) if(err_flag OR NOT EXISTS "${library_file}") message(STATUS "Failed to find compiler-rt ${name} library for ${target}") - set(COMPILER_RT_LIBRARY-${name}-${target} "NOTFOUND" CACHE INTERNAL + set(COMPILER_RT_LIBRARY_${name}_${target} "NOTFOUND" CACHE INTERNAL "compiler-rt ${name} library for ${target}") else() message(STATUS "Found compiler-rt ${name} library: ${library_file}") - set(COMPILER_RT_LIBRARY-${name}-${target} "${library_file}" CACHE INTERNAL + set(COMPILER_RT_LIBRARY_${name}_${target} "${library_file}" CACHE INTERNAL "compiler-rt ${name} library for ${target}") endif() endfunction() @@ -20,6 +20,8 @@ # This calls cache_compiler_rt_library that caches the path to speed up # repeated invocations with the same `name` and `target`. function(find_compiler_rt_library name target variable) + # While we can use compiler-rt runtimes with other compilers, we need to + # query the compiler for runtime location and thus we require Clang. if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) set(${variable} "NOTFOUND" PARENT_SCOPE) return() @@ -27,7 +29,7 @@ if (NOT target AND CMAKE_CXX_COMPILER_TARGET) set(target "${CMAKE_CXX_COMPILER_TARGET}") endif() - if(NOT DEFINED COMPILER_RT_LIBRARY-builtins-${target}) + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins_${target}) # If the cache variable is not defined, invoke clang and then # set it with cache_compiler_rt_library. set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${SANITIZER_COMMON_FLAGS} @@ -45,21 +47,20 @@ ) string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) - cache_compiler_rt_library(${HAD_ERROR} - builtins "${target}" "${LIBRARY_FILE}") + cache_compiler_rt_library(${HAD_ERROR} builtins "${target}" "${LIBRARY_FILE}") endif() - if(NOT COMPILER_RT_LIBRARY-builtins-${target}) + if(NOT COMPILER_RT_LIBRARY_builtins_${target}) set(${variable} "NOTFOUND" PARENT_SCOPE) return() endif() - if(NOT DEFINED COMPILER_RT_LIBRARY-${name}-${target}) - # clang gives only the builtins library path. Other library paths are + if(NOT DEFINED COMPILER_RT_LIBRARY_${name}_${target}) + # Clang gives only the builtins library path. Other library paths are # obtained by substituting "builtins" with ${name} in the builtins # path and then checking if the resultant path exists. The result of # this check is also cached by cache_compiler_rt_library. - set(LIBRARY_FILE "${COMPILER_RT_LIBRARY-builtins-${target}}") + set(LIBRARY_FILE "${COMPILER_RT_LIBRARY_builtins_${target}}") string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") cache_compiler_rt_library(FALSE "${name}" "${target}" "${LIBRARY_FILE}") endif() - set(${variable} "${COMPILER_RT_LIBRARY-${name}-${target}}" PARENT_SCOPE) + set(${variable} "${COMPILER_RT_LIBRARY_${name}_${target}}" PARENT_SCOPE) endfunction() diff --git a/libcxx/cmake/Modules/HandleCompilerRT.cmake b/libcxx/cmake/Modules/HandleCompilerRT.cmake --- a/libcxx/cmake/Modules/HandleCompilerRT.cmake +++ b/libcxx/cmake/Modules/HandleCompilerRT.cmake @@ -1,30 +1,69 @@ -function(find_compiler_rt_library name dest) +# Check if compile-rt library file path exists. +# If found, cache the path in: +# COMPILER_RT_LIBRARY__ +# If err_flag is true OR path not found, emit a message and set: +# COMPILER_RT_LIBRARY__ to NOTFOUND +function(cache_compiler_rt_library err_flag name target library_file) + if(err_flag OR NOT EXISTS "${library_file}") + message(STATUS "Failed to find compiler-rt ${name} library") + set(COMPILER_RT_LIBRARY_${name} "NOTFOUND" CACHE INTERNAL + "compiler-rt ${name} library") + else() + message(STATUS "Found compiler-rt ${name} library: ${library_file}") + set(COMPILER_RT_LIBRARY_${name} "${library_file}" CACHE INTERNAL + "compiler-rt ${name} library") + endif() +endfunction() + +# Find the path to compiler-rt library `name` (e.g. "builtins") for +# the specified `target` (e.g. "x86_64-linux") and return it in `variable`. +# This calls cache_compiler_rt_library that caches the path to speed up +# repeated invocations with the same `name` and `target`. +function(find_compiler_rt_library name variable) + # While we can use compiler-rt runtimes with other compilers, we need to + # query the compiler for runtime location and thus we require Clang. + if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() if (NOT DEFINED LIBCXX_COMPILE_FLAGS) message(FATAL_ERROR "LIBCXX_COMPILE_FLAGS must be defined when using this function") endif() - set(dest "" PARENT_SCOPE) - set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} - "--rtlib=compiler-rt" "--print-libgcc-file-name") - if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET) - list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}") + if (NOT target AND CMAKE_CXX_COMPILER_TARGET) + set(target "${CMAKE_CXX_COMPILER_TARGET}") endif() - get_property(LIBCXX_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) - string(REPLACE " " ";" LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}") - list(APPEND CLANG_COMMAND ${LIBCXX_CXX_FLAGS}) - execute_process( - COMMAND ${CLANG_COMMAND} - RESULT_VARIABLE HAD_ERROR - OUTPUT_VARIABLE LIBRARY_FILE - ) - string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) - file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) - string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") - if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}") - message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}") - set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE) - else() - message(STATUS "Failed to find compiler-rt library") + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins) + set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXX_COMPILE_FLAGS} + "--rtlib=compiler-rt" "--print-libgcc-file-name") + if (target) + list(APPEND CLANG_COMMAND "--target=${target}") + endif() + get_property(LIBCXX_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) + string(REPLACE " " ";" LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}") + list(APPEND CLANG_COMMAND ${LIBCXX_CXX_FLAGS}) + execute_process( + COMMAND ${CLANG_COMMAND} + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE LIBRARY_FILE + ) + string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) + file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) + cache_compiler_rt_library(${HAD_ERROR} builtins "${target}" "${LIBRARY_FILE}") + endif() + if(NOT COMPILER_RT_LIBRARY_builtins) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT DEFINED COMPILER_RT_LIBRARY_${name}) + # Clang gives only the builtins library path. Other library paths are + # obtained by substituting "builtins" with ${name} in the builtins + # path and then checking if the resultant path exists. The result of + # this check is also cached by cache_compiler_rt_library. + set(LIBRARY_FILE "${COMPILER_RT_LIBRARY_builtins}") + string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") + cache_compiler_rt_library(FALSE "${name}" "${target}" "${LIBRARY_FILE}") endif() + set(${variable} "${COMPILER_RT_LIBRARY_${name}}" PARENT_SCOPE) endfunction() function(find_compiler_rt_dir dest) diff --git a/libcxxabi/cmake/Modules/HandleCompilerRT.cmake b/libcxxabi/cmake/Modules/HandleCompilerRT.cmake --- a/libcxxabi/cmake/Modules/HandleCompilerRT.cmake +++ b/libcxxabi/cmake/Modules/HandleCompilerRT.cmake @@ -1,30 +1,69 @@ -function(find_compiler_rt_library name dest) +# Check if compile-rt library file path exists. +# If found, cache the path in: +# COMPILER_RT_LIBRARY__ +# If err_flag is true OR path not found, emit a message and set: +# COMPILER_RT_LIBRARY__ to NOTFOUND +function(cache_compiler_rt_library err_flag name target library_file) + if(err_flag OR NOT EXISTS "${library_file}") + message(STATUS "Failed to find compiler-rt ${name} library for ${target}") + set(COMPILER_RT_LIBRARY_${name}_${target} "NOTFOUND" CACHE INTERNAL + "compiler-rt ${name} library for ${target}") + else() + message(STATUS "Found compiler-rt ${name} library for ${target}: ${library_file}") + set(COMPILER_RT_LIBRARY_${name}_${target} "${library_file}" CACHE INTERNAL + "compiler-rt ${name} library for ${target}") + endif() +endfunction() + +# Find the path to compiler-rt library `name` (e.g. "builtins") for +# the specified `target` (e.g. "x86_64-linux") and return it in `variable`. +# This calls cache_compiler_rt_library that caches the path to speed up +# repeated invocations with the same `name` and `target`. +function(find_compiler_rt_library name variable) + # While we can use compiler-rt runtimes with other compilers, we need to + # query the compiler for runtime location and thus we require Clang. + if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() if (NOT DEFINED LIBCXXABI_COMPILE_FLAGS) message(FATAL_ERROR "LIBCXXABI_COMPILE_FLAGS must be defined when using this function") endif() - set(dest "" PARENT_SCOPE) - set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS} - "--rtlib=compiler-rt" "--print-libgcc-file-name") - if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET) - list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}") + if (NOT target AND CMAKE_CXX_COMPILER_TARGET) + set(target "${CMAKE_CXX_COMPILER_TARGET}") endif() - get_property(LIBCXXABI_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) - string(REPLACE " " ";" LIBCXXABI_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}") - list(APPEND CLANG_COMMAND ${LIBCXXABI_CXX_FLAGS}) - execute_process( - COMMAND ${CLANG_COMMAND} - RESULT_VARIABLE HAD_ERROR - OUTPUT_VARIABLE LIBRARY_FILE - ) - string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) - file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) - string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") - if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}") - message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}") - set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE) - else() - message(STATUS "Failed to find compiler-rt library") + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins_${target}) + set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS} + "--rtlib=compiler-rt" "--print-libgcc-file-name") + if (target) + list(APPEND CLANG_COMMAND "--target=${target}") + endif() + get_property(LIBCXXABI_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) + string(REPLACE " " ";" LIBCXX_CXX_FLAGS "${LIBCXXABI_CXX_FLAGS}") + list(APPEND CLANG_COMMAND ${LIBCXXABI_CXX_FLAGS}) + execute_process( + COMMAND ${CLANG_COMMAND} + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE LIBRARY_FILE + ) + string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) + file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) + cache_compiler_rt_library(${HAD_ERROR} builtins "${target}" "${LIBRARY_FILE}") + endif() + if(NOT COMPILER_RT_LIBRARY_builtins_${target}) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT DEFINED COMPILER_RT_LIBRARY_${name}_${target}) + # Clang gives only the builtins library path. Other library paths are + # obtained by substituting "builtins" with ${name} in the builtins + # path and then checking if the resultant path exists. The result of + # this check is also cached by cache_compiler_rt_library. + set(LIBRARY_FILE "${COMPILER_RT_LIBRARY_builtins}_${target}") + string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") + cache_compiler_rt_library(FALSE "${name}" "${target}" "${LIBRARY_FILE}") endif() + set(${variable} "${COMPILER_RT_LIBRARY_${name}_${target}}" PARENT_SCOPE) endfunction() function(find_compiler_rt_dir dest) diff --git a/libunwind/cmake/Modules/HandleCompilerRT.cmake b/libunwind/cmake/Modules/HandleCompilerRT.cmake --- a/libunwind/cmake/Modules/HandleCompilerRT.cmake +++ b/libunwind/cmake/Modules/HandleCompilerRT.cmake @@ -1,30 +1,69 @@ -function(find_compiler_rt_library name dest) +# Check if compile-rt library file path exists. +# If found, cache the path in: +# COMPILER_RT_LIBRARY__ +# If err_flag is true OR path not found, emit a message and set: +# COMPILER_RT_LIBRARY__ to NOTFOUND +function(cache_compiler_rt_library err_flag name target library_file) + if(err_flag OR NOT EXISTS "${library_file}") + message(STATUS "Failed to find compiler-rt ${name} library") + set(COMPILER_RT_LIBRARY_${name} "NOTFOUND" CACHE INTERNAL + "compiler-rt ${name} library") + else() + message(STATUS "Found compiler-rt ${name} library: ${library_file}") + set(COMPILER_RT_LIBRARY_${name} "${library_file}" CACHE INTERNAL + "compiler-rt ${name} library") + endif() +endfunction() + +# Find the path to compiler-rt library `name` (e.g. "builtins") for +# the specified `target` (e.g. "x86_64-linux") and return it in `variable`. +# This calls cache_compiler_rt_library that caches the path to speed up +# repeated invocations with the same `name` and `target`. +function(find_compiler_rt_library name variable) + # While we can use compiler-rt runtimes with other compilers, we need to + # query the compiler for runtime location and thus we require Clang. + if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() if (NOT DEFINED LIBUNWIND_COMPILE_FLAGS) message(FATAL_ERROR "LIBUNWIND_COMPILE_FLAGS must be defined when using this function") endif() - set(dest "" PARENT_SCOPE) - set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS} - "--rtlib=compiler-rt" "--print-libgcc-file-name") - if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET) - list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}") + if (NOT target AND CMAKE_CXX_COMPILER_TARGET) + set(target "${CMAKE_CXX_COMPILER_TARGET}") endif() - get_property(LIBUNWIND_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) - string(REPLACE " " ";" LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") - list(APPEND CLANG_COMMAND ${LIBUNWIND_CXX_FLAGS}) - execute_process( - COMMAND ${CLANG_COMMAND} - RESULT_VARIABLE HAD_ERROR - OUTPUT_VARIABLE LIBRARY_FILE - ) - string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) - file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) - string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") - if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}") - message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}") - set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE) - else() - message(STATUS "Failed to find compiler-rt library") + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins) + set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBUNWIND_COMPILE_FLAGS} + "--rtlib=compiler-rt" "--print-libgcc-file-name") + if (target) + list(APPEND CLANG_COMMAND "--target=${target}") + endif() + get_property(LIBUNWIND_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) + string(REPLACE " " ";" LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}") + list(APPEND CLANG_COMMAND ${LIBUNWIND_CXX_FLAGS}) + execute_process( + COMMAND ${CLANG_COMMAND} + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE LIBRARY_FILE + ) + string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE) + file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE) + cache_compiler_rt_library(${HAD_ERROR} builtins "${target}" "${LIBRARY_FILE}") + endif() + if(NOT COMPILER_RT_LIBRARY_builtins) + set(${variable} "NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT DEFINED COMPILER_RT_LIBRARY_${name}) + # Clang gives only the builtins library path. Other library paths are + # obtained by substituting "builtins" with ${name} in the builtins + # path and then checking if the resultant path exists. The result of + # this check is also cached by cache_compiler_rt_library. + set(LIBRARY_FILE "${COMPILER_RT_LIBRARY_builtins}") + string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}") + cache_compiler_rt_library(FALSE "${name}" "${target}" "${LIBRARY_FILE}") endif() + set(${variable} "${COMPILER_RT_LIBRARY_${name}}" PARENT_SCOPE) endfunction() function(find_compiler_rt_dir dest)