Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / cmake / SDL.cmake
1 #===============================================================================
2 # Copyright 2017-2018 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #===============================================================================
16
17 # Manage secure Development Lifecycle-related compiler flags
18 #===============================================================================
19
20 if(SDL_cmake_included)
21     return()
22 endif()
23 set(SDL_cmake_included true)
24 include("cmake/utils.cmake")
25
26 if(UNIX)
27     set(CMAKE_CCXX_FLAGS "-fPIC -Wformat -Wformat-security")
28     append(CMAKE_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2")
29     append(CMAKE_C_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2")
30     if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
31         if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
32             append(CMAKE_CCXX_FLAGS "-fstack-protector-all")
33         else()
34             append(CMAKE_CCXX_FLAGS "-fstack-protector-strong")
35         endif()
36
37         # GCC might be very paranoid for partial structure initialization, e.g.
38         #   struct { int a, b; } s = { 0, };
39         # However the behavior is triggered by `Wmissing-field-initializers`
40         # only. To prevent warnings on users' side who use the library and turn
41         # this warning on, let's use it too. Applicable for the library sources
42         # and interfaces only (tests currently rely on that fact heavily)
43         append(CMAKE_SRC_CCXX_FLAGS "-Wmissing-field-initializers")
44         append(CMAKE_EXAMPLE_CCXX_FLAGS "-Wmissing-field-initializers")
45     elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
46         append(CMAKE_CCXX_FLAGS "-fstack-protector-all")
47     elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
48         append(CMAKE_CXX_FLAGS "-fstack-protector")
49     endif()
50     append(CMAKE_C_FLAGS "${CMAKE_CCXX_FLAGS}")
51     append(CMAKE_CXX_FLAGS "${CMAKE_CCXX_FLAGS}")
52     if(APPLE)
53         append(CMAKE_SHARED_LINKER_FLAGS "-Wl,-bind_at_load")
54         append(CMAKE_EXE_LINKER_FLAGS "-Wl,-bind_at_load")
55     else()
56         append(CMAKE_EXE_LINKER_FLAGS "-pie")
57         append(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
58         append(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
59     endif()
60 endif()