|
- # The MIT License (MIT)
- #
- # Copyright (c)
- # 2013 Matthew Arsenault
- # 2015-2016 RWTH Aachen University, Federal Republic of Germany
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in all
- # copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- # SOFTWARE.
-
- # Helper function to get the language of a source file.
- function (sanitizer_lang_of_source FILE RETURN_VAR)
- get_filename_component(FILE_EXT "${FILE}" EXT)
- string(TOLOWER "${FILE_EXT}" FILE_EXT)
- string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT)
-
- get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
- foreach (LANG ${ENABLED_LANGUAGES})
- list(FIND CMAKE_${LANG}_SOURCE_FILE_EXTENSIONS "${FILE_EXT}" TEMP)
- if (NOT ${TEMP} EQUAL -1)
- set(${RETURN_VAR} "${LANG}" PARENT_SCOPE)
- return()
- endif ()
- endforeach()
-
- set(${RETURN_VAR} "" PARENT_SCOPE)
- endfunction ()
-
-
- # Helper function to get compilers used by a target.
- function (sanitizer_target_compilers TARGET RETURN_VAR)
- # Check if all sources for target use the same compiler. If a target uses
- # e.g. C and Fortran mixed and uses different compilers (e.g. clang and
- # gfortran) this can trigger huge problems, because different compilers may
- # use different implementations for sanitizers.
- set(BUFFER "")
- get_target_property(TSOURCES ${TARGET} SOURCES)
- foreach (FILE ${TSOURCES})
- # If expression was found, FILE is a generator-expression for an object
- # library. Object libraries will be ignored.
- string(REGEX MATCH "TARGET_OBJECTS:([^ >]+)" _file ${FILE})
- if ("${_file}" STREQUAL "")
- sanitizer_lang_of_source(${FILE} LANG)
- if (LANG)
- list(APPEND BUFFER ${CMAKE_${LANG}_COMPILER_ID})
- endif ()
- endif ()
- endforeach ()
-
- list(REMOVE_DUPLICATES BUFFER)
- set(${RETURN_VAR} "${BUFFER}" PARENT_SCOPE)
- endfunction ()
|