osquery-1/cmake/toolchain.cmake
Stefano Bonicatti d3f394026e
Restore PIE support being dropped on Linux (#6611)
CMake ignores the sysroot when testing the support of PIE,
so the link test fails when it tries to check for PIE support
and decides that it's not supported.
Therefore we tell CMake that PIE is supported when using the
osquery-toolchain and leave the automatic test for other toolchains.

Temporarily disable PIE on executables built with the
osquery-toolchain libFuzzer, since it has not been compiled with PIE/PIC
support.
2020-08-28 17:14:37 -04:00

19 lines
1.2 KiB
CMake

set(OSQUERY_TOOLCHAIN_SYSROOT "" CACHE PATH "Path to the sysroot that contains the custom toolchain to use to compile osquery. Linux only.")
if(OSQUERY_TOOLCHAIN_SYSROOT)
overwrite_cache_variable("CMAKE_C_COMPILER" "STRING" "${OSQUERY_TOOLCHAIN_SYSROOT}/usr/bin/clang")
overwrite_cache_variable("CMAKE_CXX_COMPILER" "STRING" "${OSQUERY_TOOLCHAIN_SYSROOT}/usr/bin/clang++")
overwrite_cache_variable("CMAKE_SYSROOT" "PATH" "${OSQUERY_TOOLCHAIN_SYSROOT}")
overwrite_cache_variable("CMAKE_LINK_SEARCH_START_STATIC" "BOOL" "ON")
overwrite_cache_variable("CMAKE_LINK_SEARCH_END_STATIC" "BOOL" "ON")
overwrite_cache_variable("CMAKE_CXX_LINK_NO_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_CXX_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_C_LINK_NO_PIE_SUPPORTED" "INTERNAL" "TRUE")
overwrite_cache_variable("CMAKE_C_LINK_PIE_SUPPORTED" "INTERNAL" "TRUE")
else()
option(OSQUERY_STATIC_BUILD "Whether to prefer linking static libraries or not")
overwrite_cache_variable("CMAKE_LINK_SEARCH_START_STATIC" "BOOL" "${OSQUERY_STATIC_BUILD}")
overwrite_cache_variable("CMAKE_LINK_SEARCH_END_STATIC" "BOOL" "${OSQUERY_STATIC_BUILD}")
endif()