Debian Codegraph @

cmake/CompileOptions.cmake

raw
1 # ##############################################################################
2 # Copyright (C) Intel Corporation
3 #
4 # SPDX-License-Identifier: MIT
5 # ##############################################################################
6
7 #
8 # Set compilation options
9 #
10 if(MSVC)
11 add_compile_options("$<$<CONFIG:Debug>:/D_DEBUG>")
12 else()
13 add_compile_options("$<$<CONFIG:Debug>:-D_DEBUG -O0 -g>")
14 endif()
15
16 if(ENABLE_WARNING_AS_ERROR)
17 message(STATUS "Warnings as errors enabled")
18 set(MFX_DEPRECATED_OFF 1)
19 endif()
20
21 if(DEFINED ENV{MFX_DEPRECATED_OFF})
22 set(MFX_DEPRECATED_OFF 1)
23 endif()
24
25 if(MFX_DEPRECATED_OFF)
26 message(STATUS "Deprecation warnings disabled")
27 add_definitions(-DMFX_DEPRECATED_OFF)
28 endif()
29
30 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
31
32 if(MSVC)
33 add_link_options("/guard:cf")
34 add_link_options("/DYNAMICBASE")
35 if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
36 add_link_options("/HIGHENTROPYVA")
37 endif()
38 add_link_options("/LARGEADDRESSAWARE")
39 add_link_options("/NXCOMPAT")
40 if(ENABLE_WARNING_AS_ERROR)
41 add_compile_options("/WX")
42 endif()
43 add_compile_options("/GS")
44 add_compile_options("/guard:cf")
45 else()
46 if(UNIX)
47 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
48 endif()
49 add_compile_options("-Wformat")
50 add_compile_options("-Wformat-security")
51 add_compile_options("-Werror=format-security")
52 if(NOT MINGW)
53 string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
54 if(NOT CMAKE_BUILD_TYPE MATCHES debug)
55 add_definitions("-D_FORTIFY_SOURCE=2")
56 endif()
57 endif()
58 if(NOT MINGW)
59 add_compile_options("-fstack-protector-strong")
60 endif()
61 if(NOT MINGW)
62 add_link_options("-Wl,-z,relro,-z,now,-z,noexecstack")
63 endif()
64 add_compile_options("-Wall")
65 if(ENABLE_WARNING_AS_ERROR)
66 add_compile_options("-Werror")
67 endif()
68 endif()
69
70 # Define RelWithDebRT Build Mode
71 if(MSVC)
72 set(CMAKE_DEBUG_POSTFIX "d")
73 set(CMAKE_RELWITHDEBRT_POSTFIX "d")
74 set(CMAKE_CXX_FLAGS_RELWITHDEBRT
75 "${CMAKE_CXX_FLAGS_RELEASE}"
76 CACHE STRING "Flags used by the C++ compiler during RelWithDebRT builds."
77 FORCE)
78 set(CMAKE_C_FLAGS_RELWITHDEBRT
79 "${CMAKE_C_FLAGS_RELEASE}"
80 CACHE STRING "Flags used by the C compiler during RelWithDebRT builds."
81 FORCE)
82
83 foreach(build_flag CMAKE_CXX_FLAGS_RELWITHDEBRT CMAKE_C_FLAGS_RELWITHDEBRT)
84 string(REPLACE "/MDd" "" ${build_flag} "${${build_flag}}")
85 string(REPLACE "/MTd" "" ${build_flag} "${${build_flag}}")
86 string(REPLACE "/MD" "" ${build_flag} "${${build_flag}}")
87 string(REPLACE "/MT" "" ${build_flag} "${${build_flag}}")
88 set(${build_flag} "${${build_flag}} /MDd /DEBUG:NONE")
89 endforeach()
90
91 set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBRT
92 "${CMAKE_EXE_LINKER_FLAGS_RELEASE}"
93 CACHE STRING
94 "Flags used for linking binaries during RelWithDebRT builds." FORCE)
95 set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBRT
96 "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}"
97 CACHE
98 STRING
99 "Flags used by the shared libraries linker during RelWithDebRT builds."
100 FORCE)
101 set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBRT
102 "${CMAKE_MODULE_LINKER_FLAGS_RELEASE}"
103 CACHE STRING "Flags used by the linker during RelWithDebRT builds." FORCE)
104 mark_as_advanced(
105 CMAKE_CXX_FLAGS_RELWITHDEBRT CMAKE_C_FLAGS_RELWITHDEBRT
106 CMAKE_EXE_LINKER_FLAGS_RELWITHDEBRT CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBRT)
107
108 # Add RelWithDebRT to avalible config types
109 set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES};RelWithDebRT")
110
111 endif()