Unverified Commit c428a97b authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Auto generate version number and apply it to install dir and libngraph.so (#925)

* migrate files

* apply version number to libngraph.so

* fix cmake running with empty build directory
parent 17c33415
...@@ -16,6 +16,18 @@ ...@@ -16,6 +16,18 @@
cmake_minimum_required (VERSION 3.1) cmake_minimum_required (VERSION 3.1)
include(cmake/Modules/git_tags.cmake)
NGRAPH_GET_VERSION_LABEL()
string(REGEX MATCH "([0-9]+)\.([0-9]+)\.([0-9]+)" NGRAPH_VERSION_SHORT "${NGRAPH_VERSION_LABEL}")
string(REGEX MATCH "([0-9]+)\.([0-9]+)" NGRAPH_API_VERSION "${NGRAPH_VERSION_LABEL}")
set(NGRAPH_VERSION "${NGRAPH_VERSION_LABEL}")
configure_file(VERSION.in VERSION)
message(STATUS "NGRAPH_VERSION ${NGRAPH_VERSION}")
message(STATUS "NGRAPH_VERSION_SHORT ${NGRAPH_VERSION_SHORT}")
message(STATUS "NGRAPH_API_VERSION ${NGRAPH_API_VERSION}")
set(NGRAPH_INCLUDE_PATH set(NGRAPH_INCLUDE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src
) )
...@@ -133,6 +145,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security") ...@@ -133,6 +145,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security")
if (NOT APPLE) if (NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack") 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} -z relro -z now")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
endif() endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
...@@ -169,6 +182,8 @@ if(NGRAPH_GPU_ENABLE) ...@@ -169,6 +182,8 @@ if(NGRAPH_GPU_ENABLE)
"Please select a correct compiler version\n" "Please select a correct compiler version\n"
) )
endif() endif()
elseif(NGRAPH_GPU_ENABLE)
message(FATAL_ERROR "GPU was required but CUDA library was not found")
endif() endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
......
${NGRAPH_VERSION}
# ******************************************************************************
# Copyright 2017-2018 Intel Corporation
#
# 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.
# ******************************************************************************
function(NGRAPH_GET_CURRENT_HASH)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD
RESULT_VARIABLE result
OUTPUT_VARIABLE HASH)
string(STRIP ${HASH} HASH)
set(NGRAPH_CURRENT_HASH ${HASH} PARENT_SCOPE)
endfunction()
function(NGRAPH_GET_TAG_OF_CURRENT_HASH)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} ls-remote --tags
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE TAG_LIST)
NGRAPH_GET_CURRENT_HASH()
string(REGEX MATCH "${NGRAPH_CURRENT_HASH}\t[^\r\n]*" TAG ${TAG_LIST})
set(FINAL_TAG ${TAG})
if (NOT "${TAG}" STREQUAL "")
string(REGEX REPLACE "${NGRAPH_CURRENT_HASH}\trefs/tags/(.*)" "\\1" FINAL_TAG ${TAG})
endif()
set(NGRAPH_CURRENT_RELEASE_TAG ${FINAL_TAG} PARENT_SCOPE)
endfunction()
function(NGRAPH_GET_MOST_RECENT_TAG)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
RESULT_VARIABLE RESULT
OUTPUT_VARIABLE TAG)
string(STRIP ${TAG} TAG)
set(NGRAPH_MOST_RECENT_RELEASE_TAG ${TAG} PARENT_SCOPE)
endfunction()
function(NGRAPH_GET_VERSION_LABEL)
NGRAPH_GET_TAG_OF_CURRENT_HASH()
set(NGRAPH_VERSION_LABEL ${NGRAPH_CURRENT_RELEASE_TAG} PARENT_SCOPE)
if ("${NGRAPH_CURRENT_RELEASE_TAG}" STREQUAL "")
NGRAPH_GET_CURRENT_HASH()
NGRAPH_GET_MOST_RECENT_TAG()
string(SUBSTRING "${NGRAPH_CURRENT_HASH}" 0 7 HASH)
set(NGRAPH_VERSION_LABEL "${NGRAPH_MOST_RECENT_RELEASE_TAG}+${HASH}" PARENT_SCOPE)
endif()
endfunction()
...@@ -287,7 +287,6 @@ endif() ...@@ -287,7 +287,6 @@ endif()
set_property(SOURCE codegen/compiler.cpp APPEND_STRING PROPERTY COMPILE_DEFINITIONS set_property(SOURCE codegen/compiler.cpp APPEND_STRING PROPERTY COMPILE_DEFINITIONS
"CUDNN_HEADER_PATHS=\"${CUDNN_INCLUDE_DIRS}\";") "CUDNN_HEADER_PATHS=\"${CUDNN_INCLUDE_DIRS}\";")
endif() endif()
endif() endif()
if (NGRAPH_NNP_ENABLE) if (NGRAPH_NNP_ENABLE)
...@@ -296,6 +295,7 @@ if (NGRAPH_NNP_ENABLE) ...@@ -296,6 +295,7 @@ if (NGRAPH_NNP_ENABLE)
endif() endif()
add_library(ngraph SHARED ${SRC}) add_library(ngraph SHARED ${SRC})
set_target_properties(ngraph PROPERTIES VERSION ${NGRAPH_VERSION} SOVERSION ${NGRAPH_API_VERSION})
if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND MKLDNN_INCLUDE_DIR) if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND MKLDNN_INCLUDE_DIR)
# Generate the resource file containing all headers used by the codegen compiler # Generate the resource file containing all headers used by the codegen compiler
add_custom_target(header_resource add_custom_target(header_resource
...@@ -376,6 +376,7 @@ endif() ...@@ -376,6 +376,7 @@ endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# NGraph # NGraph
install(FILES ${CMAKE_BINARY_DIR}/VERSION DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS ngraph DESTINATION ${NGRAPH_INSTALL_LIB}) # libngraph.so install(TARGETS ngraph DESTINATION ${NGRAPH_INSTALL_LIB}) # libngraph.so
install(DIRECTORY install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment