1 #===============================================================================
2 # Copyright 2016-2018 Intel Corporation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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 #===============================================================================
17 # Manage platform-specific quirks
18 #===============================================================================
20 if(platform_cmake_included)
23 set(platform_cmake_included true)
25 add_definitions(-DMKLDNN_DLL -DMKLDNN_DLL_EXPORTS)
27 # UNIT8_MAX-like macros are a part of the C99 standard and not a part of the
28 # C++ standard (see C99 standard 7.18.2 and 7.18.4)
29 add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
32 "allows Intel(R) MKL-DNN be verbose whenever MKLDNN_VERBOSE
33 environment variable set to 1" ON) # enabled by default
34 if(NOT MKLDNN_VERBOSE)
35 add_definitions(-DDISABLE_VERBOSE)
39 set(DEF_ARCH_OPT_FLAGS)
41 if(WIN32 AND NOT MINGW)
42 set(USERCONFIG_PLATFORM "x64")
43 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} /MP")
45 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} /wd4800") # int -> bool
46 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} /wd4068") # unknown pragma
47 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} /wd4305") # double -> float
48 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} /wd4551") # UNUSED(func)
50 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
51 set(DEF_ARCH_OPT_FLAGS "-QxHOST")
52 # disable: loop was not vectorized with "simd"
53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qdiag-disable:15552")
55 elseif(UNIX OR APPLE OR MINGW)
56 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -Wall -Werror -Wno-unknown-pragmas")
57 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -fvisibility=internal")
58 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
59 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility-inlines-hidden")
60 # compiler specific settings
61 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
62 # Clang cannot vectorize some loops with #pragma omp simd and gets
63 # very upset. Tell it that it's okay and that we love it
65 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -Wno-pass-failed")
66 elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
67 if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
68 set(DEF_ARCH_OPT_FLAGS "-march=native -mtune=native")
70 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
71 # suppress warning on assumptions made regarding overflow (#146)
72 set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -Wno-strict-overflow")
74 elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
75 set(DEF_ARCH_OPT_FLAGS "-xHOST")
76 # workaround for Intel Compiler 16.0 that produces error caused
77 # by pragma omp simd collapse(..)
78 if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "17.0")
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-disable:13379")
81 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-disable:15552")
86 set(CTESTCONFIG_PATH "$ENV{PATH}")
87 string(REPLACE ";" "\;" CTESTCONFIG_PATH "${CTESTCONFIG_PATH}")
90 if(UNIX OR APPLE OR MINGW)
91 if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
92 # Link Intel libraries statically (except for iomp5)
93 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -liomp5 -static-intel")
94 # Tell linker to not complain about missing static libraries
95 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -diag-disable:10237")
99 if(NOT DEFINED ARCH_OPT_FLAGS)
100 set(ARCH_OPT_FLAGS "${DEF_ARCH_OPT_FLAGS}")
103 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CCXX_FLAGS} ${ARCH_OPT_FLAGS}")
104 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CCXX_FLAGS} ${ARCH_OPT_FLAGS}")
107 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
108 # FIXME: this is ugly but required when compiler does not add its library
109 # paths to rpath (like Intel compiler...)
110 foreach(_ ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
111 set(_rpath "-Wl,-rpath,${_}")
112 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_rpath}")
113 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_rpath}")