Skip to content

Instantly share code, notes, and snippets.

@aggresss
Last active February 11, 2019 10:35
Show Gist options
  • Save aggresss/529093f9d49f7294c77dbafca7aecb80 to your computer and use it in GitHub Desktop.
Save aggresss/529093f9d49f7294c77dbafca7aecb80 to your computer and use it in GitHub Desktop.
返回工具链的前缀
# reference: https://cmake.org/cmake/help/latest/command/string.html
cmake_minimum_required (VERSION 2.8)
# Returns the compiler prefix
function(compiler_prefix input_string output_string)
string(REGEX MATCH "[^/]+$" compiler_basename ${input_string})
string(REGEX MATCH "[^-]+$" compiler_id ${compiler_basename})
if(NOT ${compiler_basename} STREQUAL ${compiler_id})
string(REPLACE "-${compiler_id}" "" compiler_host ${compiler_basename})
endif()
set(${output_string} ${compiler_host} PARENT_SCOPE)
endfunction()
set(COMPILER_STRING "/usr/local/bin/arm-linux-gcc")
message("COMPILER_STRING: " ${COMPILER_STRING})
compiler_prefix(${COMPILER_STRING} COMPILER_PREFIX)
message("COMPILER_PREFIX: " ${COMPILER_PREFIX})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment