CMakeLists.txt 7.62 KB
Newer Older
1
# ******************************************************************************
2 3
# Copyright 2017-2018 Intel Corporation
#
Robert Kimball's avatar
Robert Kimball committed
4 5 6
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
7
#
Robert Kimball's avatar
Robert Kimball committed
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
Robert Kimball's avatar
Robert Kimball committed
10 11 12 13 14
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
15
# ******************************************************************************
Robert Kimball's avatar
Robert Kimball committed
16

17
cmake_minimum_required (VERSION 3.1)
Robert Kimball's avatar
Robert Kimball committed
18

19 20 21
set(NGRAPH_INCLUDE_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)
22 23 24 25
# Suppress an OS X-specific warning.
if (POLICY CMP0042)
    cmake_policy(SET CMP0042 OLD)
endif()
Robert Kimball's avatar
Robert Kimball committed
26

27
project (ngraph)
Robert Kimball's avatar
Robert Kimball committed
28

29 30 31
SET(GCC_MIN_VERSION 4.8)
SET(CLANG_MIN_VERSION 3.8)
SET(APPLE_CLANG_MIN_VERSION 9.0)
32 33 34 35 36 37 38 39 40

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_MIN_VERSION)
        message(FATAL_ERROR "GCC version must be at least ${GCC_MIN_VERSION}!")
    endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS CLANG_MIN_VERSION)
        message(FATAL_ERROR "Clang version must be at least ${CLANG_MIN_VERSION}!")
    endif()
41 42 43 44
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS APPLE_CLANG_MIN_VERSION)
        message(FATAL_ERROR "Apple Clang version must be at least ${APPLE_CLANG_MIN_VERSION}!")
    endif()
45
else()
46
    message(WARNING "You are using an unsupported compiler. Compilation has only been tested with Clang (${CLANG_MIN_VERSION} and up), Apple Clang (${APPLE_CLANG_MIN_VERSION} and up), and GCC (${GCC_MIN_VERSION} and up).")
47 48
endif()

49 50 51
# Prevent Eigen from using any LGPL3 code
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DEIGEN_MPL2_ONLY")

52 53 54 55
if($ENV{NGRAPH_USE_PREBUILT_LLVM})
    set(NGRAPH_USE_PREBUILT_LLVM TRUE)
endif()

56
# These variables are undocumented but useful.
Robert Kimball's avatar
Robert Kimball committed
57 58 59
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

60 61 62
# Create compilation database compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Robert Kimball's avatar
Robert Kimball committed
63 64 65
# set directory where the custom finders live
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

66 67
include(var_functions)

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#-----------------------------------------------------------------------------------------------
# Installation logic...
#-----------------------------------------------------------------------------------------------

# Default installation location for cmake usually is /usr/include or /usr/local/include
# which requires sudo access on most servers. Also, this creates a problem for the shared
# development systems (e.g., build servers).
#
# Therefore we are setting the installation directory so that by defult "make install"
# won't override artifacts generated by other users.
#
# The user can always override this by using the cmake command listed below.
if (DEFINED NGRAPH_INSTALL_PREFIX)
    set(CMAKE_INSTALL_PREFIX ${NGRAPH_INSTALL_PREFIX})
else()
    set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/ngraph_dist")
endif()
message (STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}")
message (STATUS "To Override use: cmake -DNGRAPH_INSTALL_PREFIX=/foo")

# Destinations
set(NGRAPH_INSTALL_LIB "${CMAKE_INSTALL_PREFIX}/lib")
set(NGRAPH_INSTALL_INCLUDE "${CMAKE_INSTALL_PREFIX}/include")
set(NGRAPH_INSTALL_DOC "${CMAKE_INSTALL_PREFIX}/doc")

93 94 95 96 97
#-----------------------------------------------------------------------------------------------
# Compiler-specific logic...
#-----------------------------------------------------------------------------------------------

# Compiler-specific logic...
98
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang$")
99
    message( STATUS "Setting clang flags...")
100 101 102 103
    include( cmake/clang_4_0_flags.cmake )
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
104 105 106 107 108

ngraph_var(NGRAPH_WARNINGS_AS_ERRORS DEFAULT "OFF")
if ("${NGRAPH_WARNINGS_AS_ERRORS}" MATCHES "^(ON|TRUE)$")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
    message(STATUS "Warnings as errors")
