FindASANDylib.cmake 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright 2019 Google
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. if(APPLE AND CXX_CLANG)
  15. # Sanitizers in Clang are supported by a specific runtime and Clang
  16. # automatically links against the right runtime. When building statically
  17. # linked binaries, the resulting binary will contain the runtime. Dynamically
  18. # linked binaries will link against the dynamic version of the library.
  19. #
  20. # xctest bundles are necessarily dynamically linked, but linked in such a way
  21. # that the sanitizer runtime is assumed to be on the @rpath. This finds the
  22. # clang runtimes so that they can be supplied as needed.
  23. get_filename_component(compiler_bin_dir ${CMAKE_CXX_COMPILER} DIRECTORY)
  24. get_filename_component(compiler_dir ${compiler_bin_dir} DIRECTORY)
  25. if(WITH_ASAN)
  26. file(
  27. GLOB_RECURSE CLANG_ASAN_DYLIB
  28. ${compiler_dir}/libclang_rt.asan_osx_dynamic.dylib
  29. )
  30. endif()
  31. if(WITH_TSAN)
  32. file(
  33. GLOB_RECURSE CLANG_TSAN_DYLIB
  34. ${compiler_dir}/libclang_rt.tsan_osx_dynamic.dylib
  35. )
  36. endif()
  37. endif(APPLE AND CXX_CLANG)