xref: /aosp_15_r20/external/bcc/cmake/FindCompilerFlag.cmake (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1# Copyright (c) 2017 Facebook, Inc.
2# Licensed under the Apache License, Version 2.0 (the "License")
3
4if (ENABLE_NO_PIE)
5
6if (CMAKE_C_COMPILER_ID MATCHES "Clang")
7	set(COMPILER_NOPIE_FLAG "-nopie")
8else()
9	set(_backup_c_flags "${CMAKE_REQUIRED_FLAGS}")
10	set(CMAKE_REQUIRED_FLAGS "-no-pie")
11	CHECK_CXX_SOURCE_COMPILES("int main() {return 0;}"
12				  HAVE_NO_PIE_FLAG)
13	if (HAVE_NO_PIE_FLAG)
14		set(COMPILER_NOPIE_FLAG "-no-pie")
15	else()
16		set(COMPILER_NOPIE_FLAG "")
17	endif()
18	set(CMAKE_REQUIRED_FLAGS "${_backup_c_flags}")
19endif()
20
21endif(ENABLE_NO_PIE)
22
23# check whether reallocarray availability
24# this is used to satisfy reallocarray usage under src/cc/libbpf/
25CHECK_CXX_SOURCE_COMPILES(
26"
27#define _GNU_SOURCE
28#include <stdlib.h>
29
30int main(void)
31{
32        return !!reallocarray(NULL, 1, 1);
33}
34" HAVE_REALLOCARRAY_SUPPORT)
35