# Copyright 2017 Nervana Systems Inc.
# 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

#     http://www.apache.org/licenses/LICENSE-2.0

# 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.

set (SRC
    tree.cpp
    util.cpp
    log.cpp
    ops/broadcast.cpp
    ops/concatenate.cpp
    ops/convert.cpp
    ops/constant.cpp
    ops/dot.cpp
    ops/function.cpp
    ops/op.cpp
    ops/parameter.cpp
    ops/tuple.cpp
    types/element_type.cpp
    types/type.cpp
    ngraph/node.cpp
    ngraph/topological_sort.cpp
    ngraph/visualize.cpp
)

set(NGRAPH_INCLUDE_PATH 
    ${CMAKE_CURRENT_SOURCE_DIR} 
    ${CMAKE_CURRENT_SOURCE_DIR}/ngraph
)

include_directories("${NGRAPH_INCLUDE_PATH}")

add_library(ngraph SHARED ${SRC})
target_include_directories(ngraph PUBLIC "${NGRAPH_INCLUDE_PATH}")

if ( APPLE )
    set_property( TARGET ngraph PROPERTY PREFIX "lib" )
    set_property( TARGET ngraph PROPERTY OUTPUT_NAME "ngraph.so" )
    set_property( TARGET ngraph PROPERTY SUFFIX "" )
endif()

#-----------------------------------------------------------------------------------------------
# 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.
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/ngraph_dist" CACHE PATH "Install directory" FORCE)
message (STATUS "Installation directory: ${CMAKE_INSTALL_PREFIX}")
message (STATUS "To Override use: cmake -DCMAKE_INSTALL_PREFIX=/foo -P cmake_install.cmake")

install(TARGETS ngraph DESTINATION ${CMAKE_INSTALL_PREFIX} )
install(DIRECTORY 
    ${CMAKE_CURRENT_SOURCE_DIR}/ngraph 
    DESTINATION ${CMAKE_INSTALL_PREFIX} 
    FILES_MATCHING PATTERN "*.hpp"
)