-
Notifications
You must be signed in to change notification settings - Fork 13
/
linux.cmake
71 lines (65 loc) · 2.5 KB
/
linux.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2014-2024 Intel Corporation
set(TEE_SOURCES src/linux/metee_linux.c src/linux/mei.c)
add_library(${PROJECT_NAME} ${TEE_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE src/linux)
target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL>
$<$<BOOL:BUILD_SHARED_LIBS>:METEE_DLL_EXPORT>
)
# Check for new IOCTLs
include(CheckSymbolExists)
check_symbol_exists(IOCTL_MEI_CONNECT_CLIENT_VTAG linux/mei.h HAVE_VTAG)
if(NOT HAVE_VTAG)
include_directories(BEFORE "src/linux/include")
endif()
# More warnings and warning-as-error
set(COMPILE_OPTIONS
-Wall -Werror)
include(CheckCCompilerFlag)
check_c_compiler_flag(-Wshadow WARNING_SHADOW)
if(WARNING_SHADOW)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wshadow)
endif()
check_c_compiler_flag(-Wnull-dereference WARNING_NULL_DEREFERENCE)
if(WARNING_NULL_DEREFERENCE)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wnull-dereference)
endif()
check_c_compiler_flag(-Wfloat-conversion WARNING_FLOAT_CONVERSION)
if(WARNING_FLOAT_CONVERSION)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wfloat-conversion)
endif()
check_c_compiler_flag(-Wsign-conversion WARNING_SIGN_CONVERSION)
if(WARNING_SIGN_CONVERSION)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wsign-conversion)
endif()
check_c_compiler_flag(-Wstringop-truncation WARNING_STRINGOP_TRUNCATION)
if(WARNING_STRINGOP_TRUNCATION)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wstringop-truncation)
endif()
check_c_compiler_flag(-Wjump-misses-init WARNING_JUMP_MISSES_INIT)
if(WARNING_JUMP_MISSES_INIT)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wjump-misses-init)
endif()
check_c_compiler_flag(-Wunsuffixed-float-constants WARNING_UNSUFFIXED_FLOAT_CONSTANTS)
if(WARNING_UNSUFFIXED_FLOAT_CONSTANTS)
set(COMPILE_OPTIONS ${COMPILE_OPTIONS} -Wunsuffixed-float-constants)
endif()
target_compile_options(
${PROJECT_NAME}
PRIVATE ${COMPILE_OPTIONS})
# Security options
target_compile_options(
${PROJECT_NAME}
PRIVATE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2 -Wformat
-Wformat-security
PRIVATE $<$<C_COMPILER_ID:GNU>:-fno-strict-overflow>
PRIVATE $<$<C_COMPILER_ID:GNU>:-fno-delete-null-pointer-checks>
PRIVATE -fwrapv
)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now")
set_target_properties(${PROJECT_NAME} PROPERTIES C_VISIBILITY_PRESET hidden)
if(NOT CONSOLE_OUTPUT)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DSYSLOG)
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE -D_GNU_SOURCE)