Commit 4be6a307 by abergeron Committed by Tianqi Chen

Unite cmake builds (#1248)

parent 5a15664e
......@@ -34,6 +34,7 @@ tvm_option(INSTALL_DEV "Install compiler infrastructure" OFF)
tvm_option(USE_CUDNN "Build with cuDNN" OFF)
include_directories(BEFORE "nnvm/include")
include_directories("include")
include_directories("HalideIR/src")
include_directories("dlpack/include")
......@@ -68,8 +69,9 @@ else(MSVC)
endif(MSVC)
# add source group
FILE(GLOB_RECURSE GROUP_SOURCE "src/*.cc" "HalideIR/src/*.cpp")
FILE(GLOB_RECURSE GROUP_Include "src/*.h" "include/*.h" "HalideIR/src/*.h")
FILE(GLOB_RECURSE GROUP_SOURCE "src/*.cc" "HalideIR/src/*.cpp" "nnvm/src/*.cc")
FILE(GLOB_RECURSE GROUP_Include "src/*.h" "include/*.h" "HalideIR/src/*.h"
"nnvm/src/*.h" "nnvm/include/*.h")
assign_source_group("Source" ${GROUP_SOURCE})
assign_source_group("Include" ${GROUP_Include})
......@@ -82,7 +84,16 @@ file(GLOB COMPILER_SRCS
src/pass/*.cc
src/op/*.cc
src/schedule/*.cc
)
)
file(GLOB_RECURSE NNVM_COMPILER_SRCS
nnvm/src/c_api/*.cc
nnvm/src/core/*.cc
nnvm/src/pass/*.cc
nnvm/src/compiler/*.cc
nnvm/src/top/*.cc
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/topi/include)
file(GLOB TOPI_SRCS
topi/src/*.cc
......@@ -252,10 +263,21 @@ list(APPEND RUNTIME_SRCS ${GROUP_Include})
add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
add_library(tvm_topi SHARED ${TOPI_SRCS})
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
add_library(nnvm_compiler SHARED ${NNVM_COMPILER_SRCS})
target_link_libraries(tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_topi tvm ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(tvm_runtime ${TVM_RUNTIME_LINKER_LIBS})
target_link_libraries(nnvm_compiler tvm)
install(TARGETS tvm_runtime DESTINATION lib${LIB_SUFFIX})
if(WIN32)
install(TARGETS nnvm_compiler RUNTIME DESTINATION bin)
install(TARGETS nnvm_compiler ARCHIVE DESTINATION lib)
else()
install(TARGETS nnvm_compiler LIBRARY DESTINATION lib)
endif()
if (INSTALL_DEV)
install(TARGETS tvm DESTINATION lib${LIB_SUFFIX})
install(
......@@ -277,13 +299,18 @@ if (INSTALL_DEV)
DIRECTORY "dlpack/include/." DESTINATION "include"
FILES_MATCHING
PATTERN "*.h"
)
)
install(
DIRECTORY "nnvm/include/." DESTINATION "include"
FILES_MATCHING
PATTERN "*.h"
)
else(INSTALL_DEV)
install(
DIRECTORY "include/tvm/runtime/." DESTINATION "include/tvm/runtime"
FILES_MATCHING
PATTERN "*.h"
)
)
endif(INSTALL_DEV)
if(MSVC)
......@@ -291,4 +318,5 @@ if(MSVC)
target_compile_definitions(tvm_runtime PRIVATE -DHalide_EXPORTS)
target_compile_definitions(tvm PRIVATE -DTVM_EXPORTS)
target_compile_definitions(tvm_runtime PRIVATE -DTVM_EXPORTS)
target_compile_definitions(nnvm_compiler PRIVATE -DNNVM_EXPORTS)
endif()
cmake_minimum_required(VERSION 2.8.7)
project(nnvm C CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
endif()
include(cmake/Utils.cmake)
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
endif()
endif()
# include path
include_directories(BEFORE "include")
include_directories("../include")
include_directories("../dlpack/include")
include_directories("../HalideIR/src")
include_directories("../topi/include")
set(NNVM_LINKER_LIBS "")
set(NNVM_COMPILER_LINKER_LIBS "")
add_definitions(-DNNVM_EXPORTS)
# Build a shared lib (libnnvm.so) by default
option(BUILD_SHARED_NNVM "Build a shared nnvm lib" ON)
option(BUILD_STATIC_NNVM "Build a static nnvm lib" OFF)
option(USE_MSVC_MT "Build with MT" OFF)
# compile
if(MSVC)
add_definitions(-DDMLC_USE_CXX11)
add_definitions(-DDMLC_STRICT_CXX11)
if (USE_MSVC_MT)
foreach(flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
find_library(TVM_LIB tvm
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../build/Release)
message(STATUS "Build with TVM libary: " ${TVM_LIB})
list(APPEND NNVM_COMPILER_LINKER_LIBS ${TVM_LIB})
else(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
set(CMAKE_C_FLAGS "-O3 -Wall -std=c++11 -fPIC")
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
endif(MSVC)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()
mxnet_source_group("Include\\c_api" GLOB "src/c_api/*.h")
mxnet_source_group("Include\\core" GLOB "src/core/*.h")
mxnet_source_group("Include\\pass" GLOB "src/pass/*.h")
mxnet_source_group("Include\\nnvm" GLOB "include/nnvm/*.h")
mxnet_source_group("Include\\dmlc" GLOB "include/dmlc/*.h")
mxnet_source_group("Source" GLOB "src/*.cc")
mxnet_source_group("Source\\c_api" GLOB "src/c_api/*.cc")
mxnet_source_group("Source\\core" GLOB "src/core/*.cc")
mxnet_source_group("Source\\pass" GLOB "src/pass/*.cc")
file(GLOB_RECURSE SOURCE
src/c_api/*.cc
src/core/*.cc
src/pass/*.cc)
file(GLOB_RECURSE COMPILER_SRCS
src/compiler/*.cc
src/top/*.cc
)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../dmlc-core/CMakeLists.txt)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../dmlc-core/include)
elseif(DMLC_CORE_PATH)
include_directories(${DMLC_CORE_PATH}/include)
endif()
if(BUILD_SHARED_NNVM)
add_library(nnvm SHARED ${SOURCE})
target_link_libraries(nnvm ${nnvm_LINKER_LIBS})
endif()
if(BUILD_STATIC_NNVM)
add_library(nnvm_static STATIC ${SOURCE})
target_link_libraries(nnvm_static ${nnvm_LINKER_LIBS})
set_target_properties(nnvm_static PROPERTIES OUTPUT_NAME "nnvm")
endif()
add_library(nnvm_compiler SHARED ${COMPILER_SRCS} ${SOURCE})
target_link_libraries(nnvm_compiler ${NNVM_COMPILER_LINKER_LIBS} ${NNVM_LINKER_LIBS})
if(INSTALL_INCLUDE_DIR)
add_custom_command(TARGET nnvm POST_BUILD
COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/include ${INSTALL_INCLUDE_DIR}/
)
endif()
# ---[ Install lib, header and docs
if(BUILD_SHARED_NNVM)
if(WIN32)
install(TARGETS nnvm RUNTIME DESTINATION bin)
install(TARGETS nnvm ARCHIVE DESTINATION lib)
install(TARGETS nnvm_compiler RUNTIME DESTINATION bin)
install(TARGETS nnvm_compiler ARCHIVE DESTINATION lib)
else()
install(TARGETS nnvm LIBRARY DESTINATION lib)
install(TARGETS nnvm_compiler LIBRARY DESTINATION lib)
endif()
endif()
if(BUILD_STATIC_NNVM)
install(TARGETS nnvm_static ARCHIVE DESTINATION lib)
endif()
install(DIRECTORY include DESTINATION .)
install(DIRECTORY docs DESTINATION .)
# ---[ Linter target
if(MSVC)
find_package(PythonInterp 2)
set(PYTHON2_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Path to the python 2.x executable")
find_package(PythonInterp 3)
set(PYTHON3_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Path to the python 3.x executable")
endif()
set(LINT_DIRS include src scripts)
add_custom_target(nnvm_lint COMMAND ${CMAKE_COMMAND} -DMSVC=${MSVC} -DPYTHON2_EXECUTABLE=${PYTHON2_EXECUTABLE} -DPYTHON3_EXECUTABLE=${PYTHON3_EXECUTABLE} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -DLINT_DIRS=${LINT_DIRS} -DPROJECT_NAME=dmlc -P ${PROJECT_SOURCE_DIR}/cmake/lint.cmake)
......@@ -29,8 +29,8 @@ def find_lib_path():
lib_name = "nnvm_compiler" if sys.platform.startswith('win32') else "libnnvm_compiler"
api_path = os.path.join(base_path, '../../lib/')
cmake_build_path = os.path.join(base_path, '../../build/Release/')
cmake_build_path = os.path.join(base_path, '../../build/')
cmake_build_path = os.path.join(base_path, '../../../build/Release/')
cmake_build_path = os.path.join(base_path, '../../../build/')
dll_path = [base_path, api_path, cmake_build_path]
if sys.platform.startswith('linux') and os.environ.get('LD_LIBRARY_PATH', None):
......@@ -43,11 +43,11 @@ def find_lib_path():
if sys.platform.startswith('win32'):
vs_configuration = 'Release'
if platform.architecture()[0] == '64bit':
dll_path.append(os.path.join(base_path, '../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../windows/x64', vs_configuration))
dll_path.append(os.path.join(base_path, '../../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../../windows/x64', vs_configuration))
else:
dll_path.append(os.path.join(base_path, '../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../windows', vs_configuration))
dll_path.append(os.path.join(base_path, '../../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../../windows', vs_configuration))
dll_path = [os.path.join(p, '%s.dll' % lib_name) for p in dll_path]
elif sys.platform.startswith('darwin'):
dll_path = [os.path.join(p, '%s.dylib' % lib_name) for p in dll_path]
......
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