109
endif()
110 111

SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
112
SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127
# flags required for SDL-3
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fPIE -D_FORTIFY_SOURCE=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
    endif()
endif()

128 129
# Set true if CPU backend is built by default
if (NOT DEFINED NGRAPH_CPU_ENABLE)
130 131 132 133 134
    set(NGRAPH_CPU_ENABLE TRUE)
endif()

if (NOT DEFINED NGRAPH_TBB_ENABLE)
    set(NGRAPH_TBB_ENABLE ${NGRAPH_CPU_ENABLE})
135 136
endif()

Tristan Webb's avatar
Tristan Webb committed
137 138 139 140
#-----------------------------------------------------------------------------------------------
# GPU support
#-----------------------------------------------------------------------------------------------
# Setup CUDA and cuDNN if NGRAPH_GPU_ENABLE=TRUE
Robert Kimball's avatar
Robert Kimball committed
141
find_package(CUDA 8 QUIET)
142
if(CUDA_FOUND AND NGRAPH_GPU_ENABLE)
Robert Kimball's avatar
Robert Kimball committed
143 144 145 146 147
    message(STATUS "GPU Backend Enabled")
    set(NGRAPH_GPU_ENABLE TRUE)
    find_package(CUDNN 5 QUIET REQUIRED)
    include_directories(SYSTEM ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR} ${LLVM_INCLUDE_DIR})
    if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
Tristan Webb's avatar
Tristan Webb committed
148 149
        NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0 AND
        CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER)
Robert Kimball's avatar
Robert Kimball committed
150
        message(FATAL_ERROR
Tristan Webb's avatar
Tristan Webb committed
151 152 153 154
        "CUDA 8.0 is not compatible with GCC version >= 6.\n"
        "Please select a correct compiler version\n"
        )
    endif()
Robert Kimball's avatar
Robert Kimball committed
155 156
elseif(NGRAPH_GPU_ENABLE)
    message(FATAL_ERROR "GPU was required but CUDA library was not found")
Tristan Webb's avatar
Tristan Webb committed
157 158
endif()

159 160 161 162 163 164 165 166 167 168
#-----------------------------------------------------------------------------------------------
# distributed support
#-----------------------------------------------------------------------------------------------
if(NGRAPH_DISTRIBUTED_ENABLE)
    find_package(MPI REQUIRED)
    if(MPI_CXX_FOUND)
        add_definitions(-DNGRAPH_DISTRIBUTED)
    endif()
endif()

169
#-----------------------------------------------------------------------------------------------
170 171 172 173
# External projects install directory
#-----------------------------------------------------------------------------------------------

# Root for external installs, when using `make`, e.g.
174 175
# ${EXTERNAL_PROJECTS_ROOT}
# ├── eigen
176 177 178 179 180
# │   ├── include
# │   │   └── eigen3      <-- ${EIGEN_INCLUDE_DIR}
# │   │       ├── Eigen
# │   ...
# │
181
# └── mkldnn
182 183 184 185 186 187 188
#     ├── include         <-- ${MKLDNN_INCLUDE_DIR}
#     │   ├── mkldnn.h
#     │   ...
#     ├── lib             <-- ${MKLDNN_LIB_DIR}
#     │   ├── libiomp5.so
#     ...
set(EXTERNAL_INSTALL_DIR ${CMAKE_BINARY_DIR}/external)
189

190 191 192 193
# The following 'add_subdirectory' call:
# - defines the 'libgtest' target.
# - defines the 'GTEST_INCLUDE_DIR' cmake variable.
add_subdirectory(third-party)
Robert Kimball's avatar
Robert Kimball committed
194

195 196 197 198 199
# The following 'add_subdirectory' call:
# - defines the 'ngraph' library target.
# - defines the 'NGRAPH_INCLUDE_DIR' cmake variable.
# - defines the 'NGRAPH_VERSION' cmake variable.
# - install-related targets.
Robert Kimball's avatar
Robert Kimball committed
200
add_subdirectory(src)
201

Robert Kimball's avatar
Robert Kimball committed
202
add_subdirectory(test)
203

Adam Procter's avatar
Adam Procter committed
204 205
add_subdirectory(doc)